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

pack-priv final Class InjectorImpl

extends Object
implements Injector, Lookups
Class Inheritance
All Implemented Interfaces
com.google.inject.internal.Lookups, com.google.inject.Injector
Static Imports
com.google.common.base.Preconditions.checkNotNull, com.google.inject.internal.Annotations.findScopeAnnotation

Default Injector implementation.
Author
[email protected] (Bob Lee)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class
InjectorImpl.InjectorOptions

Options that control how the injector behaves.

pack-priv static enum
InjectorImpl.JitLimitation

some limitations on what just in time bindings are allowed.

pack-priv static interface
InjectorImpl.MethodInvoker

Invokes a method.

private static class
InjectorImpl.SyntheticProviderBindingImpl<T>

A framework-created JIT Provider<T> binding.

Field Summary

Modifier and TypeField and Description
private final InjectorBindingData
pack-priv final ConstructorInjectorStore
constructors

Cached constructor injectors for each type

private final InjectorJitBindingData
private final ThreadLocal<Object[]>
localContext

Holds Object[] as a mutable wrapper, rather than InternalContext, since array operations are faster than ThreadLocal.set() / .get() operations.

pack-priv Lookups
pack-priv MembersInjectorStore
membersInjectorStore

Cached field and method injectors for each type.

pack-priv final InjectorImpl.InjectorOptions
pack-priv final InjectorImpl
pack-priv ProvisionListenerCallbackStore
provisionListenerStore

Cached provision listener callbacks for each key.

public static final TypeLiteral<String>
pack-priv final Set<TypeLiteral<?>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private boolean
cleanup(BindingImpl<?> binding, Set<Key<?>> encountered)

Iterates through the binding's dependencies to clean up any stray bindings that were leftover from a failed JIT binding.

private <T> BindingImpl<T>

Returns:

the binding if it could be resolved, or null if the binding doesn't exist
convertConstantStringBinding
(Key<T> key, Errors errors)

Converts a constant string binding to the required type.

public Injector
createChildInjector(Iterable<? extends Module> modules)

Implements com.google.inject.Injector.createChildInjector.

Returns a new injector that inherits all state from this injector.
public Injector
createChildInjector(Module... modules)

Implements com.google.inject.Injector.createChildInjector.

Returns a new injector that inherits all state from this injector.
private <T> BindingImpl<T>
createImplementedByBinding(Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors, Consumer<CreationListener> creationListenerCallback)

Creates a binding for a type annotated with @ImplementedBy.

private <T> BindingImpl<T>
createJustInTimeBinding(Key<T> key, Errors errors, boolean jitDisabled, InjectorImpl.JitLimitation jitType)

Returns a new just-in-time binding created by resolving key.

private <T> BindingImpl<T>
createJustInTimeBindingRecursive(Key<T> key, Errors errors, boolean jitDisabled, InjectorImpl.JitLimitation jitType)

Attempts to create a just-in-time binding for key in the root injector, falling back to other ancestor injectors until this injector is tried.

private <T> BindingImpl<MembersInjector<T>>
pack-priv <T> SingleParameterInjector<T>
createParameterInjector(final Dependency<T> dependency, final Errors errors)

pack-priv <T> BindingImpl<T>
createProvidedByBinding(Key<T> key, Scoping scoping, ProvidedBy providedBy, Errors errors)

Creates a binding for a type annotated with @ProvidedBy.

private <T> BindingImpl<Provider<T>>
createSyntheticProviderBinding(Key<Provider<T>> key, Errors errors)

Creates a synthetic binding to Provider<T>, i.e. a framework-created JIT binding to the provider from Binding<T>.

private <T> BindingImpl<TypeLiteral<T>>
createTypeLiteralBinding(Key<TypeLiteral<T>> key, Errors errors)

Converts a binding for a Key<TypeLiteral<T>> to the value TypeLiteral<T>.

pack-priv <T> BindingImpl<T>
createUninitializedBinding(Key<T> key, Scoping scoping, Object source, Errors errors, boolean jitBinding, Consumer<CreationListener> creationListenerCallback)

Creates a binding for an injectable type with the given scope.

pack-priv InternalContext
enterContext()

Looks up thread local context and enters it or creates a new context if necessary.

public <T> List<Binding<T>>
findBindingsByType(TypeLiteral<T> type)

Implements com.google.inject.Injector.findBindingsByType.

Returns all explicit bindings for type.
public Map<Key<?>, Binding<?>>
getAllBindings()

Implements com.google.inject.Injector.getAllBindings.

Returns a snapshot of this injector's bindings, both explicit and just-in-time.
public Map<TypeLiteral<?>, List<InjectionPoint>>
getAllMembersInjectorInjectionPoints()

Implements com.google.inject.Injector.getAllMembersInjectorInjectionPoints.

Returns the injection points created for calls to getMembersInjector (either directly or indirectly, e.g. through injectMembers.
public <T> BindingImpl<T>
getBinding(Key<T> key)

Implements com.google.inject.Injector.getBinding.

Returns the binding for key
public <T> Binding<T>
getBinding(Class<T> type)

Implements com.google.inject.Injector.getBinding.

Returns the binding for the given type.
pack-priv InjectorBindingData
pack-priv <T> BindingImpl<T>
getBindingOrThrow(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType)

Gets a binding implementation.

public Map<Key<?>, Binding<?>>
getBindings()

Implements com.google.inject.Injector.getBindings.

Returns this injector's explicit bindings.
public List<Element>
getElements()

Implements com.google.inject.Injector.getElements.

Returns the elements that make up this injector.
public <T> BindingImpl<T>
getExistingBinding(Key<T> key)

Implements com.google.inject.Injector.getExistingBinding.

Returns the binding if it already exists, or null if does not exist.
public <T> T
getInstance(Key<T> key)

Implements com.google.inject.Injector.getInstance.

Returns the appropriate instance for the given injection key; equivalent to getProvider(key).get().
public <T> T
getInstance(Class<T> type)

Implements com.google.inject.Injector.getInstance.

Returns the appropriate instance for the given injection type; equivalent to getProvider(type).get().
private Set<Dependency<?>>
getInternalDependencies(BindingImpl<?> binding)

Safely gets the dependencies of possibly not initialized bindings.

pack-priv <T> InternalFactory<? extends T>
pack-priv InjectorJitBindingData
private <T> BindingImpl<T>
getJustInTimeBinding(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType)

Returns a just-in-time binding for key, creating it if necessary.

pack-priv InternalContext
getLocalContext()

Only to be called by the SingletonScope provider.

public <T> MembersInjector<T>
getMembersInjector(TypeLiteral<T>
type to get members injector for
typeLiteral
)

Implements com.google.inject.Injector.getMembersInjector, com.google.inject.internal.Lookups.getMembersInjector.

Returns the members injector used to inject dependencies into methods and fields on instances of the given type T.
public <T> MembersInjector<T>
getMembersInjector(Class<T>
type to get members injector for
type
)

Implements com.google.inject.Injector.getMembersInjector.

Returns the members injector used to inject dependencies into methods and fields on instances of the given type T.
pack-priv SingleParameterInjector<?>[]
getParametersInjectors(List<Dependency<?>> parameters, Errors errors)

Returns parameter injectors, or null if there are no parameters.

public Injector
getParent()

Implements com.google.inject.Injector.getParent.

Returns this injector's parent, or null if this is a top-level injector.
private static <T> Key<T>
getProvidedKey(Key<Provider<T>> key, Errors errors)

public <T> Provider<T>
getProvider(Class<T> type)

Implements com.google.inject.Injector.getProvider.

Returns the provider used to obtain instances for the given type.
public <T> Provider<T>
getProvider(final Key<T> key)

Implements com.google.inject.Injector.getProvider, com.google.inject.internal.Lookups.getProvider.

Returns the provider used to obtain instances for the given injection key.
pack-priv <T> Provider<T>
getProviderOrThrow(final Dependency<T> dependency, Errors errors)

public Map<Class<? extends Annotation>, Scope>
getScopeBindings()

Implements com.google.inject.Injector.getScopeBindings.

Returns a map containing all scopes in the injector.
public Set<TypeConverterBinding>
getTypeConverterBindings()

Implements com.google.inject.Injector.getTypeConverterBindings.

Returns a set containing all type converter bindings in the injector.
pack-priv <T> void
initializeBinding(BindingImpl<T> binding, Errors errors)

pack-priv <T> void
public void
injectMembers(Object
to inject members on
instance
)

Implements com.google.inject.Injector.injectMembers.

Injects dependencies into the fields and methods of instance.
private static boolean
isMembersInjector(Key<?> key)

Returns true if the key type is MembersInjector (but not a subclass of MembersInjector).

private static boolean
isProvider(Key<?> key)

Returns true if the key type is Provider (but not a subclass of Provider).

private static boolean
private void
removeFailedJitBinding(Binding<?> binding, InjectionPoint ip)

Cleans up any state that may have been cached when constructing the JIT binding.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait