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
bindingSelectionFields 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.booleancontainsElement(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) voidInitialize 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 theKeyfor this binding.Methods inherited from class com.google.inject.internal.RealOptionalBinder.RealOptionalBinderProviderWithDependencies
equals, hashCode, initializeMethods 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.RealOptionalBinderProviderWithDependenciesInitialize the factory. BindingSelection is guaranteed to be initialized at this point and this will be called prior to any provisioning.- Specified by:
doInitializein 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.FactoryCreates an object to be injected.- Specified by:
doProvisionin 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:HasDependenciesReturns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for theInjectorwill be included in the returned set.- Specified by:
getDependenciesin interfaceHasDependencies- Returns:
- a possibly empty set
-
acceptExtensionVisitor
public <B,R> R acceptExtensionVisitor(BindingTargetVisitor<B, R> visitor, ProviderInstanceBinding<? extends B> binding) Description copied from interface:ProviderWithExtensionVisitorInstructs 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:
acceptExtensionVisitorin interfaceProviderWithExtensionVisitor<T>
-
getKey
Description copied from interface:OptionalBinderBindingReturns theKeyfor this binding.- Specified by:
getKeyin interfaceOptionalBinderBinding<T>
-
getAlternateKeys
Description copied from interface:OptionalBinderBindingReturns 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:
getAlternateKeysin interfaceOptionalBinderBinding<T>
-
getActualBinding
Description copied from interface:OptionalBinderBindingReturns the actual binding (set byOptionalBinder.setBinding()) or null if not set. This will throwUnsupportedOperationExceptionif 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:
getActualBindingin interfaceOptionalBinderBinding<T>
-
getDefaultBinding
Description copied from interface:OptionalBinderBindingReturns the default binding (set byOptionalBinder.setDefault()) if one exists or null if no default binding is set. This will throwUnsupportedOperationExceptionif 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:
getDefaultBindingin interfaceOptionalBinderBinding<T>
-
containsElement
Description copied from interface:OptionalBinderBindingReturns 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:
containsElementin interfaceOptionalBinderBinding<T>
-