aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/ftbsc/lll/processor/LilleroProcessor.java15
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/ASTUtils.java8
2 files changed, 13 insertions, 10 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
index aaaa2f0..a2a42f2 100644
--- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
+++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
@@ -29,6 +29,7 @@ import java.util.*;
import java.util.stream.Collectors;
import static ftbsc.lll.processor.tools.ASTUtils.*;
+import static ftbsc.lll.processor.tools.ASTUtils.getClassFullyQualifiedName;
/**
* The actual annotation processor behind the magic.
@@ -175,8 +176,8 @@ public class LilleroProcessor extends AbstractProcessor {
private static String findClassName(Patch patchAnn, FindMethod methodAnn, ObfuscationMapper mapper) {
String fullyQualifiedName =
methodAnn == null || methodAnn.parent() == Object.class
- ? getClassFullyQualifiedName(patchAnn.value())
- : getClassFullyQualifiedName(methodAnn.parent());
+ ? getClassFullyQualifiedName(patchAnn, p -> patchAnn.value())
+ : getClassFullyQualifiedName(methodAnn, m -> methodAnn.parent());
return findClassName(fullyQualifiedName, mapper);
}
@@ -322,11 +323,11 @@ public class LilleroProcessor extends AbstractProcessor {
private VariableElement findField(ExecutableElement stub, ObfuscationMapper mapper) {
Patch patchAnn = stub.getEnclosingElement().getAnnotation(Patch.class);
FindField fieldAnn = stub.getAnnotation(FindField.class);
- String parentName = findClassName(getClassFullyQualifiedName(
- fieldAnn.parent().equals(Object.class)
- ? patchAnn.value()
- : fieldAnn.parent()
- ), mapper);
+ String parentName;
+ if(fieldAnn.parent().equals(Object.class))
+ parentName = getClassFullyQualifiedName(patchAnn, p -> patchAnn.value());
+ else parentName = getClassFullyQualifiedName(fieldAnn, f -> fieldAnn.parent());
+ parentName = findClassName(parentName, mapper);
String name = fieldAnn.name().equals("")
? stub.getSimpleName().toString()
: fieldAnn.name();
diff --git a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java
index c35e008..fb6806e 100644
--- a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java
+++ b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java
@@ -13,6 +13,7 @@ import javax.lang.model.type.MirroredTypeException;
import javax.lang.model.type.TypeMirror;
import java.lang.annotation.Annotation;
import java.util.List;
+import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -137,13 +138,14 @@ public class ASTUtils {
* Safely converts a {@link Class} to its fully qualified name. See
* <a href="https://area-51.blog/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor">this blogpost</a>
* for more information.
- * @param clazz the class to get the name for
+ * @param ann the annotation containing the class
+ * @param fun the annotation function returning the class
* @return the fully qualified name of the given class
* @since 0.3.0
*/
- public static String getClassFullyQualifiedName(Class<?> clazz) {
+ public static <T extends Annotation> String getClassFullyQualifiedName(T ann, Function<Annotation, Class<?>> fun) {
try {
- return clazz.getCanonicalName();
+ return fun.apply(ann).getCanonicalName();
} catch(MirroredTypeException e) {
return e.getTypeMirror().toString();
}