Package com.google.inject.internal
Class RealOptionalBinder.JavaOptionalProvider<T>
- java.lang.Object
-
- com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory<P>
-
- com.google.inject.internal.RealOptionalBinder.RealOptionalBinderProviderWithDependencies<T,java.util.Optional<T>>
-
- com.google.inject.internal.RealOptionalBinder.JavaOptionalProvider<T>
-
- All Implemented Interfaces:
InternalFactory<java.util.Optional<T>>
,OptionalBinderBinding<java.util.Optional<T>>
,Provider<java.util.Optional<T>>
,HasDependencies
,ProviderWithExtensionVisitor<java.util.Optional<T>>
,javax.inject.Provider<java.util.Optional<T>>
- Enclosing class:
- RealOptionalBinder<T>
private static final class RealOptionalBinder.JavaOptionalProvider<T> extends RealOptionalBinder.RealOptionalBinderProviderWithDependencies<T,java.util.Optional<T>> implements ProviderWithExtensionVisitor<java.util.Optional<T>>, OptionalBinderBinding<java.util.Optional<T>>
Provides the binding for java.util.Optional.
-
-
Field Summary
Fields Modifier and Type Field Description private Key<java.util.Optional<T>>
optionalKey
private InternalFactory<? extends T>
target
private Dependency<?>
targetDependency
-
Fields inherited from class com.google.inject.internal.RealOptionalBinder.RealOptionalBinderProviderWithDependencies
bindingSelection
-
Fields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback
-
-
Constructor Summary
Constructors Constructor Description JavaOptionalProvider(RealOptionalBinder.BindingSelection<T> bindingSelection, Key<java.util.Optional<T>> optionalKey)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <B,R>
RacceptExtensionVisitor(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
doInitialize()
Initialize the factory.protected java.util.Optional<T>
doProvision(InternalContext context, Dependency<?> currentDependency)
Creates an object to be injected.Binding<?>
getActualBinding()
Returns the actual binding (set byOptionalBinder.setBinding()
) or null if not set.java.util.Set<Key<?>>
getAlternateKeys()
Returns the keys of other bindings that represent this OptionalBinder.Binding<?>
getDefaultBinding()
Returns the default binding (set byOptionalBinder.setDefault()
) if one exists or null if no default binding is set.java.util.Set<Dependency<?>>
getDependencies()
Returns the known dependencies for this type.Key<java.util.Optional<T>>
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 Detail
-
targetDependency
private Dependency<?> targetDependency
-
target
private InternalFactory<? extends T> target
-
-
Constructor Detail
-
JavaOptionalProvider
JavaOptionalProvider(RealOptionalBinder.BindingSelection<T> bindingSelection, Key<java.util.Optional<T>> optionalKey)
-
-
Method Detail
-
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,java.util.Optional<T>>
-
doProvision
protected java.util.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<java.util.Optional<T>>
- Returns:
- instance to be injected
- Throws:
InternalProvisionException
- if a value cannot be provided
-
getDependencies
public java.util.Set<Dependency<?>> 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>
-
containsElement
public boolean containsElement(Element element)
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>
-
getActualBinding
public Binding<?> 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
public Binding<?> 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>
-
getKey
public Key<java.util.Optional<T>> getKey()
Description copied from interface:OptionalBinderBinding
Returns theKey
for this binding.- Specified by:
getKey
in interfaceOptionalBinderBinding<T>
-
getAlternateKeys
public java.util.Set<Key<?>> 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>
-
-