mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-14 17:19:21 +01:00
fix: logic error in main loop
This commit is contained in:
parent
92a4273b10
commit
309415056e
1 changed files with 32 additions and 36 deletions
|
@ -384,64 +384,60 @@ public class LilleroProcessor extends AbstractProcessor {
|
||||||
for(Injector injectorAnn : minjAnn) { //java is dumb
|
for(Injector injectorAnn : minjAnn) { //java is dumb
|
||||||
List<ExecutableElement> injectionCandidates = targets;
|
List<ExecutableElement> injectionCandidates = targets;
|
||||||
|
|
||||||
//case 1: it has a name, try to match it
|
if(!injectorAnn.targetName().equals("") && targetNames.contains(injectorAnn.targetName())) {
|
||||||
if(!injectorAnn.targetName().equals("") && targetNames.contains(injectorAnn.targetName()))
|
//case 1: it has a name, try to match it
|
||||||
injectionCandidates =
|
injectionCandidates =
|
||||||
injectionCandidates
|
injectionCandidates
|
||||||
.stream()
|
.stream()
|
||||||
.filter(i -> i.getSimpleName().toString().equals(injectorAnn.targetName()))
|
.filter(i -> i.getSimpleName().toString().equals(injectorAnn.targetName()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} else if(targets.size() == 1) {
|
||||||
//case 2: try to match by injectTargetName
|
//case 2: there is only one target
|
||||||
String inferredName = inj.getSimpleName()
|
|
||||||
.toString()
|
|
||||||
.replaceFirst("inject", "");
|
|
||||||
injectionCandidates =
|
|
||||||
injectionCandidates
|
|
||||||
.stream()
|
|
||||||
.filter(t -> t.getSimpleName().toString().equalsIgnoreCase(inferredName))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
//case 3: there is only one target
|
|
||||||
if(targets.size() == 1)
|
|
||||||
injectionCandidates.add(targets.get(0));
|
injectionCandidates.add(targets.get(0));
|
||||||
|
} else {
|
||||||
|
//case 3: try to match by injectTargetName
|
||||||
|
String inferredName = inj.getSimpleName()
|
||||||
|
.toString()
|
||||||
|
.replaceFirst("inject", "");
|
||||||
|
injectionCandidates =
|
||||||
|
injectionCandidates
|
||||||
|
.stream()
|
||||||
|
.filter(t -> t.getSimpleName().toString().equalsIgnoreCase(inferredName))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
ExecutableElement injectionTarget = null;
|
ExecutableElement injectionTarget = null;
|
||||||
|
|
||||||
if(injectionCandidates.size() == 1)
|
if(injectionCandidates.size() == 1)
|
||||||
injectionTarget = injectionCandidates.get(0);
|
injectionTarget = injectionCandidates.get(0);
|
||||||
|
else {
|
||||||
|
List<TypeMirror> params = classArrayFromAnnotation(injectorAnn, Injector::params, processingEnv.getElementUtils());
|
||||||
|
|
||||||
List<TypeMirror> params = classArrayFromAnnotation(injectorAnn, Injector::params, processingEnv.getElementUtils());
|
if(params.size() != 0) {
|
||||||
|
StringBuilder descr = new StringBuilder("(");
|
||||||
if(params.size() != 0) {
|
for(TypeMirror p : params)
|
||||||
StringBuilder descr = new StringBuilder("(");
|
descr.append(descriptorFromType(TypeName.get(p)));
|
||||||
for(TypeMirror p : params)
|
descr.append(")");
|
||||||
descr.append(descriptorFromType(TypeName.get(p)));
|
injectionCandidates =
|
||||||
descr.append(")");
|
injectionCandidates
|
||||||
injectionCandidates =
|
.stream()
|
||||||
injectionCandidates
|
.filter(t -> //we care about arguments but not really about return type
|
||||||
.stream()
|
|
||||||
.filter(t -> //we care about arguments but not really about return type
|
|
||||||
descr.toString()
|
descr.toString()
|
||||||
.split("\\)")[0]
|
.split("\\)")[0]
|
||||||
.equalsIgnoreCase(descriptorFromExecutableElement(t).split("\\)")[0])
|
.equalsIgnoreCase(descriptorFromExecutableElement(t).split("\\)")[0])
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(injectionCandidates.size() == 1)
|
if(injectionCandidates.size() == 1)
|
||||||
injectionTarget = injectionCandidates.get(0);
|
injectionTarget = injectionCandidates.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
//if we haven't found it yet, it's an ambiguity
|
//if we haven't found it yet, it's an ambiguity
|
||||||
if(injectionTarget == null)
|
if(injectionTarget == null)
|
||||||
throw new AmbiguousDefinitionException("Unclear target for injector " + inj.getSimpleName().toString() + "!");
|
throw new AmbiguousDefinitionException("Unclear target for injector " + inj.getSimpleName().toString() + "!");
|
||||||
else toGenerate.put(
|
else toGenerate.put(
|
||||||
cl.getSimpleName().toString() + "Injector" + iterationNumber,
|
cl.getSimpleName().toString() + "Injector" + iterationNumber,
|
||||||
new InjectorInfo(
|
new InjectorInfo(inj, findRealMethod(injectionTarget, mapper))
|
||||||
inj, findRealMethod(
|
|
||||||
injectionTarget,
|
|
||||||
mapper
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
iterationNumber++;
|
iterationNumber++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue