aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/processor/annotations
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-18 17:24:43 +0100
committer zaaarf <zaaarf@proton.me>2023-03-18 17:24:43 +0100
commit344e66061b31a83f7ace2ab887e80f782f560297 (patch)
treeb8841cdf15a97376cc75206818a989b0e1918e36 /src/main/java/ftbsc/lll/processor/annotations
parent8695612c58141b1d5e0ee274027ebbd2050de6f8 (diff)
parent909f5cfa07464f35814da1686b0ac1a6c3ea03dd (diff)
Merge branch 'version3' into dev
Diffstat (limited to 'src/main/java/ftbsc/lll/processor/annotations')
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/FindField.java12
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/FindMethod.java20
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/Injector.java18
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/MultipleInjectors.java19
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/Target.java13
5 files changed, 77 insertions, 5 deletions
diff --git a/src/main/java/ftbsc/lll/processor/annotations/FindField.java b/src/main/java/ftbsc/lll/processor/annotations/FindField.java
index 9b5a824..40de173 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/FindField.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/FindField.java
@@ -16,6 +16,16 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.CLASS)
@java.lang.annotation.Target(ElementType.METHOD)
public @interface FindField {
- Class<?> parent();
+ /**
+ * @return the {@link Class} object containing the desired field,
+ * 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 field, will default to the empty string
+ * (the name of the annotated method will instead be used)
+ */
String name() default "";
}
diff --git a/src/main/java/ftbsc/lll/processor/annotations/FindMethod.java b/src/main/java/ftbsc/lll/processor/annotations/FindMethod.java
index bf93442..1705619 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/FindMethod.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/FindMethod.java
@@ -17,7 +17,23 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.CLASS)
@java.lang.annotation.Target(ElementType.METHOD)
public @interface FindMethod {
- Class<?> parent();
+ /**
+ * @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;
+
+ /**
+ * @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 "";
- Class<?>[] params();
+
+ /**
+ * @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/Injector.java b/src/main/java/ftbsc/lll/processor/annotations/Injector.java
index f5e22aa..4b74961 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/Injector.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/Injector.java
@@ -1,6 +1,7 @@
package ftbsc.lll.processor.annotations;
import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -10,9 +11,24 @@ import java.lang.annotation.RetentionPolicy;
* as parameters. It will be discarded otherwise.
* It will also be discarded unless the containing class is annotated with {@link Patch}
* and another method within the class is annotated with {@link Target}.
+ * This annotation may be added multiple times, in order to target multiple methods.
* @see Patch
* @see Target
*/
@Retention(RetentionPolicy.CLASS)
+@Repeatable(MultipleInjectors.class)
@java.lang.annotation.Target(ElementType.METHOD)
-public @interface Injector {}
+public @interface Injector {
+ /**
+ * @return the name of the stub annotated with {@link Target} this is referring to.
+ * @since 0.3.0
+ */
+ String targetName() default "";
+
+ /**
+ * @return the parameters of the stub annotated with {@link Target} this is referring
+ * to (used to discern in case of method stubs by the same name)
+ * @since 0.3.0
+ */
+ Class<?>[] params() default {};
+}
diff --git a/src/main/java/ftbsc/lll/processor/annotations/MultipleInjectors.java b/src/main/java/ftbsc/lll/processor/annotations/MultipleInjectors.java
new file mode 100644
index 0000000..8b4b3f8
--- /dev/null
+++ b/src/main/java/ftbsc/lll/processor/annotations/MultipleInjectors.java
@@ -0,0 +1,19 @@
+package ftbsc.lll.processor.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Used to support {@link Injector} as a {@link Repeatable} annotation.
+ * @since 0.3.0
+ */
+@Retention(RetentionPolicy.CLASS)
+@java.lang.annotation.Target(ElementType.METHOD)
+public @interface MultipleInjectors {
+ /**
+ * @return the {@link Injector} annotations, as an array
+ */
+ Injector[] value();
+}
diff --git a/src/main/java/ftbsc/lll/processor/annotations/Target.java b/src/main/java/ftbsc/lll/processor/annotations/Target.java
index 885bd9c..dbe7cf6 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/Target.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/Target.java
@@ -15,4 +15,15 @@ import java.lang.annotation.RetentionPolicy;
*/
@Retention(RetentionPolicy.CLASS)
@java.lang.annotation.Target(ElementType.METHOD)
-public @interface Target {}
+public @interface Target {
+
+ /**
+ * When set to false, tells the processor to first try to match a single method by name,
+ * and to only check parameters if further clarification is needed.
+ * @implNote While non-strict mode is more computationally efficient, it's ultimately not
+ * relevant, as it only matters at compile time. Do not set this to false unless
+ * you know what you're doing.
+ * @since 0.3.0
+ */
+ boolean strict() default true;
+}