diff options
Diffstat (limited to 'src/main/java')
5 files changed, 28 insertions, 10 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index f70c58a..4564d5b 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -234,7 +234,12 @@ public class LilleroProcessor extends AbstractProcessor { //case-specific handling if(type == ProxyType.TYPE) { //find and validate - ClassContainer clazz = ClassContainer.findOrFallback(targetClass, proxyVar.getAnnotation(Find.class), this.processingEnv, this.mapper); + ClassContainer clazz = ClassContainer.findOrFallback( + ClassContainer.from(cl, this.processingEnv, this.mapper), + proxyVar.getAnnotation(Find.class), + this.processingEnv, + this.mapper + ); //types can be generated with a single instruction constructorBuilder.addStatement( "super.$L = $T.from($S, 0, $L)", diff --git a/src/main/java/ftbsc/lll/processor/annotations/Find.java b/src/main/java/ftbsc/lll/processor/annotations/Find.java index 82dea62..e684cb5 100644 --- a/src/main/java/ftbsc/lll/processor/annotations/Find.java +++ b/src/main/java/ftbsc/lll/processor/annotations/Find.java @@ -19,8 +19,8 @@ import java.lang.annotation.RetentionPolicy; public @interface Find { /** * @return the {@link Class} object containing the target, or the - * {@link Object} class if not specified (the {@link Class} from - * {@link Patch#value()} is instead used). + * {@link Object} class if not specified (the annotation's parent + * class is instead used). * @since 0.5.0 */ Class<?> value() default Object.class; 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(); |