summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-18 19:12:53 +0100
committer zaaarf <zaaarf@proton.me>2023-03-18 19:12:53 +0100
commita96417ece93e25148ab21c2f684a7d469f8f4d3f (patch)
treeabd0ae95463aa960442a379edf1d908ea62819d3
parenteea87d367f33b7c45b453f84227102057d3ca112 (diff)
feat: initial implementation of anonymous class support, merged FindField and FindMethod
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/Find.java56
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/FindMethod.java39
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/Patch.java15
3 files changed, 71 insertions, 39 deletions
diff --git a/src/main/java/ftbsc/lll/processor/annotations/Find.java b/src/main/java/ftbsc/lll/processor/annotations/Find.java
new file mode 100644
index 0000000..5f31325
--- /dev/null
+++ b/src/main/java/ftbsc/lll/processor/annotations/Find.java
@@ -0,0 +1,56 @@
+package ftbsc.lll.processor.annotations;
+
+import ftbsc.lll.proxies.FieldProxy;
+import ftbsc.lll.proxies.MethodProxy;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Overrides the marked method in the Injector, having the
+ * implementation return a built {@link MethodProxy} or
+ * {@link FieldProxy} with the specified characteristics.
+ * @since 0.4.0
+ */
+@Retention(RetentionPolicy.CLASS)
+@java.lang.annotation.Target(ElementType.METHOD)
+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)
+ */
+ Class<?> parent() default Object.class;
+
+ /**
+ * @return the name of the inner class that contains the target,
+ * defaults to empty string (not an inner class)
+ * @since 0.4.0
+ */
+ String parentInnerClass() default "";
+
+ /**
+ * @return the anonymous class counter (1 for the first, 2 for
+ * the second, 3 for the third...) for the class that contains
+ * the target, defaults to 0 (not an anonymous class)
+ * @since 0.4.0
+ */
+ int parentAnonymousClassCounter() default 0;
+
+ /**
+ * The name of the class member to find. If omitted, the name of the
+ * annotated method will be used.
+ * @return the name of the target, will default to the empty string
+ * (the name of the annotated method will instead be used)
+ */
+ String name() default "";
+
+ /**
+ * Only use if the target is a method.
+ * @return a list of the parameters of the method, will default to empty
+ * array (in that case, an attempt will be made to match a method without
+ * args first)
+ */
+ Class<?>[] params() default {};
+}
diff --git a/src/main/java/ftbsc/lll/processor/annotations/FindMethod.java b/src/main/java/ftbsc/lll/processor/annotations/FindMethod.java
deleted file mode 100644
index 25db816..0000000
--- a/src/main/java/ftbsc/lll/processor/annotations/FindMethod.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package ftbsc.lll.processor.annotations;
-
-import ftbsc.lll.proxies.MethodProxy;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * Overrides the marked method in the Injector, having the
- * implementation return a built {@link MethodProxy} with
- * the specified parameters.
- * @since 0.2.0
- */
-@Retention(RetentionPolicy.CLASS)
-@java.lang.annotation.Target(ElementType.METHOD)
-public @interface FindMethod {
- /**
- * @return the {@link Class} object containing the desired method,
- * or the {@link Object} class if not specified (the {@link Class}
- * from {@link Patch#value()} is instead used)
- */
- Class<?> parent() default Object.class;
-
- /**
- * The name of the method to find. If omitted, the name of the annotated
- * method will be used.
- * @return the name of the method, will default to the empty string
- * (the name of the annotated method will instead be used)
- */
- String name() default "";
-
- /**
- * @return a list of the parameters of the method, will default to empty
- * array (in that case, an attempt will be made to match a method without
- * args first)
- */
- Class<?>[] params() default {};
-}
diff --git a/src/main/java/ftbsc/lll/processor/annotations/Patch.java b/src/main/java/ftbsc/lll/processor/annotations/Patch.java
index 6ad360b..0dcc377 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/Patch.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/Patch.java
@@ -23,4 +23,19 @@ public @interface Patch {
* @return the patching reason, for logging, defaults to "No reason specified."
*/
String reason() default "No reason specified.";
+
+ /**
+ * @return the name of the inner class that should be targeted,
+ * defaults to empty string (not an inner class)
+ * @since 0.4.0
+ */
+ String innerClass() default "";
+
+ /**
+ * @return the anonymous class counter (1 for the first, 2 for
+ * the second, 3 for the third...) for the class that should be
+ * targeted, defaults to 0 (not an anonymous class)
+ * @since 0.4.0
+ */
+ int anonymousClassCounter() default 0;
}