public abstract class ProviderMethod<T> extends InternalProviderInstanceBindingImpl.CyclicFactory<T> implements HasDependencies, ProvidesMethodBinding<T>, ProviderWithExtensionVisitor<T>
| Modifier and Type | Class and Description |
|---|---|
private static class |
ProviderMethod.FastClassProviderMethod<T>
A
ProviderMethod implementation that uses FastClass.invoke(java.lang.String, java.lang.Class[], java.lang.Object, java.lang.Object[])
to invoke the provider method. |
private static class |
ProviderMethod.ReflectionProviderMethod<T>
A
ProviderMethod implementation that invokes the method using normal java reflection. |
| Modifier and Type | Field and 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 by
initialize(InjectorImpl, Errors) so it is always available prior to injection. |
private java.lang.Class<? extends java.lang.annotation.Annotation> |
scopeAnnotation |
provisionCallback| Modifier | Constructor and 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) |
| Modifier and Type | Method and Description |
|---|---|
<B,V> V |
acceptExtensionVisitor(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 a
ProviderMethod. |
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() |
getget, getSourceprotected final java.lang.Object instance
protected final java.lang.reflect.Method method
private final java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation
private final com.google.common.collect.ImmutableSet<Dependency<?>> dependencies
private final boolean exposed
private final java.lang.annotation.Annotation annotation
private SingleParameterInjector<?>[] parameterInjectors
initialize(InjectorImpl, Errors) so it is always available prior to injection.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 - the method to invoke. It's return type must be the same type as key.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)
ProviderMethod.
Unless skipFastClassGeneration is set, this will use FastClass to invoke the actual method, since it is significantly faster.
However, this will fail if the method is private or protected, since fastclass
is subject to java access policies.
public Key<T> getKey()
ProvidesMethodBindinggetKey in interface ProvidesMethodBinding<T>public java.lang.reflect.Method getMethod()
ProvidesMethodBindinggetMethod in interface ProvidesMethodBinding<T>public java.lang.Object getInstance()
public java.lang.Object getEnclosingInstance()
ProvidesMethodBindinggetEnclosingInstance in interface ProvidesMethodBinding<T>public java.lang.annotation.Annotation getAnnotation()
ProvidesMethodBinding@Provides methods,
this is an instance of the @Provides annotation. For bindings from ModuleAnnotatedMethodScanner, this is the annotation that caused the scanner to produce the
binding.getAnnotation in interface ProvidesMethodBinding<T>public void configure(Binder binder)
void initialize(InjectorImpl injector, Errors errors) throws ErrorsException
InternalProviderInstanceBindingImpl.FactoryWill be called exactly once, prior to any call to InternalProviderInstanceBindingImpl.Factory.doProvision(com.google.inject.internal.InternalContext, com.google.inject.spi.Dependency<?>).
initialize in class InternalProviderInstanceBindingImpl.Factory<T>ErrorsExceptionprotected T doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException
InternalProviderInstanceBindingImpl.FactorydoProvision in class InternalProviderInstanceBindingImpl.Factory<T>InternalProvisionException - if a value cannot be providedabstract T doProvision(java.lang.Object[] parameters) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionpublic java.util.Set<Dependency<?>> getDependencies()
HasDependenciesInjector will be
included in the returned set.getDependencies in interface HasDependenciespublic <B,V> V acceptExtensionVisitor(BindingTargetVisitor<B,V> visitor, ProviderInstanceBinding<? extends B> binding)
ProviderWithExtensionVisitorDue 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'.
acceptExtensionVisitor in interface ProviderWithExtensionVisitor<T>public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object