Status: Accepted
Owner: sberlin

New issue 539 by sberlin: Multibinder & MapBinder should have an extension SPI
http://code.google.com/p/google-guice/issues/detail?id=539

An extension SPI should be available for Multibinder & MapBinder, similar to the one added for the servlet extension in r1207. (The Guice extension SPI was added in r1206).

Attached is a patch for a multibindings extension SPI.  It adds:
* MultibindingsTargetVisitor, with a visit(MultibinderBinding) & visit(MapBinderBinding).

 * MultibinderBinding<T>, with:
   Key<T> setSetKey
   TypeLiteral<?> getElementTypeLiteral
   List<Binding<?>> getElements -- requires Injector
   boolean permitsDuplicates -- requires Injector
   boolean containsElement(Element)
   boolean isPermitDuplicatesElement(Element)

 * MapBinderBinding<T>, with:
    Key<T> getMapKey
    TypeLiteral<?> getKeyTypeLiteral
    TypeLiteral<?> getValueTypeLiteral
    List<Map.Entry<?, Binding<?>> getEntries -- requires Injector
    boolean permitsDuplicates -- requires Injector
    boolean containsElement(Element)
    ElementType getElementType(Element)
ElementType enum { VALUE, ENTRY, VALUE_PROVIDER, PERMIT_DUPLICATE, MAP_OF_PROVIDER, MAP_OF_SET, MAP_OF_SET_OF_PROVIDER, ENTRY_SET }

The rationale behind both the getEntries/getElements & containsElement+others was that the former methods require a live Injector in order to work. If an Injector is available, those methods are very easy to use. If an Injector isn't available (and we are processing based on Elements retrieved through the Elements SPI), then the multibindings can detect if an Element is part of itself if it's given the Element (but they cannot hand out their elements).

For details & javadoc, see the patch. Visitor tests were added to each existing test method, with a ton of support code in a new SpiUtils class.

Attachments:
        multibindings-visitor.txt  91.5 KB

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to