aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-04-12 15:42:17 +0200
committer zaaarf <zaaarf@proton.me>2023-04-12 15:42:17 +0200
commit2c2b24e5b40a48d443b3caf13abe7661284129a3 (patch)
tree5d175500f52b3b638056ccdf365137a76b0f3166
parent3344fd766f6e7e0e405c3c2b4c02a8b7e05c7e3c (diff)
feat: @Patch's value field is now mandatory
-rw-r--r--src/main/java/ftbsc/lll/processor/LilleroProcessor.java8
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/Find.java6
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/Patch.java10
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/containers/ClassContainer.java17
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java4
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java4
6 files changed, 17 insertions, 32 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
index 15e1cd3..467fa88 100644
--- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
+++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
@@ -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
);
diff --git a/src/main/java/ftbsc/lll/processor/annotations/Find.java b/src/main/java/ftbsc/lll/processor/annotations/Find.java
index 8d28671..0d43d33 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/Find.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/Find.java
@@ -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)
diff --git a/src/main/java/ftbsc/lll/processor/annotations/Patch.java b/src/main/java/ftbsc/lll/processor/annotations/Patch.java
index e0472da..f5d2698 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/Patch.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/Patch.java
@@ -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 "";
}
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 67ec26f..dd5635f 100644
--- a/src/main/java/ftbsc/lll/processor/tools/containers/ClassContainer.java
+++ b/src/main/java/ftbsc/lll/processor/tools/containers/ClassContainer.java
@@ -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;
}
-} \ No newline at end of file
+}
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 3f08201..5b6564f 100644
--- a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java
+++ b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java
@@ -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);
}
-} \ No newline at end of file
+}
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 5315ee8..8bef323 100644
--- a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java
+++ b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java
@@ -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);
}
-} \ No newline at end of file
+}