summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-02-27 12:45:39 +0100
committer zaaarf <zaaarf@proton.me>2023-02-27 12:45:39 +0100
commitf01f45f9cf416d26df2481fb105294a8364f504c (patch)
tree7a9141f40c87d0c594e5e83d134fc777827f673b
parent0e8ae4b69a06e357946e03f2ae0df439a89594ce (diff)
chore: more code refactoring for quality
-rw-r--r--build.gradle3
-rw-r--r--src/main/java/ftbsc/lll/processor/LilleroProcessor.java18
-rw-r--r--src/main/java/ftbsc/lll/processor/annotations/Injector.java7
3 files changed, 10 insertions, 18 deletions
diff --git a/build.gradle b/build.gradle
index 9f6a331..de0c181 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,8 +3,6 @@ plugins {
}
group 'ftbsc.lll.processor'
-sourceCompatibility = 1.8
-targetCompatibility = 1.8
repositories {
mavenCentral()
@@ -15,5 +13,4 @@ repositories {
dependencies {
implementation 'com.squareup:javapoet:1.13.0'
implementation 'ftbsc:lll:0.2.1'
- implementation 'org.ow2.asm:asm-commons:9.4'
} \ No newline at end of file
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
index 321116e..28e7217 100644
--- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
+++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
@@ -9,8 +9,6 @@ import ftbsc.lll.processor.exceptions.MappingNotFoundException;
import ftbsc.lll.processor.exceptions.MappingsFileNotFoundException;
import ftbsc.lll.tools.DescriptorBuilder;
import ftbsc.lll.tools.SrgMapper;
-import org.objectweb.asm.tree.ClassNode;
-import org.objectweb.asm.tree.MethodNode;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
@@ -79,7 +77,7 @@ public class LilleroProcessor extends AbstractProcessor {
/**
* This checks whether a given class contains the requirements to be parsed into a Lillero injector.
* It must have at least one method annotated with {@link Target}, and one method annotated with {@link Injector}
- * that must be public, static and take in a {@link ClassNode} and a {@link MethodNode}.
+ * that must be public, static and take in a ClassNode and MethodNode from ObjectWeb's ASM library.
* @param elem the element to check.
* @return whether it can be converted into a valid {@link IInjector}.
*/
@@ -122,6 +120,12 @@ public class LilleroProcessor extends AbstractProcessor {
.get(); //will never be null so can ignore warning
}
+ /**
+ * Builds a {@link MethodSpec} for a public method whose body simply returns a {@link String}.
+ * @param name the name of the method
+ * @param returnString the {@link String} to return
+ * @return the built {@link MethodSpec}
+ */
private static MethodSpec buildStringReturnMethod(String name, String returnString) {
return MethodSpec.methodBuilder(name)
.addModifiers(Modifier.PUBLIC)
@@ -231,12 +235,6 @@ public class LilleroProcessor extends AbstractProcessor {
String injectorSimpleClassName = cl.getSimpleName().toString() + "Injector";
String injectorClassName = packageName + "." + injectorSimpleClassName;
- MethodSpec methodDesc = MethodSpec.methodBuilder("methodDesc")
- .addModifiers(Modifier.PUBLIC)
- .returns(String.class)
- .addCode("return $S;", targetMethodDescriptor)
- .build();
-
MethodSpec inject = MethodSpec.methodBuilder("inject")
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
@@ -258,7 +256,7 @@ public class LilleroProcessor extends AbstractProcessor {
.addMethod(buildStringReturnMethod("reason", ann.reason()))
.addMethod(buildStringReturnMethod("targetClass", targetClassSrgName.replace('/', '.')))
.addMethod(buildStringReturnMethod("methodName", targetMethodSrgName))
- .addMethod(methodDesc)
+ .addMethod(buildStringReturnMethod("methodDesc", targetMethodDescriptor))
.addMethod(inject)
.build();
diff --git a/src/main/java/ftbsc/lll/processor/annotations/Injector.java b/src/main/java/ftbsc/lll/processor/annotations/Injector.java
index df523ac..1e2d8dd 100644
--- a/src/main/java/ftbsc/lll/processor/annotations/Injector.java
+++ b/src/main/java/ftbsc/lll/processor/annotations/Injector.java
@@ -4,13 +4,10 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import org.objectweb.asm.tree.ClassNode;
-import org.objectweb.asm.tree.MethodNode;
-
/**
* Marks a method as the injector method for purposes of generation.
- * The method itself should be {@code public static}, and take in a {@link ClassNode}
- * and a {@link MethodNode} as parameters. It will be discarded otherwise.
+ * The method itself should be {@code public static}, and take in a ClassNode and MethodNode
+ * (from the ObjectWeb ASM library) as parameters. It will be discarded otherwise.
* It will also be discarded unless the containing class is not annotated with {@link Patch}
* and no other method within the class is annotated with {@link Target}.
* @see Patch