mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-22 10:34:51 +01:00
feat: @Find now falls back on containing class
This commit is contained in:
parent
e27dab1c66
commit
a91d7c810f
5 changed files with 28 additions and 10 deletions
|
@ -234,7 +234,12 @@ public class LilleroProcessor extends AbstractProcessor {
|
||||||
//case-specific handling
|
//case-specific handling
|
||||||
if(type == ProxyType.TYPE) {
|
if(type == ProxyType.TYPE) {
|
||||||
//find and validate
|
//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
|
//types can be generated with a single instruction
|
||||||
constructorBuilder.addStatement(
|
constructorBuilder.addStatement(
|
||||||
"super.$L = $T.from($S, 0, $L)",
|
"super.$L = $T.from($S, 0, $L)",
|
||||||
|
|
|
@ -19,8 +19,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
public @interface Find {
|
public @interface Find {
|
||||||
/**
|
/**
|
||||||
* @return the {@link Class} object containing the target, or the
|
* @return the {@link Class} object containing the target, or the
|
||||||
* {@link Object} class if not specified (the {@link Class} from
|
* {@link Object} class if not specified (the annotation's parent
|
||||||
* {@link Patch#value()} is instead used).
|
* class is instead used).
|
||||||
* @since 0.5.0
|
* @since 0.5.0
|
||||||
*/
|
*/
|
||||||
Class<?> value() default Object.class;
|
Class<?> value() default Object.class;
|
||||||
|
|
|
@ -95,23 +95,36 @@ public class ClassContainer {
|
||||||
* Safely extracts a {@link Class} from an annotation and gets its fully qualified name.
|
* Safely extracts a {@link Class} from an annotation and gets its fully qualified name.
|
||||||
* @param ann the annotation containing the class
|
* @param ann the annotation containing the class
|
||||||
* @param classFunction the annotation function returning 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 env the {@link ProcessingEnvironment} to be used to locate the class
|
||||||
* @param mapper the {@link ObfuscationMapper} to be used, may be null
|
* @param mapper the {@link ObfuscationMapper} to be used, may be null
|
||||||
* @param <T> the type of the annotation carrying the information
|
* @param <T> the type of the annotation carrying the information
|
||||||
* @return the fully qualified name of the given class
|
* @return the fully qualified name of the given class
|
||||||
* @since 0.5.0
|
* @since 0.5.0
|
||||||
*/
|
*/
|
||||||
public static <T extends Annotation> ClassContainer from(
|
public static <T extends Annotation> ClassContainer from(T ann, Function<T, Class<?>> classFunction, String innerName,
|
||||||
T ann, Function<T, Class<?>> classFunction, String className,
|
|
||||||
ProcessingEnvironment env, ObfuscationMapper mapper) {
|
ProcessingEnvironment env, ObfuscationMapper mapper) {
|
||||||
String fqn;
|
String fqn;
|
||||||
String[] inner;
|
String[] inner;
|
||||||
fqn = getTypeFromAnnotation(ann, classFunction, env).toString();
|
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);
|
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
|
* Finds and builds a {@link ClassContainer} based on information contained
|
||||||
* within a {@link Find} annotation, else returns a fallback.
|
* within a {@link Find} annotation, else returns a fallback.
|
||||||
|
|
|
@ -7,6 +7,7 @@ import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
import javax.lang.model.element.VariableElement;
|
import javax.lang.model.element.VariableElement;
|
||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
@ -96,7 +97,7 @@ public class FieldContainer {
|
||||||
Find f = finder.getAnnotation(Find.class);
|
Find f = finder.getAnnotation(Find.class);
|
||||||
|
|
||||||
ClassContainer parent = ClassContainer.findOrFallback(
|
ClassContainer parent = ClassContainer.findOrFallback(
|
||||||
ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper),
|
ClassContainer.from((TypeElement) finder.getEnclosingElement(), env, mapper),
|
||||||
f, env, mapper
|
f, env, mapper
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -102,10 +102,9 @@ public class MethodContainer {
|
||||||
//the parent always has a @Patch annotation
|
//the parent always has a @Patch annotation
|
||||||
Patch patchAnn = stub.getEnclosingElement().getAnnotation(Patch.class);
|
Patch patchAnn = stub.getEnclosingElement().getAnnotation(Patch.class);
|
||||||
ClassContainer parent = ClassContainer.findOrFallback(
|
ClassContainer parent = ClassContainer.findOrFallback(
|
||||||
ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper),
|
ClassContainer.from((TypeElement) stub.getEnclosingElement(), env, mapper),
|
||||||
f, env, mapper
|
f, env, mapper
|
||||||
);
|
);
|
||||||
|
|
||||||
String name = !t.methodName().equals("")
|
String name = !t.methodName().equals("")
|
||||||
? t.methodName() //name was specified in target
|
? t.methodName() //name was specified in target
|
||||||
: stub.getSimpleName().toString();
|
: stub.getSimpleName().toString();
|
||||||
|
|
Loading…
Reference in a new issue