Class RealMultibinder<T>
- All Implemented Interfaces:
Module
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 ClassesModifier and TypeClassDescriptionprivate static class
Base implement ofInternalProviderInstanceBindingImpl.Factory
that works based on aRealMultibinder.BindingSelection
, allowing provider instances for various bindings to be implemented with less duplication.private static final class
private static final class
Implementation of BaseFactory that exposes details about the multibinder through the extension SPI.private static class
We install the permit duplicates configuration as its own binding, all by itself.private static final class
Implementation of BaseFactory that exposes a collection of providers of the values in the set.private static final class
Provider instance implementation that provides the actual set of values. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Binder
private final RealMultibinder.BindingSelection<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <T> TypeLiteral<Collection<javax.inject.Provider<T>>>
collectionOfJavaxProvidersOf
(TypeLiteral<T> elementType) (package private) static <T> TypeLiteral<Collection<Provider<T>>>
collectionOfProvidersOf
(TypeLiteral<T> elementType) void
Contributes bindings and other configurations for this module tobinder
.(package private) boolean
containsElement
(Element element) boolean
(package private) TypeLiteral<T>
Adds a new entry to the set and returns the key for it.(package private) String
int
hashCode()
static <T> RealMultibinder<T>
newRealSetBinder
(Binder binder, Key<T> key) Implementation of newSetBinder.void
(package private) boolean
permitsDuplicates
(Injector injector) (package private) static <T> TypeLiteral<Set<T>>
setOf
(TypeLiteral<T> elementType) (package private) static <T> TypeLiteral<Set<? extends T>>
setOfExtendsOf
(TypeLiteral<T> elementType)
-
Field Details
-
bindingSelection
-
binder
-
-
Constructor Details
-
RealMultibinder
-
-
Method Details
-
newRealSetBinder
Implementation of newSetBinder. -
setOf
-
collectionOfProvidersOf
-
collectionOfJavaxProvidersOf
static <T> TypeLiteral<Collection<javax.inject.Provider<T>>> collectionOfJavaxProvidersOf(TypeLiteral<T> elementType) -
setOfExtendsOf
-
configure
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() -
getKeyForNewItem
Adds a new entry to the set and returns the key for it. -
addBinding
-
getSetKey
-
getElementTypeLiteral
TypeLiteral<T> getElementTypeLiteral() -
getSetName
String getSetName() -
permitsDuplicates
-
containsElement
-
equals
-
hashCode
public int hashCode()
-