diff --git a/compiler/src/main/java/io/jbock/simple/processor/binding/ComponentElement.java b/compiler/src/main/java/io/jbock/simple/processor/binding/ComponentElement.java index 2469c4a..13f58dd 100644 --- a/compiler/src/main/java/io/jbock/simple/processor/binding/ComponentElement.java +++ b/compiler/src/main/java/io/jbock/simple/processor/binding/ComponentElement.java @@ -26,7 +26,6 @@ public final class ComponentElement { private final TypeElement element; private final KeyFactory keyFactory; - private final InjectBinding.Factory injectBindingFactory; private final Supplier generatedClass = memoize(() -> { ClassName className = ClassName.get(element()); @@ -74,7 +73,7 @@ public final class ComponentElement { continue; // ignore } Key key = keyFactory().getKey(method); - InjectBinding b = injectBindingFactory().create(method); + InjectBinding b = keyFactory().createBinding(method); result.put(key, b); } return result; @@ -125,11 +124,9 @@ public final class ComponentElement { @Inject public ComponentElement( TypeElement element, - KeyFactory keyFactory, - InjectBinding.Factory injectBindingFactory) { + KeyFactory keyFactory) { this.element = element; this.keyFactory = keyFactory; - this.injectBindingFactory = injectBindingFactory; } public TypeElement element() { @@ -164,10 +161,6 @@ private KeyFactory keyFactory() { return keyFactory; } - private InjectBinding.Factory injectBindingFactory() { - return injectBindingFactory; - } - public Optional parameterBinding(Key key) { return Optional.ofNullable(parameterBindings.get().get(key)); } diff --git a/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBinding.java b/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBinding.java index fc311b2..a77002d 100644 --- a/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBinding.java +++ b/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBinding.java @@ -4,9 +4,7 @@ import io.jbock.javapoet.ParameterSpec; import io.jbock.javapoet.ParameterizedTypeName; import io.jbock.javapoet.TypeName; -import io.jbock.simple.Inject; import io.jbock.simple.Provides; -import io.jbock.simple.processor.util.ValidationFailure; import io.jbock.simple.processor.util.Visitors; import io.jbock.simple.processor.writing.NamedBinding; @@ -105,7 +103,7 @@ private static String lowerFirst(String s) { .map(parameter -> new DependencyRequest(keyFactory().getKey(parameter), parameter, element())) .collect(Collectors.toList())); - private InjectBinding( + InjectBinding( Key key, KeyFactory keyFactory, ExecutableElement bindingElement) { @@ -159,23 +157,4 @@ public String toString() { private KeyFactory keyFactory() { return keyFactory; } - - public static final class Factory { - private final KeyFactory keyFactory; - - @Inject - public Factory(KeyFactory keyFactory) { - this.keyFactory = keyFactory; - } - - InjectBinding create(ExecutableElement m) { - Key key = keyFactory.getKey(m); - if (m.getKind() == ElementKind.CONSTRUCTOR) { - if (key.qualifier().isPresent()) { - throw new ValidationFailure("Constructors can't have qualifiers", m); - } - } - return new InjectBinding(key, keyFactory, m); - } - } } diff --git a/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBindingFactory.java b/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBindingFactory.java index 14d0add..fabf279 100644 --- a/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBindingFactory.java +++ b/compiler/src/main/java/io/jbock/simple/processor/binding/InjectBindingFactory.java @@ -19,16 +19,16 @@ public final class InjectBindingFactory implements ClearableCache { private final Map> injectBindingCache = new HashMap<>(); private final TypeTool tool; - private final InjectBinding.Factory injectBindingFactory; + private final KeyFactory keyFactory; private final InjectBindingScanner injectBindingScanner; @Inject public InjectBindingFactory( TypeTool tool, - InjectBinding.Factory injectBindingFactory, + KeyFactory keyFactory, InjectBindingScanner injectBindingScanner) { this.tool = tool; - this.injectBindingFactory = injectBindingFactory; + this.keyFactory = keyFactory; this.injectBindingScanner = injectBindingScanner; } @@ -40,7 +40,7 @@ private Map injectBindingsMiss(TypeElement typeElement) { Map result = new LinkedHashMap<>(); List methods = injectBindingScanner.scan(typeElement); for (ExecutableElement method : methods) { - InjectBinding b = injectBindingFactory.create(method); + InjectBinding b = keyFactory.createBinding(method); result.put(b.key(), b); } return result; diff --git a/compiler/src/main/java/io/jbock/simple/processor/binding/KeyFactory.java b/compiler/src/main/java/io/jbock/simple/processor/binding/KeyFactory.java index b861ffd..357ec43 100644 --- a/compiler/src/main/java/io/jbock/simple/processor/binding/KeyFactory.java +++ b/compiler/src/main/java/io/jbock/simple/processor/binding/KeyFactory.java @@ -8,6 +8,7 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; @@ -62,7 +63,7 @@ public Key getKey(ExecutableElement element) { return key; } - public Key getKey(VariableElement parameter) { + Key getKey(VariableElement parameter) { Key key = keyCache.get(parameter); if (key != null) { return key; @@ -78,6 +79,16 @@ private boolean hasQualifierAnnotation(AnnotationMirror mirror) { return tool.hasQualifierAnnotation(element); } + InjectBinding createBinding(ExecutableElement m) { + Key key = getKey(m); + if (m.getKind() == ElementKind.CONSTRUCTOR) { + if (key.qualifier().isPresent()) { + throw new ValidationFailure("Constructors can't have qualifiers", m); + } + } + return new InjectBinding(key, this, m); + } + TypeTool tool() { return tool; }