Author: limpbizkit
Date: Mon Mar 30 17:18:59 2009
New Revision: 919

Modified:
    trunk/src/com/google/inject/spi/ModuleWriter.java
    trunk/test/com/google/inject/spi/ElementsTest.java

Log:
InjectableTypeListenerBinding elements now participate in module rewriting.  
This is necessary to use 'em in Modules.override().

Modified: trunk/src/com/google/inject/spi/ModuleWriter.java
==============================================================================
--- trunk/src/com/google/inject/spi/ModuleWriter.java   (original)
+++ trunk/src/com/google/inject/spi/ModuleWriter.java   Mon Mar 30 17:18:59  
2009
@@ -109,8 +109,9 @@
          return null;
        }

-      public Void visit(InjectableTypeListenerBinding binding) {
-        throw new UnsupportedOperationException("TODO");
+      public Void visit(InjectableTypeListenerBinding element) {
+        writeBindListener(binder, element);
+        return null;
        }

        public Void visit(PrivateElements privateElements) {
@@ -137,13 +138,18 @@
    }
    /*end[AOP]*/

+  protected void writeBindListener(Binder binder,  
InjectableTypeListenerBinding element) {
+    binder.withSource(element.getSource())
+        .bindListener(element.getTypeMatcher(), element.getListener());
+  }
+
    protected void writeBindScope(Binder binder, ScopeBinding element) {
      binder.withSource(element.getSource()).bindScope(
          element.getAnnotationType(), element.getScope());
    }

-  protected void writeRequestInjection(Binder binder, InjectionRequest  
command) {
-     
binder.withSource(command.getSource()).requestInjection(command.getInstance());
+  protected void writeRequestInjection(Binder binder, InjectionRequest  
element) {
+     
binder.withSource(element.getSource()).requestInjection(element.getInstance());
    }

    protected void writeRequestStaticInjection(Binder binder,  
StaticInjectionRequest element) {

Modified: trunk/test/com/google/inject/spi/ElementsTest.java
==============================================================================
--- trunk/test/com/google/inject/spi/ElementsTest.java  (original)
+++ trunk/test/com/google/inject/spi/ElementsTest.java  Mon Mar 30 17:18:59  
2009
@@ -588,6 +588,32 @@
      );
    }

+  public void testBindListener() {
+    final Matcher<Object> typeMatcher =  
Matchers.only(TypeLiteral.get(String.class));
+    final InjectableType.Listener listener = new InjectableType.Listener()  
{
+      public <I> void hear(
+          InjectableType<I> injectableType, InjectableType.Encounter<I>  
encounter) {
+        throw new UnsupportedOperationException();
+      }
+    };
+
+    checkModule(
+        new AbstractModule() {
+          protected void configure() {
+            bindListener(typeMatcher, listener);
+          }
+        },
+
+        new FailingElementVisitor() {
+          @Override public Void visit(InjectableTypeListenerBinding  
binding) {
+            assertSame(typeMatcher, binding.getTypeMatcher());
+            assertSame(listener, binding.getListener());
+            return null;
+          }
+        }
+    );
+  }
+
    public void testConvertToTypes() {
      final TypeConverter typeConverter = new TypeConverter() {
        public Object convert(String value, TypeLiteral<?> toType) {

--~--~---------~--~----~------------~-------~--~----~
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