summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-04-12 17:08:56 +0200
committer zaaarf <zaaarf@proton.me>2023-04-12 17:08:56 +0200
commit527cef56e6881c88f630e93b90c8d412ed4c4723 (patch)
tree9313ac1c27663c643ce9086e4b766c7ed199d7a9 /src/main/java/ftbsc
parent5973cf6d95cd7c3139d696e32cf44fc28a4ed679 (diff)
feat: generate dummies for all abstract methods, not just targets
Diffstat (limited to 'src/main/java/ftbsc')
-rw-r--r--src/main/java/ftbsc/lll/processor/LilleroProcessor.java2
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java33
2 files changed, 19 insertions, 16 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
index fdddd9a..eb1a3a6 100644
--- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
+++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
@@ -346,7 +346,7 @@ public class LilleroProcessor extends AbstractProcessor {
.addMethod(buildStringReturnMethod("targetClass", obfuscateInjectorMetadata ? targetClass.fqnObf : targetClass.fqn))
.addMethod(buildStringReturnMethod("methodName", obfuscateInjectorMetadata ? target.nameObf : target.name))
.addMethod(buildStringReturnMethod("methodDesc", obfuscateInjectorMetadata ? target.descriptorObf : target.descriptor))
- .addMethods(generateDummies(targets))
+ .addMethods(generateDummies(cl))
.addMethod(generateInjector(toGenerate.get(injName), this.processingEnv))
.build();
diff --git a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
index 62d82e3..b09ffba 100644
--- a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
+++ b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
@@ -13,11 +13,7 @@ import ftbsc.lll.proxies.impl.FieldProxy;
import ftbsc.lll.proxies.impl.MethodProxy;
import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.VariableElement;
-import java.util.Collection;
+import javax.lang.model.element.*;
import java.util.HashSet;
import static ftbsc.lll.processor.tools.ASTUtils.getProxyType;
@@ -102,7 +98,7 @@ public class JavaPoetUtils {
con.addStatement(
"$L.setModifiers($L)",
builderName,
- target == null ? 0 :mapModifiers(target.getModifiers())
+ target == null ? 0 : mapModifiers(target.getModifiers())
);
//set type(s)
@@ -121,19 +117,26 @@ public class JavaPoetUtils {
}
/**
- * Generates a {@link HashSet} of dummy overrides given a {@link Collection} stubs.
- * @param dummies the stubs
+ * Generates a {@link HashSet} of dummy overrides for every abstract method in a given class,
+ * represented as a {@link TypeElement}.
+ * @param clazz the given class
* @return a {@link HashSet} containing the generated {@link MethodSpec}s
* @since 0.5.0
*/
- public static HashSet<MethodSpec> generateDummies(Collection<ExecutableElement> dummies) {
+ public static HashSet<MethodSpec> generateDummies(TypeElement clazz) {
HashSet<MethodSpec> specs = new HashSet<>();
- for(ExecutableElement d : dummies)
- if(d.getModifiers().contains(Modifier.ABSTRACT))
- specs.add(MethodSpec.overriding(d)
- .addStatement("throw new $T($S)", RuntimeException.class, "This is a stub and should not have been called")
- .build()
- );
+ clazz
+ .getEnclosedElements()
+ .stream()
+ .filter(e -> e instanceof ExecutableElement)
+ .map(e -> (ExecutableElement) e)
+ .forEach(e -> {
+ if(e.getModifiers().contains(Modifier.ABSTRACT))
+ specs.add(MethodSpec.overriding(e)
+ .addStatement("throw new $T($S)", RuntimeException.class, "This is a stub and should not have been called")
+ .build()
+ );
+ });
return specs;
}