mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-12-22 21:04:55 +01:00
fix: bug in main loop, generation of stubs
This commit is contained in:
parent
cd21d0973d
commit
d967afe2e3
2 changed files with 25 additions and 8 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue