Revision: 1119
Author: limpbizkit
Date: Mon Oct 12 16:16:51 2009
Log: Apply sberlin's patch for issue 434

http://code.google.com/p/google-guice/source/detail?r=1119

Modified:
  /trunk/src/com/google/inject/internal/ConstructorBindingImpl.java
  /trunk/test/com/google/inject/BindingTest.java

=======================================
--- /trunk/src/com/google/inject/internal/ConstructorBindingImpl.java   Mon  
Aug 10 16:57:56 2009
+++ /trunk/src/com/google/inject/internal/ConstructorBindingImpl.java   Mon  
Oct 12 16:16:51 2009
@@ -65,7 +65,11 @@
        InjectionPoint constructorInjector, Object source, Scoping scoping,  
Errors errors)
        throws ErrorsException {
      int numErrors = errors.size();
-    Class<? super T> rawType = key.getTypeLiteral().getRawType();
+
+    @SuppressWarnings("unchecked") // constructorBinding guarantees type  
is consistent
+    Class<? super T> rawType = constructorInjector == null
+        ? key.getTypeLiteral().getRawType()
+        : (Class) constructorInjector.getDeclaringType().getRawType();

      // We can't inject abstract classes.
      if (Modifier.isAbstract(rawType.getModifiers())) {
=======================================
--- /trunk/test/com/google/inject/BindingTest.java      Thu Jul 16 20:10:13 2009
+++ /trunk/test/com/google/inject/BindingTest.java      Mon Oct 12 16:16:51 2009
@@ -364,6 +364,21 @@
      assertEquals(ImmutableSet.of(TypeLiteral.get(Stage.class),  
TypeLiteral.get(D.class)),
          heardTypes);
    }
+
+  public void testInterfaceToImplementationConstructor() throws  
NoSuchMethodException {
+    final Constructor<CFoo> constructor =  
CFoo.class.getDeclaredConstructor();
+
+    Injector injector = Guice.createInjector(new AbstractModule() {
+      protected void configure() {
+        bind(IFoo.class).toConstructor(constructor);
+      }
+    });
+
+    injector.getInstance(IFoo.class);
+  }
+
+  public static interface IFoo {}
+  public static class CFoo implements IFoo {}

    public void testGetAllBindings() {
      Injector injector = Guice.createInjector(new AbstractModule() {

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