Class InternalInjectorCreator.ToolStageInjector
- java.lang.Object
-
- com.google.inject.internal.InternalInjectorCreator.ToolStageInjector
-
- All Implemented Interfaces:
Injector
- Enclosing class:
- InternalInjectorCreator
static class InternalInjectorCreator.ToolStageInjector extends java.lang.Object implements Injector
Injector
exposed to users inStage.TOOL
.
-
-
Field Summary
Fields Modifier and Type Field Description private Injector
delegateInjector
-
Constructor Summary
Constructors Constructor Description ToolStageInjector(Injector delegateInjector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Injector
createChildInjector(Module... modules)
Returns a new injector that inherits all state from this injector.Injector
createChildInjector(java.lang.Iterable<? extends Module> modules)
Returns a new injector that inherits all state from this injector.<T> java.util.List<Binding<T>>
findBindingsByType(TypeLiteral<T> type)
Returns all explicit bindings fortype
.java.util.Map<Key<?>,Binding<?>>
getAllBindings()
Returns a snapshot of this injector's bindings, both explicit and just-in-time.<T> Binding<T>
getBinding(Key<T> key)
Returns the binding for the given injection key.<T> Binding<T>
getBinding(java.lang.Class<T> type)
Returns the binding for the given type.java.util.Map<Key<?>,Binding<?>>
getBindings()
Returns this injector's explicit bindings.<T> Binding<T>
getExistingBinding(Key<T> key)
Returns the binding if it already exists, or null if does not exist.<T> T
getInstance(Key<T> key)
Returns the appropriate instance for the given injection key; equivalent togetProvider(key).get()
.<T> T
getInstance(java.lang.Class<T> type)
Returns the appropriate instance for the given injection type; equivalent togetProvider(type).get()
.<T> MembersInjector<T>
getMembersInjector(TypeLiteral<T> typeLiteral)
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
.<T> MembersInjector<T>
getMembersInjector(java.lang.Class<T> type)
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
.Injector
getParent()
Returns this injector's parent, ornull
if this is a top-level injector.<T> Provider<T>
getProvider(Key<T> key)
Returns the provider used to obtain instances for the given injection key.<T> Provider<T>
getProvider(java.lang.Class<T> type)
Returns the provider used to obtain instances for the given type.java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,Scope>
getScopeBindings()
Returns a map containing all scopes in the injector.java.util.Set<TypeConverterBinding>
getTypeConverterBindings()
Returns a set containing all type converter bindings in the injector.void
injectMembers(java.lang.Object o)
Injects dependencies into the fields and methods ofinstance
.
-
-
-
Field Detail
-
delegateInjector
private final Injector delegateInjector
-
-
Constructor Detail
-
ToolStageInjector
ToolStageInjector(Injector delegateInjector)
-
-
Method Detail
-
injectMembers
public void injectMembers(java.lang.Object o)
Description copied from interface:Injector
Injects dependencies into the fields and methods ofinstance
. Ignores the presence or absence of an injectable constructor.Whenever Guice creates an instance, it performs this injection automatically (after first performing constructor injection), so if you're able to let Guice create all your objects for you, you'll never need to use this method.
- Specified by:
injectMembers
in interfaceInjector
- Parameters:
o
- to inject members on- See Also:
for a preferred alternative that supports checks before run time
-
getBindings
public java.util.Map<Key<?>,Binding<?>> getBindings()
Description copied from interface:Injector
Returns this injector's explicit bindings.The returned map does not include bindings inherited from a
parent injector
, should one exist. The returned map is guaranteed to iterate (for example, with itsMap.entrySet()
iterator) in the order of insertion. In other words, the order in which bindings appear in user Modules.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getBindings
in interfaceInjector
-
getAllBindings
public java.util.Map<Key<?>,Binding<?>> getAllBindings()
Description copied from interface:Injector
Returns a snapshot of this injector's bindings, both explicit and just-in-time. The returned map is immutable; it contains only the bindings that were present whengetAllBindings()
was invoked. Just-in-time bindings are only present if they have been requested at least once. Subsequent calls may return a map with additional just-in-time bindings.The returned map does not include bindings inherited from a
parent injector
, should one exist.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getAllBindings
in interfaceInjector
-
getBinding
public <T> Binding<T> getBinding(Key<T> key)
Description copied from interface:Injector
Returns the binding for the given injection key. This will be an explicit bindings if the key was bound explicitly by a module, or an implicit binding otherwise. The implicit binding will be created if necessary.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getBinding
in interfaceInjector
-
getBinding
public <T> Binding<T> getBinding(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the binding for the given type. This will be an explicit bindings if the injection key was bound explicitly by a module, or an implicit binding otherwise. The implicit binding will be created if necessary.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getBinding
in interfaceInjector
-
getExistingBinding
public <T> Binding<T> getExistingBinding(Key<T> key)
Description copied from interface:Injector
Returns the binding if it already exists, or null if does not exist. UnlikeInjector.getBinding(Key)
, this does not attempt to create just-in-time bindings for keys that aren't bound.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getExistingBinding
in interfaceInjector
-
findBindingsByType
public <T> java.util.List<Binding<T>> findBindingsByType(TypeLiteral<T> type)
Description copied from interface:Injector
Returns all explicit bindings fortype
.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
findBindingsByType
in interfaceInjector
-
getParent
public Injector getParent()
Description copied from interface:Injector
Returns this injector's parent, ornull
if this is a top-level injector.
-
createChildInjector
public Injector createChildInjector(java.lang.Iterable<? extends Module> modules)
Description copied from interface:Injector
Returns a new injector that inherits all state from this injector. All bindings, scopes, interceptors and type converters are inherited -- they are visible to the child injector. Elements of the child injector are not visible to its parent.Just-in-time bindings created for child injectors will be created in an ancestor injector whenever possible. This allows for scoped instances to be shared between injectors. Use explicit bindings to prevent bindings from being shared with the parent injector. Optional injections in just-in-time bindings (created in the parent injector) may be silently ignored if the optional dependencies are from the child injector.
No key may be bound by both an injector and one of its ancestors. This includes just-in-time bindings. The lone exception is the key for
Injector.class
, which is bound by each injector to itself.- Specified by:
createChildInjector
in interfaceInjector
-
createChildInjector
public Injector createChildInjector(Module... modules)
Description copied from interface:Injector
Returns a new injector that inherits all state from this injector. All bindings, scopes, interceptors and type converters are inherited -- they are visible to the child injector. Elements of the child injector are not visible to its parent.Just-in-time bindings created for child injectors will be created in an ancestor injector whenever possible. This allows for scoped instances to be shared between injectors. Use explicit bindings to prevent bindings from being shared with the parent injector.
No key may be bound by both an injector and one of its ancestors. This includes just-in-time bindings. The lone exception is the key for
Injector.class
, which is bound by each injector to itself.- Specified by:
createChildInjector
in interfaceInjector
-
getScopeBindings
public java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,Scope> getScopeBindings()
Description copied from interface:Injector
Returns a map containing all scopes in the injector. The maps keys are scoping annotations likeSingleton.class
, and the values are scope instances, such asScopes.SINGLETON
. The returned map is immutable.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getScopeBindings
in interfaceInjector
-
getTypeConverterBindings
public java.util.Set<TypeConverterBinding> getTypeConverterBindings()
Description copied from interface:Injector
Returns a set containing all type converter bindings in the injector. The returned set is immutable.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getTypeConverterBindings
in interfaceInjector
-
getProvider
public <T> Provider<T> getProvider(Key<T> key)
Description copied from interface:Injector
Returns the provider used to obtain instances for the given injection key. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getProvider
in interfaceInjector
- See Also:
for an alternative that offers up front error detection
-
getProvider
public <T> Provider<T> getProvider(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the provider used to obtain instances for the given type. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getProvider
in interfaceInjector
- See Also:
for an alternative that offers up front error detection
-
getMembersInjector
public <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral)
Description copied from interface:Injector
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
.- Specified by:
getMembersInjector
in interfaceInjector
- Parameters:
typeLiteral
- type to get members injector for- See Also:
for an alternative that offers up front error detection
-
getMembersInjector
public <T> MembersInjector<T> getMembersInjector(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
. When feasible, useBinder.getMembersInjector(TypeLiteral)
instead to get increased up front error detection.- Specified by:
getMembersInjector
in interfaceInjector
- Parameters:
type
- type to get members injector for- See Also:
for an alternative that offers up front error detection
-
getInstance
public <T> T getInstance(Key<T> key)
Description copied from interface:Injector
Returns the appropriate instance for the given injection key; equivalent togetProvider(key).get()
. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getInstance
in interfaceInjector
-
getInstance
public <T> T getInstance(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the appropriate instance for the given injection type; equivalent togetProvider(type).get()
. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getInstance
in interfaceInjector
-
-