public abstract class ProviderMethod<T> extends java.lang.Object implements ProviderWithExtensionVisitor<T>, HasDependencies, ProvidesMethodBinding<T>
| Modifier and Type | Class and Description |
|---|---|
private static class |
ProviderMethod.Factory<T> |
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.ProviderMethodProviderInstanceBindingImpl<T> |
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 java.util.List<Provider<?>> |
parameterProviders |
private java.lang.Class<? extends java.lang.annotation.Annotation> |
scopeAnnotation |
| 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.util.List<Provider<?>> parameterProviders,
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.util.List<Provider<?>> parameterProviders,
java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation,
boolean skipFastClassGeneration,
java.lang.annotation.Annotation annotation)
Creates a
ProviderMethod. |
(package private) static <T> BindingImpl<T> |
createBinding(InjectorImpl injector,
Key<T> key,
ProviderMethod<T> providerMethod,
java.lang.Object source,
Scoping scoping) |
(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) |
T |
get()
Provides an instance of
T. |
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() |
java.lang.String |
toString() |
protected 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 java.util.List<Provider<?>> parameterProviders
private final boolean exposed
private final java.lang.annotation.Annotation annotation
private ProviderMethod(Key<T> key, java.lang.reflect.Method method, java.lang.Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, java.util.List<Provider<?>> parameterProviders, 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.util.List<Provider<?>> parameterProviders, 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)
public T get()
ProviderT. Must never return null.get in interface javax.inject.Provider<T>abstract 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.Objectstatic <T> BindingImpl<T> createBinding(InjectorImpl injector, Key<T> key, ProviderMethod<T> providerMethod, java.lang.Object source, Scoping scoping)