Package com.google.inject.internal
Class RealOptionalBinder.RealOptionalKeyProvider<T>
java.lang.Object
com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory<P>
com.google.inject.internal.RealOptionalBinder.RealOptionalBinderProviderWithDependencies<T,com.google.common.base.Optional<T>>
com.google.inject.internal.RealOptionalBinder.RealOptionalKeyProvider<T>
- All Implemented Interfaces:
InternalFactory<com.google.common.base.Optional<T>>
,OptionalBinderBinding<com.google.common.base.Optional<T>>
,Provider<com.google.common.base.Optional<T>>
,HasDependencies
,ProviderWithExtensionVisitor<com.google.common.base.Optional<T>>
,javax.inject.Provider<com.google.common.base.Optional<T>>
- Enclosing class:
- RealOptionalBinder<T>
private static final class RealOptionalBinder.RealOptionalKeyProvider<T>
extends RealOptionalBinder.RealOptionalBinderProviderWithDependencies<T,com.google.common.base.Optional<T>>
implements ProviderWithExtensionVisitor<com.google.common.base.Optional<T>>, OptionalBinderBinding<com.google.common.base.Optional<T>>
Provides the binding for Optional.
-
Field Summary
FieldsFields inherited from class com.google.inject.internal.RealOptionalBinder.RealOptionalBinderProviderWithDependencies
bindingSelection
Fields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback
-
Constructor Summary
ConstructorsConstructorDescriptionRealOptionalKeyProvider
(RealOptionalBinder.BindingSelection<T> bindingSelection, Key<com.google.common.base.Optional<T>> optionalKey) -
Method Summary
Modifier and TypeMethodDescription<B,
R> R acceptExtensionVisitor
(BindingTargetVisitor<B, R> 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.boolean
containsElement
(Element element) Returns true if this OptionalBinder contains the given Element in order to build the optional binding or uses the given Element in order to support building and injecting its data.(package private) void
Initialize the factory.protected com.google.common.base.Optional<T>
doProvision
(InternalContext context, Dependency<?> currentDependency) Creates an object to be injected.Binding<?>
Returns the actual binding (set byOptionalBinder.setBinding()
) or null if not set.Returns the keys of other bindings that represent this OptionalBinder.Binding<?>
Returns the default binding (set byOptionalBinder.setDefault()
) if one exists or null if no default binding is set.Set<Dependency<?>>
Returns the known dependencies for this type.getKey()
Returns theKey
for this binding.Methods inherited from class com.google.inject.internal.RealOptionalBinder.RealOptionalBinderProviderWithDependencies
equals, hashCode, initialize
Methods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
get, get, getSource
-
Field Details
-
optionalKey
-
targetDependency
-
delegate
-
-
Constructor Details
-
RealOptionalKeyProvider
RealOptionalKeyProvider(RealOptionalBinder.BindingSelection<T> bindingSelection, Key<com.google.common.base.Optional<T>> optionalKey)
-
-
Method Details
-
doInitialize
void doInitialize()Description copied from class:RealOptionalBinder.RealOptionalBinderProviderWithDependencies
Initialize the factory. BindingSelection is guaranteed to be initialized at this point and this will be called prior to any provisioning.- Specified by:
doInitialize
in classRealOptionalBinder.RealOptionalBinderProviderWithDependencies<T,
com.google.common.base.Optional<T>>
-
doProvision
protected com.google.common.base.Optional<T> doProvision(InternalContext context, Dependency<?> currentDependency) throws InternalProvisionException Description copied from class:InternalProviderInstanceBindingImpl.Factory
Creates an object to be injected.- Specified by:
doProvision
in classInternalProviderInstanceBindingImpl.Factory<com.google.common.base.Optional<T>>
- Returns:
- instance to be injected
- Throws:
InternalProvisionException
- if a value cannot be provided
-
getDependencies
Description copied from interface:HasDependencies
Returns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for theInjector
will be included in the returned set.- Specified by:
getDependencies
in interfaceHasDependencies
- Returns:
- a possibly empty set
-
acceptExtensionVisitor
public <B,R> R acceptExtensionVisitor(BindingTargetVisitor<B, R> visitor, ProviderInstanceBinding<? extends B> binding) Description copied from interface:ProviderWithExtensionVisitor
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'.
- Specified by:
acceptExtensionVisitor
in interfaceProviderWithExtensionVisitor<T>
-
getKey
Description copied from interface:OptionalBinderBinding
Returns theKey
for this binding.- Specified by:
getKey
in interfaceOptionalBinderBinding<T>
-
getAlternateKeys
Description copied from interface:OptionalBinderBinding
Returns the keys of other bindings that represent this OptionalBinder. This will return an entry forOptional<com.google.inject.Provider<V>>
andOptional<javax.inject.Provider<V>>
.- Specified by:
getAlternateKeys
in interfaceOptionalBinderBinding<T>
-
getActualBinding
Description copied from interface:OptionalBinderBinding
Returns the actual binding (set byOptionalBinder.setBinding()
) or null if not set. This will throwUnsupportedOperationException
if it is called on an element retrieved fromElements.getElements(com.google.inject.Module...)
.The Binding's type will always match the type Optional's generic type. For example, if getKey returns a key of
Optional<String>
, then this will always return aBinding<String>
.- Specified by:
getActualBinding
in interfaceOptionalBinderBinding<T>
-
getDefaultBinding
Description copied from interface:OptionalBinderBinding
Returns the default binding (set byOptionalBinder.setDefault()
) if one exists or null if no default binding is set. This will throwUnsupportedOperationException
if it is called on an element retrieved fromElements.getElements(com.google.inject.Module...)
.The Binding's type will always match the type Optional's generic type. For example, if getKey returns a key of
Optional<String>
, then this will always return aBinding<String>
.- Specified by:
getDefaultBinding
in interfaceOptionalBinderBinding<T>
-
containsElement
Description copied from interface:OptionalBinderBinding
Returns true if this OptionalBinder contains the given Element in order to build the optional binding or uses the given Element in order to support building and injecting its data. This will work for OptionalBinderBinding retrieved from an injector andElements.getElements(com.google.inject.Module...)
. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwiseOptionalBinderBinding.getDefaultBinding()
andOptionalBinderBinding.getActualBinding()
are better options.- Specified by:
containsElement
in interfaceOptionalBinderBinding<T>
-