diff options
Diffstat (limited to 'src/main/java/ftbsc/lll/processor/tools')
3 files changed, 20 insertions, 7 deletions
diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/ClassContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/ClassContainer.java index 95a71bb..110c0f0 100644 --- a/src/main/java/ftbsc/lll/processor/tools/containers/ClassContainer.java +++ b/src/main/java/ftbsc/lll/processor/tools/containers/ClassContainer.java @@ -95,24 +95,37 @@ public class ClassContainer { * Safely extracts a {@link Class} from an annotation and gets its fully qualified name. * @param ann the annotation containing the class * @param classFunction the annotation function returning the class - * @param className a string containing the FQN, the inner class name or nothing + * @param innerName a string containing the inner class name or nothing * @param env the {@link ProcessingEnvironment} to be used to locate the class * @param mapper the {@link ObfuscationMapper} to be used, may be null * @param <T> the type of the annotation carrying the information * @return the fully qualified name of the given class * @since 0.5.0 */ - public static <T extends Annotation> ClassContainer from( - T ann, Function<T, Class<?>> classFunction, String className, + public static <T extends Annotation> ClassContainer from(T ann, Function<T, Class<?>> classFunction, String innerName, ProcessingEnvironment env, ObfuscationMapper mapper) { String fqn; String[] inner; fqn = getTypeFromAnnotation(ann, classFunction, env).toString(); - inner = className.equals("") ? null : className.split("//$"); + inner = innerName.equals("") ? null : innerName.split("//$"); return new ClassContainer(fqn, inner, env, mapper); } /** + * Safely extracts a {@link Class} from an annotation and gets its fully qualified name. + * @param cl the {@link TypeElement} representing the class + * @param env the {@link ProcessingEnvironment} to be used to locate the class + * @param mapper the {@link ObfuscationMapper} to be used, may be null + * @param <T> the type of the annotation carrying the information + * @return the fully qualified name of the given class + * @since 0.6.0 + */ + public static <T extends Annotation> ClassContainer from( + TypeElement cl, ProcessingEnvironment env, ObfuscationMapper mapper) { + return new ClassContainer(cl.getQualifiedName().toString(), null, env, mapper); + } + + /** * Finds and builds a {@link ClassContainer} based on information contained * within a {@link Find} annotation, else returns a fallback. * @param fallback the {@link ClassContainer} it falls back on diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java index 5b6564f..6458c59 100644 --- a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java +++ b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java @@ -7,6 +7,7 @@ import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper; import org.objectweb.asm.Type; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -96,7 +97,7 @@ public class FieldContainer { Find f = finder.getAnnotation(Find.class); ClassContainer parent = ClassContainer.findOrFallback( - ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper), + ClassContainer.from((TypeElement) finder.getEnclosingElement(), env, mapper), f, env, mapper ); diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java index 8bef323..00141a1 100644 --- a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java +++ b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java @@ -102,10 +102,9 @@ public class MethodContainer { //the parent always has a @Patch annotation Patch patchAnn = stub.getEnclosingElement().getAnnotation(Patch.class); ClassContainer parent = ClassContainer.findOrFallback( - ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper), + ClassContainer.from((TypeElement) stub.getEnclosingElement(), env, mapper), f, env, mapper ); - String name = !t.methodName().equals("") ? t.methodName() //name was specified in target : stub.getSimpleName().toString(); |