Package com.google.inject.internal
Class ProviderMethod<T>
- java.lang.Object
-
- com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory<T>
-
- com.google.inject.internal.InternalProviderInstanceBindingImpl.CyclicFactory<T>
-
- com.google.inject.internal.ProviderMethod<T>
-
- All Implemented Interfaces:
InternalFactory<T>
,Provider<T>
,HasDependencies
,ProviderWithExtensionVisitor<T>
,ProvidesMethodBinding<T>
,javax.inject.Provider<T>
- Direct Known Subclasses:
ProviderMethod.ReflectionProviderMethod
public abstract class ProviderMethod<T> extends InternalProviderInstanceBindingImpl.CyclicFactory<T> implements HasDependencies, ProvidesMethodBinding<T>, ProviderWithExtensionVisitor<T>
A provider that invokes a method and returns its result.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ProviderMethod.ReflectionProviderMethod<T>
AProviderMethod
implementation that invokes the method using normal java reflection.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.annotation.Annotation
annotation
private com.google.common.collect.ImmutableSet<Dependency<?>>
dependencies
private boolean
exposed
protected java.lang.Object
instance
private Key<T>
key
protected java.lang.reflect.Method
method
private SingleParameterInjector<?>[]
parameterInjectors
Set byinitialize(InjectorImpl, Errors)
so it is always available prior to injection.private java.lang.Class<? extends java.lang.annotation.Annotation>
scopeAnnotation
-
Fields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ProviderMethod(Key<T> key, java.lang.reflect.Method method, java.lang.Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, java.lang.annotation.Annotation annotation)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <B,V>
VacceptExtensionVisitor(BindingTargetVisitor<B,V> visitor, ProviderInstanceBinding<? extends B> binding)
Instructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method.void
configure(Binder binder)
(package private) static <T> ProviderMethod<T>
create(Key<T> key, java.lang.reflect.Method method, java.lang.Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, boolean skipFastClassGeneration, java.lang.annotation.Annotation annotation)
Creates aProviderMethod
.protected T
doProvision(InternalContext context, Dependency<?> dependency)
Creates an object to be injected.(package private) abstract T
doProvision(java.lang.Object[] parameters)
Extension point for our subclasses to implement the provisioning strategy.boolean
equals(java.lang.Object obj)
java.lang.annotation.Annotation
getAnnotation()
Returns the annotation that caused this binding to be created.java.util.Set<Dependency<?>>
getDependencies()
Returns the known dependencies for this type.java.lang.Object
getEnclosingInstance()
Returns the instance of the object the method is defined in.java.lang.Object
getInstance()
Key<T>
getKey()
Returns the key of the binding.java.lang.reflect.Method
getMethod()
Returns the method this binding uses.int
hashCode()
(package private) void
initialize(InjectorImpl injector, Errors errors)
A callback that allows for implementations to fetch dependencies on other bindings.java.lang.String
toString()
-
Methods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.CyclicFactory
get
-
Methods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
get, getSource
-
-
-
-
Field Detail
-
instance
protected final java.lang.Object instance
-
method
protected final java.lang.reflect.Method method
-
scopeAnnotation
private final java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation
-
dependencies
private final com.google.common.collect.ImmutableSet<Dependency<?>> dependencies
-
exposed
private final boolean exposed
-
annotation
private final java.lang.annotation.Annotation annotation
-
parameterInjectors
private SingleParameterInjector<?>[] parameterInjectors
Set byinitialize(InjectorImpl, Errors)
so it is always available prior to injection.
-
-
Constructor Detail
-
ProviderMethod
private ProviderMethod(Key<T> key, java.lang.reflect.Method method, java.lang.Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, java.lang.annotation.Annotation annotation)
- Parameters:
method
- the method to invoke. It's return type must be the same type askey
.
-
-
Method Detail
-
create
static <T> ProviderMethod<T> create(Key<T> key, java.lang.reflect.Method method, java.lang.Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, boolean skipFastClassGeneration, java.lang.annotation.Annotation annotation)
Creates aProviderMethod
.Unless
skipFastClassGeneration
is set, this will usenet.sf.cglib.reflect.FastClass
to invoke the actual method, since it is significantly faster. However, this will fail if the method isprivate
orprotected
, since fastclass is subject to java access policies.
-
getKey
public Key<T> getKey()
Description copied from interface:ProvidesMethodBinding
Returns the key of the binding.- Specified by:
getKey
in interfaceProvidesMethodBinding<T>
-
getMethod
public java.lang.reflect.Method getMethod()
Description copied from interface:ProvidesMethodBinding
Returns the method this binding uses.- Specified by:
getMethod
in interfaceProvidesMethodBinding<T>
-
getInstance
public java.lang.Object getInstance()
-
getEnclosingInstance
public java.lang.Object getEnclosingInstance()
Description copied from interface:ProvidesMethodBinding
Returns the instance of the object the method is defined in.- Specified by:
getEnclosingInstance
in interfaceProvidesMethodBinding<T>
-
getAnnotation
public java.lang.annotation.Annotation getAnnotation()
Description copied from interface:ProvidesMethodBinding
Returns the annotation that caused this binding to be created. For@Provides
methods, this is an instance of the@Provides
annotation. For bindings fromModuleAnnotatedMethodScanner
, this is the annotation that caused the scanner to produce the binding.- Specified by:
getAnnotation
in interfaceProvidesMethodBinding<T>
-
configure
public void configure(Binder binder)
-
initialize
void initialize(InjectorImpl injector, Errors errors) throws ErrorsException
Description copied from class:InternalProviderInstanceBindingImpl.Factory
A callback that allows for implementations to fetch dependencies on other bindings.Will be called exactly once, prior to any call to
InternalProviderInstanceBindingImpl.Factory.doProvision(com.google.inject.internal.InternalContext, com.google.inject.spi.Dependency<?>)
.- Specified by:
initialize
in classInternalProviderInstanceBindingImpl.Factory<T>
- Throws:
ErrorsException
-
doProvision
protected T doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException
Description copied from class:InternalProviderInstanceBindingImpl.Factory
Creates an object to be injected.- Specified by:
doProvision
in classInternalProviderInstanceBindingImpl.Factory<T>
- Returns:
- instance to be injected
- Throws:
InternalProvisionException
- if a value cannot be provided
-
doProvision
abstract T doProvision(java.lang.Object[] parameters) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Extension point for our subclasses to implement the provisioning strategy.- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
getDependencies
public java.util.Set<Dependency<?>> getDependencies()
Description copied from interface:HasDependencies
Returns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for theInjector
will be included in the returned set.- Specified by:
getDependencies
in interfaceHasDependencies
- Returns:
- a possibly empty set
-
acceptExtensionVisitor
public <B,V> V acceptExtensionVisitor(BindingTargetVisitor<B,V> visitor, ProviderInstanceBinding<? extends B> binding)
Description copied from interface:ProviderWithExtensionVisitor
Instructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method. If the visitor is not an instance of the custom extension visitor, this method MUST call visitor.visit(binding).Due to issues with generics, the type parameters of this method do not relate to the type of the provider. In practice, the 'B' type will always be a supertype of 'T'.
- Specified by:
acceptExtensionVisitor
in interfaceProviderWithExtensionVisitor<T>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-