mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-13 01:39:22 +01:00
feat: @Patch's value field is now mandatory
This commit is contained in:
parent
3344fd766f
commit
2c2b24e5b4
6 changed files with 17 additions and 32 deletions
|
@ -165,12 +165,6 @@ public class LilleroProcessor extends AbstractProcessor {
|
|||
* @return whether it can be converted into a valid {@link IInjector}.
|
||||
*/
|
||||
private boolean isValidInjector(TypeElement elem) {
|
||||
Patch p = elem.getAnnotation(Patch.class);
|
||||
if(getTypeFromAnnotation(p, Patch::value, this.processingEnv).toString().equals("java.lang.Object") && p.className().equals("")) {
|
||||
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
|
||||
String.format("Empty @Patch annotation on class %s, skipping.", elem));
|
||||
return false;
|
||||
}
|
||||
TypeMirror classNodeType = this.processingEnv.getElementUtils().getTypeElement("org.objectweb.asm.tree.ClassNode").asType();
|
||||
TypeMirror methodNodeType = this.processingEnv.getElementUtils().getTypeElement("org.objectweb.asm.tree.MethodNode").asType();
|
||||
if (elem.getEnclosedElements().stream().anyMatch(e -> e.getAnnotation(Target.class) != null)
|
||||
|
@ -200,7 +194,7 @@ public class LilleroProcessor extends AbstractProcessor {
|
|||
ClassContainer targetClass = ClassContainer.from(
|
||||
patchAnn,
|
||||
Patch::value,
|
||||
patchAnn.className(),
|
||||
patchAnn.innerClass(),
|
||||
this.processingEnv,
|
||||
this.mapper
|
||||
);
|
||||
|
|
|
@ -26,9 +26,9 @@ public @interface Find {
|
|||
Class<?> value() default Object.class;
|
||||
|
||||
/**
|
||||
* This can be either the fully-qualified name to be used in place of {@link #value()} to
|
||||
* represent the parent class or an inner class name to append after a $ symbol to the
|
||||
* already acquired fully-qualified name.
|
||||
* This is the inner class name to append after a $ symbol to the already acquired
|
||||
* fully-qualified name. If it's a number instead of a valid name, the class will be
|
||||
* treated as an anonymous class, and will therefore be automatically unverified.
|
||||
* For a {@link TypeProxy}, this refers to the class itself rather than the parent.
|
||||
* @return the name of the inner class that contains the target,
|
||||
* defaults to empty string (not an inner class)
|
||||
|
|
|
@ -17,15 +17,15 @@ public @interface Patch {
|
|||
/**
|
||||
* @return the {@link Class} to target for patching
|
||||
*/
|
||||
Class<?> value() default Object.class;
|
||||
Class<?> value();
|
||||
|
||||
/**
|
||||
* This can be either the fully-qualified name to be used in place of {@link #value()}
|
||||
* or an inner class name to append after a $ symbol to the already acquired
|
||||
* fully-qualified name.
|
||||
* This is the inner class name to append after a $ symbol to the already acquired
|
||||
* fully-qualified name. If it's a number instead of a valid name, the class will be
|
||||
* treated as an anonymous class, and will therefore be automatically unverified.
|
||||
* @return the name of the inner class that contains the target,
|
||||
* defaults to empty string (not an inner class)
|
||||
* @since 0.5.0
|
||||
*/
|
||||
String className() default "";
|
||||
String innerClass() default "";
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ public class ClassContainer {
|
|||
throw new TargetNotFoundException("class", inner);
|
||||
}
|
||||
}
|
||||
|
||||
this.fqn = fqnBuilder.toString();
|
||||
this.fqnObf = findClassName(this.fqn, mapper);
|
||||
this.elem = elem;
|
||||
|
@ -106,19 +105,11 @@ public class ClassContainer {
|
|||
*/
|
||||
public static <T extends Annotation> ClassContainer from(
|
||||
T ann, Function<T, Class<?>> classFunction, String className,
|
||||
ProcessingEnvironment env, ObfuscationMapper mapper)
|
||||
{
|
||||
ProcessingEnvironment env, ObfuscationMapper mapper) {
|
||||
String fqn;
|
||||
String[] inner;
|
||||
if(className.contains(".")) {
|
||||
String[] split = className.split("//$");
|
||||
fqn = split[0];
|
||||
inner = split.length == 1 ? null : Arrays.copyOfRange(split, 1, split.length - 1);
|
||||
} else {
|
||||
fqn = getTypeFromAnnotation(ann, classFunction, env).toString();
|
||||
inner = className.equals("") ? null : className.split("//$");
|
||||
}
|
||||
|
||||
fqn = getTypeFromAnnotation(ann, classFunction, env).toString();
|
||||
inner = className.equals("") ? null : className.split("//$");
|
||||
return new ClassContainer(fqn, inner, env, mapper);
|
||||
}
|
||||
|
||||
|
@ -139,4 +130,4 @@ public class ClassContainer {
|
|||
? fallback
|
||||
: cl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class FieldContainer {
|
|||
Find f = finder.getAnnotation(Find.class);
|
||||
|
||||
ClassContainer parent = ClassContainer.findOrFallback(
|
||||
ClassContainer.from(patchAnn, Patch::value, patchAnn.className(), env, mapper),
|
||||
ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper),
|
||||
f, env, mapper
|
||||
);
|
||||
|
||||
|
@ -116,4 +116,4 @@ public class FieldContainer {
|
|||
|
||||
return new FieldContainer(parent, name, descriptor, env, mapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ 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.className(), env, mapper),
|
||||
ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper),
|
||||
f, env, mapper
|
||||
);
|
||||
|
||||
|
@ -115,4 +115,4 @@ public class MethodContainer {
|
|||
|
||||
return new MethodContainer(parent, name, descriptor, t.strict(), t.bridge(), env, mapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue