Top Description Inners Fields Constructors Methods
com.google.inject.internal

public abstract Class ProviderMethod<T>

extends InternalProviderInstanceBindingImpl.CyclicFactory<T>
implements HasDependencies, ProvidesMethodBinding<T>, ProviderWithExtensionVisitor<T>
Class Inheritance
All Implemented Interfaces
com.google.inject.spi.ProviderWithExtensionVisitor, com.google.inject.Provider, jakarta.inject.Provider, com.google.inject.spi.ProvidesMethodBinding, com.google.inject.spi.HasDependencies
Known Direct Subclasses
com.google.inject.internal.ProviderMethod.FastClassProviderMethod, com.google.inject.internal.ProviderMethod.ReflectionProviderMethod
Imports
com.google.common.base.Objects, com.google.common.collect.ImmutableSet, com.google.inject.Binder, .Exposed, .Key, .PrivateBinder, .Provides, com.google.inject.internal.InternalProviderInstanceBindingImpl.InitializationTiming, com.google.inject.internal.util.StackTraceElements, com.google.inject.spi.BindingTargetVisitor, .Dependency, .HasDependencies, .ProviderInstanceBinding, .ProviderWithExtensionVisitor, .ProvidesMethodBinding, .ProvidesMethodTargetVisitor, java.lang.annotation.Annotation, java.lang.reflect.InvocationTargetException, .Method, .Modifier, java.util.Set, java.util.function.BiFunction

A provider that invokes a method and returns its result.
Author
[email protected] (Jesse Wilson)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ProviderMethod.FastClassProviderMethod<T>

A ProviderMethod implementation that uses bytecode generation to invoke the provider method.

private static class
ProviderMethod.ReflectionProviderMethod<T>

A ProviderMethod implementation that invokes the method using normal java reflection.

Field Summary

Modifier and TypeField and Description
private final Annotation
private final ImmutableSet<Dependency<?>>
private final boolean
protected final Object
private final Key<T>
protected final Method
private SingleParameterInjector<?>[]
parameterInjectors

Set by initialize(InjectorImpl, Errors) so it is always available prior to injection.

private final Class<? extends Annotation>

Constructor Summary

AccessConstructor and Description
pack-priv
ProviderMethod(Key<T> key, Method
the method to invoke. Its return type must be the same type as key.
method
,
Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation)

Method Summary

Modifier and TypeMethod and Description
public <B, V> V
acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding)

Implements com.google.inject.spi.ProviderWithExtensionVisitor.acceptExtensionVisitor.

Instructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method.
public void
configure(Binder binder)

pack-priv static <T> ProviderMethod<T>
create(Key<T> key, Method method, Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, boolean skipFastClassGeneration, Annotation annotation)

Creates a ProviderMethod.

protected T
doProvision(InternalContext context, Dependency<?> dependency)

Implements abstract com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory.doProvision.

Creates an object to be injected.
pack-priv abstract T
doProvision(Object[] parameters)

Extension point for our subclasses to implement the provisioning strategy.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Annotation
getAnnotation()

Implements com.google.inject.spi.ProvidesMethodBinding.getAnnotation.

Returns the annotation that caused this binding to be created.
public Set<Dependency<?>>
getDependencies()

Implements com.google.inject.spi.HasDependencies.getDependencies.

Returns the known dependencies for this type.
public Object
getEnclosingInstance()

Implements com.google.inject.spi.ProvidesMethodBinding.getEnclosingInstance.

Returns the instance of the object the method is defined in.
public Object
public Key<T>
getKey()

Implements com.google.inject.spi.ProvidesMethodBinding.getKey.

Returns the key of the binding.
public Method
getMethod()

Implements com.google.inject.spi.ProvidesMethodBinding.getMethod.

Returns the method this binding uses.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
pack-priv void
initialize(InjectorImpl injector, Errors errors)

Implements abstract com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory.initialize.

A callback that allows for implementations to fetch dependencies on other bindings.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.inject.internal.InternalProviderInstanceBindingImpl.CyclicFactory:
get

Field Detail

annotationback to summary
private final Annotation annotation
dependenciesback to summary
private final ImmutableSet<Dependency<?>> dependencies
exposedback to summary
private final boolean exposed
instanceback to summary
protected final Object instance
keyback to summary
private final Key<T> key
methodback to summary
protected final Method method
parameterInjectorsback to summary
private SingleParameterInjector<?>[] parameterInjectors

Set by initialize(InjectorImpl, Errors) so it is always available prior to injection.

scopeAnnotationback to summary
private final Class<? extends Annotation> scopeAnnotation

Constructor Detail

ProviderMethodback to summary
pack-priv ProviderMethod(Key<T> key, Method method, Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation)
Parameters
method:Method

the method to invoke. Its return type must be the same type as key.

Method Detail

acceptExtensionVisitorback to summary
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding)

Implements com.google.inject.spi.ProviderWithExtensionVisitor.acceptExtensionVisitor.

Doc from com.google.inject.spi.ProviderWithExtensionVisitor.acceptExtensionVisitor.

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'.

Annotations
@Override
@SuppressWarnings:unchecked
configureback to summary
public void configure(Binder binder)
createback to summary
pack-priv static <T> ProviderMethod<T> create(Key<T> key, Method method, Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, boolean skipFastClassGeneration, Annotation annotation)

Creates a ProviderMethod.

Unless skipFastClassGeneration is set, this will use bytecode generation to invoke the actual method, since it is significantly faster. However, this may fail if the method is private or protected, since this approach is subject to java access policies.

doProvisionback to summary
protected T doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException

Implements abstract com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory.doProvision.

Doc from com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory.doProvision.

Creates an object to be injected.

Returns:T

instance to be injected

Annotations
@Override
Exceptions
InternalProvisionException:
if a value cannot be provided
doProvisionback to summary
pack-priv abstract T doProvision(Object[] parameters) throws IllegalAccessException, InvocationTargetException

Extension point for our subclasses to implement the provisioning strategy.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAnnotationback to summary
public Annotation getAnnotation()

Implements com.google.inject.spi.ProvidesMethodBinding.getAnnotation.

Doc from com.google.inject.spi.ProvidesMethodBinding.getAnnotation.

Returns the annotation that caused this binding to be created. For @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.

Annotations
@Override
getDependenciesback to summary
public Set<Dependency<?>> getDependencies()

Implements com.google.inject.spi.HasDependencies.getDependencies.

Doc from com.google.inject.spi.HasDependencies.getDependencies.

Returns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for the Injector will be included in the returned set.

Returns:Set<Dependency<?>>

a possibly empty set

Annotations
@Override
getEnclosingInstanceback to summary
public Object getEnclosingInstance()

Implements com.google.inject.spi.ProvidesMethodBinding.getEnclosingInstance.

Doc from com.google.inject.spi.ProvidesMethodBinding.getEnclosingInstance.

Returns the instance of the object the method is defined in.

Annotations
@Override
getInstanceback to summary
public Object getInstance()
getKeyback to summary
public Key<T> getKey()

Implements com.google.inject.spi.ProvidesMethodBinding.getKey.

Doc from com.google.inject.spi.ProvidesMethodBinding.getKey.

Returns the key of the binding.

Annotations
@Override
getMethodback to summary
public Method getMethod()

Implements com.google.inject.spi.ProvidesMethodBinding.getMethod.

Doc from com.google.inject.spi.ProvidesMethodBinding.getMethod.

Returns the method this binding uses.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
initializeback to summary
pack-priv void initialize(InjectorImpl injector, Errors errors) throws ErrorsException

Implements abstract com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory.initialize.

Doc from com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory.initialize.

A callback that allows for implementations to fetch dependencies on other bindings.

Will be called exactly once, prior to any call to doProvision.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.inject.internal back to summary

private final Class ProviderMethod.FastClassProviderMethod<T>

extends ProviderMethod<T>
Class Inheritance

A ProviderMethod implementation that uses bytecode generation to invoke the provider method.

Field Summary

Modifier and TypeField and Description
pack-priv final BiFunction<Object, Object[], Object>
Inherited from com.google.inject.internal.ProviderMethod:
instancemethod

Constructor Summary

AccessConstructor and Description
pack-priv
FastClassProviderMethod(Key<T> key, Method method, Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation, BiFunction<Object, Object[], Object> fastMethod)

Method Summary

Modifier and TypeMethod and Description
public T
doProvision(Object[] parameters)

Implements abstract com.google.inject.internal.ProviderMethod.doProvision.

Extension point for our subclasses to implement the provisioning strategy.
Inherited from com.google.inject.internal.ProviderMethod:
acceptExtensionVisitorconfigurecreatedoProvisionequalsgetAnnotationgetDependenciesgetEnclosingInstancegetInstancegetKeygetMethodhashCodeinitializetoString

Field Detail

fastMethodback to summary
pack-priv final BiFunction<Object, Object[], Object> fastMethod

Constructor Detail

FastClassProviderMethodback to summary
pack-priv FastClassProviderMethod(Key<T> key, Method method, Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation, BiFunction<Object, Object[], Object> fastMethod)

Method Detail

doProvisionback to summary
public T doProvision(Object[] parameters) throws InvocationTargetException

Implements abstract com.google.inject.internal.ProviderMethod.doProvision.

Doc from com.google.inject.internal.ProviderMethod.doProvision.

Extension point for our subclasses to implement the provisioning strategy.

Annotations
@SuppressWarnings:unchecked
@Override
com.google.inject.internal back to summary

private final Class ProviderMethod.ReflectionProviderMethod<T>

extends ProviderMethod<T>
Class Inheritance

A ProviderMethod implementation that invokes the method using normal java reflection.

Field Summary

Inherited from com.google.inject.internal.ProviderMethod:
instancemethod

Constructor Summary

AccessConstructor and Description
pack-priv
ReflectionProviderMethod(Key<T> key, Method method, Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation)

Method Summary

Modifier and TypeMethod and Description
pack-priv T
doProvision(Object[] parameters)

Implements abstract com.google.inject.internal.ProviderMethod.doProvision.

Extension point for our subclasses to implement the provisioning strategy.
Inherited from com.google.inject.internal.ProviderMethod:
acceptExtensionVisitorconfigurecreatedoProvisionequalsgetAnnotationgetDependenciesgetEnclosingInstancegetInstancegetKeygetMethodhashCodeinitializetoString

Constructor Detail

ReflectionProviderMethodback to summary
pack-priv ReflectionProviderMethod(Key<T> key, Method method, Object instance, ImmutableSet<Dependency<?>> dependencies, Class<? extends Annotation> scopeAnnotation, Annotation annotation)

Method Detail

doProvisionback to summary
pack-priv T doProvision(Object[] parameters) throws IllegalAccessException, InvocationTargetException

Implements abstract com.google.inject.internal.ProviderMethod.doProvision.

Doc from com.google.inject.internal.ProviderMethod.doProvision.

Extension point for our subclasses to implement the provisioning strategy.

Annotations
@SuppressWarnings:unchecked
@Override