google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

Modules.override() does not play nice with multibinder #263

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Because Multibinder relies on the fact that one module won't be installed
multiple times.

Original issue reported on code.google.com by limpbizkit on 21 Oct 2008 at 6:59

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 8 Dec 2008 at 7:18

GoogleCodeExporter commented 9 years ago
Upping priority to high. We've run into this problem internally at Google.

Original comment by limpbizkit on 19 Feb 2009 at 6:37

GoogleCodeExporter commented 9 years ago
Could this be resolved by making OverriddenModuleBuilder's equals/hashCode 
delegate
to the overridden module?

Original comment by net...@gmail.com on 17 Jul 2009 at 2:17

GoogleCodeExporter commented 9 years ago
Unfortunately delegating equals/hashCode doesn't seem to be possible, because
OverridenModuleBuilder can collapse many modules into a single one.  This is a 
tricky
one.

Original comment by sberlin on 26 Apr 2010 at 3:10

GoogleCodeExporter commented 9 years ago
Attached is a patch that fixes this.  It requires one addition to the API:
Binder.visitElements.  The signature & javadoc of it is:

---

  /**
   * Visits all elements that have already been processed by this Binder. This will
continue
   * visiting elements until the visitor returns true. If all known elements were
visited and the
   * visitor returned false, this returns false. Otherwise, (if the elementVisitor
returned true)
   * this returns true.
   * 
   * @param elementVisitor that will be applied to each element already processed.
   * @since 2.1
   */
  boolean visitElements(ElementVisitor<Boolean> elementVisitor);

---

I do not think it is possible to solve this without an API addition, and this 
was the
best I could think of.  (Other possibilities were: isBound(Key), V 
addBindInfo(Key
key, V value), ...)

Thoughts?

Original comment by sberlin on 2 May 2010 at 8:15

GoogleCodeExporter commented 9 years ago
Sorry, patch attached this time.

Original comment by sberlin on 2 May 2010 at 8:16

Attachments:

GoogleCodeExporter commented 9 years ago
Alternate patch based on deduplicating equal bindings (with no overhead to 
runtime or
memory if not using Modules.override).

Original comment by sberlin on 9 May 2010 at 1:34

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
A more complete version of the deduplication patch, with a suite of tests & bugs
fixed.  (Sorry if you get two emails of this.. I deleted the first one to add 
one
additional test.)

Original comment by sberlin on 16 May 2010 at 12:35

Attachments:

GoogleCodeExporter commented 9 years ago
fixed with r1178.

Original comment by sberlin on 24 Jun 2010 at 1:05