mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-21 21:24:49 +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
|
||||
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)",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -95,23 +95,36 @@ 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.
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue