fix requireExplicitBindings so TypeLiteral<T> can be injected.

git-svn-id: https://google-guice.googlecode.com/svn/trunk@1217 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/internal/InjectorImpl.java b/src/com/google/inject/internal/InjectorImpl.java
index b9a78eb..ab8e281 100644
--- a/src/com/google/inject/internal/InjectorImpl.java
+++ b/src/com/google/inject/internal/InjectorImpl.java
@@ -211,7 +211,8 @@
       throws ErrorsException {
 
 
-    if(options.jitDisabled && jitType == JitLimitation.NO_JIT && !isProvider(key)) {
+    boolean jitOverride = isProvider(key) || isTypeLiteral(key);
+    if(options.jitDisabled && jitType == JitLimitation.NO_JIT && !jitOverride) {
       throw errors.jitDisabled(key).toException();
     }
     
@@ -226,7 +227,7 @@
         }
       }
       
-      if(options.jitDisabled && jitType != JitLimitation.NEW_OR_EXISTING_JIT && !isProvider(key)) {
+      if(options.jitDisabled && jitType != JitLimitation.NEW_OR_EXISTING_JIT && !jitOverride) {
         throw errors.jitDisabled(key).toException();
       } else {
         return createJustInTimeBindingRecursive(key, errors);
@@ -239,6 +240,10 @@
     return key.getTypeLiteral().getRawType().equals(Provider.class);
   }
   
+  private static boolean isTypeLiteral(Key<?> key) {
+    return key.getTypeLiteral().getRawType().equals(TypeLiteral.class);
+  }
+  
   private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException {
     Type providerType = key.getTypeLiteral().getType();
 
diff --git a/test/com/google/inject/JitBindingsTest.java b/test/com/google/inject/JitBindingsTest.java
index 95be8d3..6e48316 100644
--- a/test/com/google/inject/JitBindingsTest.java
+++ b/test/com/google/inject/JitBindingsTest.java
@@ -1,8 +1,12 @@
 package com.google.inject;
 
 import static com.google.inject.Asserts.assertContains;
+import static com.google.inject.internal.util.ImmutableSet.of;
+
 import junit.framework.TestCase;
 
+import java.util.Set;
+
 /**
  * Some tests for {@link InjectorBuilder#requireExplicitBindings()}
  * 
@@ -303,6 +307,22 @@
     }
   }
   
+  public void testTypeLiteralsCanBeInjected() {
+    Injector injector = new InjectorBuilder()
+      .requireExplicitBindings()
+      .addModules(new AbstractModule() {
+        @Override protected void configure() {
+          bind(new TypeLiteral<WantsTypeLiterals<String>>() {});
+          bind(new TypeLiteral<Set<String>>() {}).toInstance(of("bar"));
+        }
+      })
+      .build();
+
+    WantsTypeLiterals<String> foo = injector.getInstance(new Key<WantsTypeLiterals<String>>() {});
+    assertEquals(foo.literal.getRawType(), String.class);
+    assertEquals(of("bar"), foo.set);
+  }
+  
   private void ensureWorks(Injector injector, Class<?>... classes) {
     for(int i = 0; i < classes.length; i++) {
       injector.getInstance(classes[i]);
@@ -387,4 +407,15 @@
       return new ProvBy() {};
     }
   }
+  
+  private static class WantsTypeLiterals<T> {
+    TypeLiteral<T> literal;
+    Set<T> set;
+    
+    @Inject WantsTypeLiterals(TypeLiteral<T> literal, Set<T> set) {
+      this.literal = literal;
+      this.set = set;
+      
+    }
+  }
 }