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.FastClassProviderMethod,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 ClassesModifier and TypeClassDescriptionprivate static final classAProviderMethodimplementation that uses bytecode generation to invoke the provider method.private static final classAProviderMethodimplementation that invokes the method using normal java reflection. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Annotationprivate final com.google.common.collect.ImmutableSet<Dependency<?>> private final booleanprotected final Objectprotected final Methodprivate SingleParameterInjector<?>[]Set byinitialize(InjectorImpl, Errors)so it is always available prior to injection.private final Class<? extends Annotation> Fields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback -
Constructor Summary
ConstructorsConstructorDescriptionProviderMethod(Key<T> key, Method method, Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation) -
Method Summary
Modifier and TypeMethodDescription<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(package private) static <T> ProviderMethod<T> create(Key<T> key, Method method, Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, boolean skipFastClassGeneration, Annotation annotation) Creates aProviderMethod.protected TdoProvision(InternalContext context, Dependency<?> dependency) Creates an object to be injected.(package private) abstract TdoProvision(Object[] parameters) Extension point for our subclasses to implement the provisioning strategy.booleanReturns the annotation that caused this binding to be created.Set<Dependency<?>> Returns the known dependencies for this type.Returns the instance of the object the method is defined in.getKey()Returns the key of the binding.Returns the method this binding uses.inthashCode()(package private) voidinitialize(InjectorImpl injector, Errors errors) A callback that allows for implementations to fetch dependencies on other bindings.toString()Methods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.CyclicFactory
getMethods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
get, getSource
-
Field Details
-
instance
-
method
-
key
-
scopeAnnotation
-
dependencies
-
exposed
private final boolean exposed -
annotation
-
parameterInjectors
Set byinitialize(InjectorImpl, Errors)so it is always available prior to injection.
-
-
Constructor Details
-
ProviderMethod
ProviderMethod(Key<T> key, Method method, Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation) - Parameters:
method- the method to invoke. Its return type must be the same type askey.
-
-
Method Details
-
create
static <T> ProviderMethod<T> create(Key<T> key, Method method, Object instance, com.google.common.collect.ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, boolean skipFastClassGeneration, Annotation annotation) Creates aProviderMethod.Unless
skipFastClassGenerationis set, this will use bytecode generation to invoke the actual method, since it is significantly faster. However, this may fail if the method isprivateorprotected, since this approach is subject to java access policies. -
getKey
Description copied from interface:ProvidesMethodBindingReturns the key of the binding.- Specified by:
getKeyin interfaceProvidesMethodBinding<T>
-
getMethod
Description copied from interface:ProvidesMethodBindingReturns the method this binding uses.- Specified by:
getMethodin interfaceProvidesMethodBinding<T>
-
getInstance
-
getEnclosingInstance
Description copied from interface:ProvidesMethodBindingReturns the instance of the object the method is defined in.- Specified by:
getEnclosingInstancein interfaceProvidesMethodBinding<T>
-
getAnnotation
Description copied from interface:ProvidesMethodBindingReturns the annotation that caused this binding to be created. For@Providesmethods, this is an instance of the@Providesannotation. For bindings fromModuleAnnotatedMethodScanner, this is the annotation that caused the scanner to produce the binding.- Specified by:
getAnnotationin interfaceProvidesMethodBinding<T>
-
configure
-
initialize
Description copied from class:InternalProviderInstanceBindingImpl.FactoryA 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:
initializein classInternalProviderInstanceBindingImpl.Factory<T>- Throws:
ErrorsException
-
doProvision
protected T doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException Description copied from class:InternalProviderInstanceBindingImpl.FactoryCreates an object to be injected.- Specified by:
doProvisionin classInternalProviderInstanceBindingImpl.Factory<T>- Returns:
- instance to be injected
- Throws:
InternalProvisionException- if a value cannot be provided
-
doProvision
abstract T doProvision(Object[] parameters) throws IllegalAccessException, InvocationTargetException Extension point for our subclasses to implement the provisioning strategy. -
getDependencies
Description copied from interface:HasDependenciesReturns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for theInjectorwill be included in the returned set.- Specified by:
getDependenciesin interfaceHasDependencies- Returns:
- a possibly empty set
-
acceptExtensionVisitor
public <B,V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) Description copied from interface:ProviderWithExtensionVisitorInstructs 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:
acceptExtensionVisitorin interfaceProviderWithExtensionVisitor<T>
-
toString
-
equals
-
hashCode
public int hashCode()
-