diff options
4 files changed, 40 insertions, 7 deletions
diff --git a/annotations/src/main/java/com/yahoo/component/annotation/Inject.java b/annotations/src/main/java/com/yahoo/component/annotation/Inject.java new file mode 100644 index 00000000000..dd11635ba3f --- /dev/null +++ b/annotations/src/main/java/com/yahoo/component/annotation/Inject.java @@ -0,0 +1,19 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.component.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Use this annotation to specify which constructor should be used when constructing a component. + * + * @author bjorncs + */ +@Target(CONSTRUCTOR) +@Retention(RUNTIME) +@Documented +public @interface Inject {} diff --git a/annotations/src/main/java/com/yahoo/component/annotation/package-info.java b/annotations/src/main/java/com/yahoo/component/annotation/package-info.java new file mode 100644 index 00000000000..89e53b1f5ee --- /dev/null +++ b/annotations/src/main/java/com/yahoo/component/annotation/package-info.java @@ -0,0 +1,6 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +/** + * @author bjorncs + */ +@com.yahoo.api.annotations.PublicApi +package com.yahoo.component.annotation;
\ No newline at end of file diff --git a/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java b/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java index 029213c0119..e22897903db 100644 --- a/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java +++ b/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java @@ -1,15 +1,22 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.model.graph; -import com.google.inject.Inject; import com.yahoo.component.ComponentId; import com.yahoo.config.model.ConfigModel; import com.yahoo.config.model.ConfigModelContext; -import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.ConfigModelInstanceFactory; +import com.yahoo.config.model.builder.xml.ConfigModelBuilder; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Represents a node in the dependency graph, and contains information about a builders dependencies. @@ -37,7 +44,8 @@ public class ModelNode<MODEL extends ConfigModel> implements ConfigModelInstance private Constructor<MODEL> findConstructor(Class<MODEL> clazz) { for (Constructor<?> ctor : clazz.getDeclaredConstructors()) { - if (ctor.getAnnotation(Inject.class) != null) { + if (ctor.getAnnotation(com.google.inject.Inject.class) != null + || ctor.getAnnotation(com.yahoo.component.annotation.Inject.class) != null) { return (Constructor<MODEL>) ctor; } } diff --git a/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java index bf7366cc60f..e5a66fea8d1 100644 --- a/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java +++ b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.di.componentgraph.core; -import com.google.inject.Inject; import com.google.inject.Key; import com.yahoo.collections.Pair; import com.yahoo.component.AbstractComponent; @@ -280,7 +279,8 @@ public class ComponentNode extends Node { Constructor<?> annotated = null; for (Constructor<?> ctor : publicConstructors) { - Annotation annotation = ctor.getAnnotation(Inject.class); + Annotation annotation = ctor.getAnnotation(com.google.inject.Inject.class); + if (annotation == null) annotation = ctor.getAnnotation(com.yahoo.component.annotation.Inject.class); if (annotation != null) { if (annotated == null) { annotated = ctor; |