summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/ftbsc/lll/processor/LilleroProcessor.java9
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java24
2 files changed, 25 insertions, 8 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
index 204108c..7a85b8b 100644
--- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
+++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
@@ -243,7 +243,7 @@ public class LilleroProcessor extends AbstractProcessor {
List<ExecutableElement> injectorCandidates = injectors;
List<VariableElement> finderCandidates = methodFinders;
- if(!targetAnn.of().equals("") && injectorNames.contains(targetAnn.of())) {
+ if(!targetAnn.of().equals("")) {
//case 1: find target by name
injectorCandidates =
injectorCandidates
@@ -311,11 +311,6 @@ public class LilleroProcessor extends AbstractProcessor {
for(String injName : toGenerate.keySet()) {
String targetMethodDescriptor = descriptorFromExecutableElement(toGenerate.get(injName).target);
String targetMethodName = findMemberName(targetClass.fqnObf, toGenerate.get(injName).target.getSimpleName().toString(), targetMethodDescriptor, this.mapper);
-
- MethodSpec stubOverride = MethodSpec.overriding(toGenerate.get(injName).targetStub)
- .addStatement("throw new $T($S)", RuntimeException.class, "This is a stub and should not have been called")
- .build();
-
MethodSpec inject = MethodSpec.methodBuilder("inject")
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
@@ -341,7 +336,7 @@ public class LilleroProcessor extends AbstractProcessor {
.addMethod(buildStringReturnMethod("targetClass", targetClass.fqn))
.addMethod(buildStringReturnMethod("methodName", targetMethodName))
.addMethod(buildStringReturnMethod("methodDesc", targetMethodDescriptor))
- .addMethod(stubOverride)
+ .addMethods(generateDummies(targets))
.addMethod(inject)
.build();
diff --git a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
index 2728cc8..4a103a6 100644
--- a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
+++ b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
@@ -20,6 +20,12 @@ import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
import static ftbsc.lll.processor.tools.ASTUtils.*;
/**
@@ -157,7 +163,7 @@ public class JavaPoetUtils {
if(isMethod) {
ExecutableElement executableTarget;
if(f.name().equals("")) //find and validate from stub
- executableTarget = findMethodFromStub(stub, null, env);
+ executableTarget = findMethodFromStub(stub, f, env);
else { //find and validate by name alone
if(LilleroProcessor.badPracticeWarnings) //warn user that he is doing bad stuff
env.getMessager().printMessage(Diagnostic.Kind.WARNING,
@@ -212,4 +218,20 @@ public class JavaPoetUtils {
builderName
);
}
+
+ /**
+ * Generates a {@link HashSet} of dummy overrides given a {@link Collection} stubs.
+ * @param dummies the stubs
+ * @return the generated {@link HashSet}
+ * @since 0.5.0
+ */
+ public static HashSet<MethodSpec> generateDummies(Collection<ExecutableElement> dummies) {
+ HashSet<MethodSpec> specs = new HashSet<>();
+ for(ExecutableElement d : dummies)
+ specs.add(MethodSpec.overriding(d)
+ .addStatement("throw new $T($S)", RuntimeException.class, "This is a stub and should not have been called")
+ .build()
+ );
+ return specs;
+ }
}