Package com.google.inject.spi
Class InjectionPoint
- java.lang.Object
-
- com.google.inject.spi.InjectionPoint
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
static <T> InjectionPoint
forConstructor(Constructor<T> constructor)
Returns a new injection point for the specified constructor.static <T> InjectionPoint
forConstructor(Constructor<T> constructor, TypeLiteral<? extends T> type)
Returns a new injection point for the specified constructor oftype
.static InjectionPoint
forConstructorOf(TypeLiteral<?> type)
Returns a new injection point for the injectable constructor oftype
.static InjectionPoint
forConstructorOf(TypeLiteral<?> type, boolean atInjectRequired)
Returns a new injection point for the injectable constructor oftype
.static InjectionPoint
forConstructorOf(Class<?> type)
Returns a new injection point for the injectable constructor oftype
.static Set<InjectionPoint>
forInstanceMethodsAndFields(TypeLiteral<?> type)
Returns all instance method and field injection points ontype
.static Set<InjectionPoint>
forInstanceMethodsAndFields(Class<?> type)
Returns all instance method and field injection points ontype
.static <T> InjectionPoint
forMethod(Method method, TypeLiteral<T> type)
Returns a new injection point for the specified method oftype
.static Set<InjectionPoint>
forStaticMethodsAndFields(TypeLiteral<?> type)
Returns all static method and field injection points ontype
.static Set<InjectionPoint>
forStaticMethodsAndFields(Class<?> type)
Returns all static method and field injection points ontype
.TypeLiteral<?>
getDeclaringType()
Returns the generic type that defines this injection point.List<Dependency<?>>
getDependencies()
Returns the dependencies for this injection point.Member
getMember()
Returns the injected constructor, field, or method.int
hashCode()
boolean
isOptional()
Returns true if this injection point shall be skipped if the injector cannot resolve bindings for all required dependencies.boolean
isToolable()
Returns true if the element is annotated with @Toolable
.String
toString()
-
-
-
Method Detail
-
getMember
public Member getMember()
Returns the injected constructor, field, or method.
-
getDependencies
public List<Dependency<?>> getDependencies()
Returns the dependencies for this injection point. If the injection point is for a method or constructor, the dependencies will correspond to that member's parameters. Field injection points always have a single dependency for the field itself.- Returns:
- a possibly-empty list
-
isOptional
public boolean isOptional()
Returns true if this injection point shall be skipped if the injector cannot resolve bindings for all required dependencies. Both explicit bindings (as specified in a module), and implicit bindings (@ImplementedBy
, default constructors etc.) may be used to satisfy optional injection points.
-
isToolable
public boolean isToolable()
Returns true if the element is annotated with @Toolable
.- Since:
- 3.0
-
getDeclaringType
public TypeLiteral<?> getDeclaringType()
Returns the generic type that defines this injection point. If the member exists on a parameterized type, the result will include more type information than the member'sraw declaring class
.- Since:
- 3.0
-
forConstructor
public static <T> InjectionPoint forConstructor(Constructor<T> constructor)
Returns a new injection point for the specified constructor. If the declaring type ofconstructor
is parameterized (such asList<T>
), prefer the overload that includes a type literal.- Parameters:
constructor
- any single constructor present ontype
.- Since:
- 3.0
-
forConstructor
public static <T> InjectionPoint forConstructor(Constructor<T> constructor, TypeLiteral<? extends T> type)
Returns a new injection point for the specified constructor oftype
.- Parameters:
constructor
- any single constructor present ontype
.type
- the concrete type that definesconstructor
.- Since:
- 3.0
-
forConstructorOf
public static InjectionPoint forConstructorOf(TypeLiteral<?> type)
Returns a new injection point for the injectable constructor oftype
.Either a
@Inject
annotated constructor or a non-private no arg constructor is required to be defined by the class corresponding totype
.- Parameters:
type
- a concrete type with exactly one constructor annotated @Inject
, or a no-arguments constructor that is not private.- Throws:
ConfigurationException
- if there is no injectable constructor, more than one injectable constructor, or if parameters of the injectable constructor are malformed, such as a parameter with multiple binding annotations.
-
forConstructorOf
public static InjectionPoint forConstructorOf(TypeLiteral<?> type, boolean atInjectRequired)
Returns a new injection point for the injectable constructor oftype
.If
atInjectRequired
is true, the constructor must be annotated with@Inject
. IfatInjectRequired
is false, either a@Inject
annotated constructor or a non-private no arg constructor is required to be defined by the class corresponding totype
.- Parameters:
type
- a concrete type with exactly one constructor annotated@Inject
, or a no-arguments constructor that is not private.atInjectRequired
- whether the constructor must be annotated withInject
.- Throws:
ConfigurationException
- if there is no injectable constructor, more than one injectable constructor, or if parameters of the injectable constructor are malformed, such as a parameter with multiple binding annotations.
-
forConstructorOf
public static InjectionPoint forConstructorOf(Class<?> type)
Returns a new injection point for the injectable constructor oftype
.- Parameters:
type
- a concrete type with exactly one constructor annotated @Inject
, or a no-arguments constructor that is not private.- Throws:
ConfigurationException
- if there is no injectable constructor, more than one injectable constructor, or if parameters of the injectable constructor are malformed, such as a parameter with multiple binding annotations.
-
forMethod
public static <T> InjectionPoint forMethod(Method method, TypeLiteral<T> type)
Returns a new injection point for the specified method oftype
. This is useful for extensions that need to build dependency graphs from arbitrary methods.- Parameters:
method
- any single method present ontype
.type
- the concrete type that definesmethod
.- Since:
- 4.0
-
forStaticMethodsAndFields
public static Set<InjectionPoint> forStaticMethodsAndFields(TypeLiteral<?> type)
Returns all static method and field injection points ontype
.- Returns:
- a possibly empty set of injection points. The set has a specified iteration order. All fields are returned and then all methods. Within the fields, supertype fields are returned before subtype fields. Similarly, supertype methods are returned before subtype methods.
- Throws:
ConfigurationException
- if there is a malformed injection point ontype
, such as a field with multiple binding annotations. The exception'spartial value
is aSet<InjectionPoint>
of the valid injection points.
-
forStaticMethodsAndFields
public static Set<InjectionPoint> forStaticMethodsAndFields(Class<?> type)
Returns all static method and field injection points ontype
.- Returns:
- a possibly empty set of injection points. The set has a specified iteration order. All fields are returned and then all methods. Within the fields, supertype fields are returned before subtype fields. Similarly, supertype methods are returned before subtype methods.
- Throws:
ConfigurationException
- if there is a malformed injection point ontype
, such as a field with multiple binding annotations. The exception'spartial value
is aSet<InjectionPoint>
of the valid injection points.
-
forInstanceMethodsAndFields
public static Set<InjectionPoint> forInstanceMethodsAndFields(TypeLiteral<?> type)
Returns all instance method and field injection points ontype
.- Returns:
- a possibly empty set of injection points. The set has a specified iteration order. All fields are returned and then all methods. Within the fields, supertype fields are returned before subtype fields. Similarly, supertype methods are returned before subtype methods.
- Throws:
ConfigurationException
- if there is a malformed injection point ontype
, such as a field with multiple binding annotations. The exception'spartial value
is aSet<InjectionPoint>
of the valid injection points.
-
forInstanceMethodsAndFields
public static Set<InjectionPoint> forInstanceMethodsAndFields(Class<?> type)
Returns all instance method and field injection points ontype
.- Returns:
- a possibly empty set of injection points. The set has a specified iteration order. All fields are returned and then all methods. Within the fields, supertype fields are returned before subtype fields. Similarly, supertype methods are returned before subtype methods.
- Throws:
ConfigurationException
- if there is a malformed injection point ontype
, such as a field with multiple binding annotations. The exception'spartial value
is aSet<InjectionPoint>
of the valid injection points.
-
-