mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-22 10:24:50 +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}.
|
* @return whether it can be converted into a valid {@link IInjector}.
|
||||||
*/
|
*/
|
||||||
private boolean isValidInjector(TypeElement elem) {
|
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 classNodeType = this.processingEnv.getElementUtils().getTypeElement("org.objectweb.asm.tree.ClassNode").asType();
|
||||||
TypeMirror methodNodeType = this.processingEnv.getElementUtils().getTypeElement("org.objectweb.asm.tree.MethodNode").asType();
|
TypeMirror methodNodeType = this.processingEnv.getElementUtils().getTypeElement("org.objectweb.asm.tree.MethodNode").asType();
|
||||||
if (elem.getEnclosedElements().stream().anyMatch(e -> e.getAnnotation(Target.class) != null)
|
if (elem.getEnclosedElements().stream().anyMatch(e -> e.getAnnotation(Target.class) != null)
|
||||||
|
@ -200,7 +194,7 @@ public class LilleroProcessor extends AbstractProcessor {
|
||||||
ClassContainer targetClass = ClassContainer.from(
|
ClassContainer targetClass = ClassContainer.from(
|
||||||
patchAnn,
|
patchAnn,
|
||||||
Patch::value,
|
Patch::value,
|
||||||
patchAnn.className(),
|
patchAnn.innerClass(),
|
||||||
this.processingEnv,
|
this.processingEnv,
|
||||||
this.mapper
|
this.mapper
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,9 +26,9 @@ public @interface Find {
|
||||||
Class<?> value() default Object.class;
|
Class<?> value() default Object.class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This can be either the fully-qualified name to be used in place of {@link #value()} to
|
* This is the inner class name to append after a $ symbol to the already acquired
|
||||||
* represent the parent class or an inner class name to append after a $ symbol to the
|
* fully-qualified name. If it's a number instead of a valid name, the class will be
|
||||||
* already acquired fully-qualified name.
|
* 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.
|
* 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,
|
* @return the name of the inner class that contains the target,
|
||||||
* defaults to empty string (not an inner class)
|
* defaults to empty string (not an inner class)
|
||||||
|
|
|
@ -17,15 +17,15 @@ public @interface Patch {
|
||||||
/**
|
/**
|
||||||
* @return the {@link Class} to target for patching
|
* @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()}
|
* This is the inner class name to append after a $ symbol to the already acquired
|
||||||
* or an 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
|
||||||
* fully-qualified name.
|
* treated as an anonymous class, and will therefore be automatically unverified.
|
||||||
* @return the name of the inner class that contains the target,
|
* @return the name of the inner class that contains the target,
|
||||||
* defaults to empty string (not an inner class)
|
* defaults to empty string (not an inner class)
|
||||||
* @since 0.5.0
|
* @since 0.5.0
|
||||||
*/
|
*/
|
||||||
String className() default "";
|
String innerClass() default "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,6 @@ public class ClassContainer {
|
||||||
throw new TargetNotFoundException("class", inner);
|
throw new TargetNotFoundException("class", inner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fqn = fqnBuilder.toString();
|
this.fqn = fqnBuilder.toString();
|
||||||
this.fqnObf = findClassName(this.fqn, mapper);
|
this.fqnObf = findClassName(this.fqn, mapper);
|
||||||
this.elem = elem;
|
this.elem = elem;
|
||||||
|
@ -106,19 +105,11 @@ public class ClassContainer {
|
||||||
*/
|
*/
|
||||||
public static <T extends Annotation> ClassContainer from(
|
public static <T extends Annotation> ClassContainer from(
|
||||||
T ann, Function<T, Class<?>> classFunction, String className,
|
T ann, Function<T, Class<?>> classFunction, String className,
|
||||||
ProcessingEnvironment env, ObfuscationMapper mapper)
|
ProcessingEnvironment env, ObfuscationMapper mapper) {
|
||||||
{
|
|
||||||
String fqn;
|
String fqn;
|
||||||
String[] inner;
|
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();
|
fqn = getTypeFromAnnotation(ann, classFunction, env).toString();
|
||||||
inner = className.equals("") ? null : className.split("//$");
|
inner = className.equals("") ? null : className.split("//$");
|
||||||
}
|
|
||||||
|
|
||||||
return new ClassContainer(fqn, inner, env, mapper);
|
return new ClassContainer(fqn, inner, env, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,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.className(), env, mapper),
|
ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper),
|
||||||
f, env, mapper
|
f, env, mapper
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ 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.className(), env, mapper),
|
ClassContainer.from(patchAnn, Patch::value, patchAnn.innerClass(), env, mapper),
|
||||||
f, env, mapper
|
f, env, mapper
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue