Class RealMultibinder<T>
- java.lang.Object
-
- com.google.inject.internal.RealMultibinder<T>
-
- All Implemented Interfaces:
Module
public final class RealMultibinder<T> extends java.lang.Object implements Module
The actual multibinder plays several roles:As a Multibinder, it acts as a factory for LinkedBindingBuilders for each of the set's elements. Each binding is given an annotation that identifies it as a part of this set.
As a Module, it installs the binding to the set itself. As a module, this implements equals() and hashcode() in order to trick Guice into executing its configure() method only once. That makes it so that multiple multibinders can be created for the same target collection, but only one is bound. Since the list of bindings is retrieved from the injector itself (and not the multibinder), each multibinder has access to all contributions from all multibinders.
As a Provider, this constructs the set instances.
We use a subclass to hide 'implements Module, Provider' from the public API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RealMultibinder.BaseFactory<ValueT,ProvidedT>
Base implement ofInternalProviderInstanceBindingImpl.Factory
that works based on aRealMultibinder.BindingSelection
, allowing provider instances for various bindings to be implemented with less duplication.private static class
RealMultibinder.BindingSelection<T>
private static class
RealMultibinder.ExtensionRealMultibinderProvider<T>
Implementation of BaseFactory that exposes details about the multibinder through the extension SPI.private static class
RealMultibinder.PermitDuplicatesModule
We install the permit duplicates configuration as its own binding, all by itself.private static class
RealMultibinder.RealMultibinderCollectionOfProvidersProvider<T>
Implementation of BaseFactory that exposes a collection of providers of the values in the set.private static class
RealMultibinder.RealMultibinderProvider<T>
Provider instance implementation that provides the actual set of values.
-
Field Summary
Fields Modifier and Type Field Description private Binder
binder
private RealMultibinder.BindingSelection<T>
bindingSelection
-
Constructor Summary
Constructors Constructor Description RealMultibinder(Binder binder, Key<T> key)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LinkedBindingBuilder<T>
addBinding()
(package private) static <T> TypeLiteral<java.util.Collection<javax.inject.Provider<T>>>
collectionOfJavaxProvidersOf(TypeLiteral<T> elementType)
(package private) static <T> TypeLiteral<java.util.Collection<Provider<T>>>
collectionOfProvidersOf(TypeLiteral<T> elementType)
void
configure(Binder binder)
Contributes bindings and other configurations for this module tobinder
.(package private) boolean
containsElement(Element element)
boolean
equals(java.lang.Object o)
(package private) TypeLiteral<T>
getElementTypeLiteral()
(package private) Key<T>
getKeyForNewItem()
Adds a new entry to the set and returns the key for it.(package private) Key<java.util.Set<T>>
getSetKey()
(package private) java.lang.String
getSetName()
int
hashCode()
static <T> RealMultibinder<T>
newRealSetBinder(Binder binder, Key<T> key)
Implementation of newSetBinder.void
permitDuplicates()
(package private) boolean
permitsDuplicates(Injector injector)
(package private) static <T> TypeLiteral<java.util.Set<T>>
setOf(TypeLiteral<T> elementType)
(package private) static <T> TypeLiteral<java.util.Set<? extends T>>
setOfExtendsOf(TypeLiteral<T> elementType)
-
-
-
Field Detail
-
bindingSelection
private final RealMultibinder.BindingSelection<T> bindingSelection
-
binder
private final Binder binder
-
-
Method Detail
-
newRealSetBinder
public static <T> RealMultibinder<T> newRealSetBinder(Binder binder, Key<T> key)
Implementation of newSetBinder.
-
setOf
static <T> TypeLiteral<java.util.Set<T>> setOf(TypeLiteral<T> elementType)
-
collectionOfProvidersOf
static <T> TypeLiteral<java.util.Collection<Provider<T>>> collectionOfProvidersOf(TypeLiteral<T> elementType)
-
collectionOfJavaxProvidersOf
static <T> TypeLiteral<java.util.Collection<javax.inject.Provider<T>>> collectionOfJavaxProvidersOf(TypeLiteral<T> elementType)
-
setOfExtendsOf
static <T> TypeLiteral<java.util.Set<? extends T>> setOfExtendsOf(TypeLiteral<T> elementType)
-
configure
public void configure(Binder binder)
Description copied from interface:Module
Contributes bindings and other configurations for this module tobinder
.Do not invoke this method directly to install submodules. Instead use
Binder.install(Module)
, which ensures thatprovider methods
are discovered.
-
permitDuplicates
public void permitDuplicates()
-
addBinding
public LinkedBindingBuilder<T> addBinding()
-
getElementTypeLiteral
TypeLiteral<T> getElementTypeLiteral()
-
getSetName
java.lang.String getSetName()
-
permitsDuplicates
boolean permitsDuplicates(Injector injector)
-
containsElement
boolean containsElement(Element element)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-