Renamed Generator to Factory.

git-svn-id: https://google-guice.googlecode.com/svn/trunk@165 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/Container.java b/src/com/google/inject/Container.java
index 87c2d85..4299d51 100644
--- a/src/com/google/inject/Container.java
+++ b/src/com/google/inject/Container.java
@@ -40,11 +40,6 @@
   void injectMembers(Object o);
 
   /**
-   * Gets the locator bound to the given key.
-   */
-  <T> Locator<T> getLocator(Key<T> key);
-
-  /**
    * Gets all bindings.
    */
   Map<Key<?>, Binding<?>> getBindings();
@@ -60,16 +55,6 @@
   <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type);
 
   /**
-   * Gets the locator bound to the given type.
-   */
-  <T> Locator<T> getLocator(Class<T> type);
-
-  /**
-   * Gets the locator bound to the given type.
-   */
-  <T> Locator<T> getLocator(TypeLiteral<T> type);
-
-  /**
    * Gets an instance from the locator bound to the given type.
    */
   <T> T getInstance(TypeLiteral<T> type);
@@ -95,16 +80,6 @@
   <T> T getInstance(Class<T> type, Annotation annotation);
 
   /**
-   * Gets the locator bound to the given type and annotation.
-   */
-  <T> Locator<T> getLocator(Class<T> type, Annotation annotation);
-
-  /**
-   * Gets the locator bound to the given type and annotation.
-   */
-  <T> Locator<T> getLocator(TypeLiteral<T> type, Annotation annotation);
-
-  /**
    * Gets an instance from the locator bound to the given type and annotation.
    */
   <T> T getInstance(TypeLiteral<T> type,
@@ -117,6 +92,31 @@
       Class<? extends Annotation> annotationType);
 
   /**
+   * Gets the locator bound to the given key.
+   */
+  <T> Locator<T> getLocator(Key<T> key);
+
+  /**
+   * Gets the locator bound to the given type.
+   */
+  <T> Locator<T> getLocator(Class<T> type);
+
+  /**
+   * Gets the locator bound to the given type.
+   */
+  <T> Locator<T> getLocator(TypeLiteral<T> type);
+
+  /**
+   * Gets the locator bound to the given type and annotation.
+   */
+  <T> Locator<T> getLocator(Class<T> type, Annotation annotation);
+
+  /**
+   * Gets the locator bound to the given type and annotation.
+   */
+  <T> Locator<T> getLocator(TypeLiteral<T> type, Annotation annotation);
+
+  /**
    * Gets the locator bound to the given type and annotation.
    */
   <T> Locator<T> getLocator(Class<T> type,
diff --git a/src/com/google/inject/ContainerBuilder.java b/src/com/google/inject/ContainerBuilder.java
index 21a59b1..7e99764 100644
--- a/src/com/google/inject/ContainerBuilder.java
+++ b/src/com/google/inject/ContainerBuilder.java
@@ -562,11 +562,11 @@
     }
 
     /**
-     * Binds to instances generated by the given generator.
+     * Binds to instances generated by the given factory.
      */
-    public BindingBuilder<T> to(Generator<? extends T> generator) {
+    public BindingBuilder<T> to(Factory<? extends T> factory) {
       ensureImplementationIsNotSet();
-      this.factory = new InternalFactoryToGeneratorAdapter<T>(generator);
+      this.factory = new InternalFactoryToFactoryAdapter<T>(factory);
       return this;
     }
 
@@ -594,32 +594,32 @@
     }
 
     /**
-     * Binds to instances from the generator bound to the given type.
+     * Binds to instances from the factory bound to the given type.
      */
-    public BindingBuilder<T> toGenerator(
-        final Class<? extends Generator<T>> generatorType) {
-      return toGenerator(Key.get(generatorType));
+    public BindingBuilder<T> toFactory(
+        final Class<? extends Factory<T>> factoryType) {
+      return toFactory(Key.get(factoryType));
     }
 
     /**
-     * Binds to instances from the generator bound to the given type.
+     * Binds to instances from the factory bound to the given type.
      */
-    public BindingBuilder<T> toGenerator(
-        final TypeLiteral<? extends Generator<T>> generatorType) {
-      return toGenerator(Key.get(generatorType));
+    public BindingBuilder<T> toFactory(
+        final TypeLiteral<? extends Factory<T>> factoryType) {
+      return toFactory(Key.get(factoryType));
     }
 
     /**
      * Binds to instances from the given generator bound to the given key.
      */
-    public BindingBuilder<T> toGenerator(
-        final Key<? extends Generator<T>> generatorKey) {
+    public BindingBuilder<T> toFactory(
+        final Key<? extends Factory<T>> factoryKey) {
       ensureImplementationIsNotSet();
 
-      final BoundGenerator<T> boundGenerator =
-          new BoundGenerator<T>(generatorKey, errorHandler);
-      creationListeners.add(boundGenerator);
-      this.factory = boundGenerator;
+      final BoundFactory<T> boundFactory =
+          new BoundFactory<T>(factoryKey, errorHandler);
+      creationListeners.add(boundFactory);
+      this.factory = boundFactory;
 
       return this;
     }
@@ -715,37 +715,36 @@
   }
 
   /**
-   * Delegates to a custom generator which is also bound in the container.
+   * Delegates to a custom factory which is also bound in the container.
    */
-  private static class BoundGenerator<T>
+  private static class BoundFactory<T>
       implements InternalFactory<T>, CreationListener {
 
-    final Key<? extends Generator<? extends T>> generatorKey;
+    final Key<? extends Factory<? extends T>> factoryKey;
     final ErrorHandler errorHandler;
-    private InternalFactory<? extends Generator<? extends T>> generatorFactory;
+    private InternalFactory<? extends Factory<? extends T>> factoryFactory;
 
-    public BoundGenerator(
-        Key<? extends Generator<? extends T>> generatorKey,
+    public BoundFactory(
+        Key<? extends Factory<? extends T>> factoryKey,
         ErrorHandler errorHandler) {
-      this.generatorKey = generatorKey;
+      this.factoryKey = factoryKey;
       this.errorHandler = errorHandler;
     }
 
     public void notify(final ContainerImpl container) {
       container.withErrorHandler(errorHandler, new Runnable() {
         public void run() {
-          generatorFactory = container.getInternalFactory(
-              null, generatorKey);
+          factoryFactory = container.getInternalFactory(null, factoryKey);
         }
       });
     }
 
     public String toString() {
-      return generatorKey.toString();
+      return factoryKey.toString();
     }
 
     public T get(InternalContext context) {
-      return generatorFactory
+      return factoryFactory
           .get(context)
           .generate(context.getExternalContext());
     }
diff --git a/src/com/google/inject/Generator.java b/src/com/google/inject/Factory.java
similarity index 96%
rename from src/com/google/inject/Generator.java
rename to src/com/google/inject/Factory.java
index cfd3623..c97085c 100644
--- a/src/com/google/inject/Generator.java
+++ b/src/com/google/inject/Factory.java
@@ -21,7 +21,7 @@
  *
  * @author crazybob@google.com (Bob Lee)
  */
-public interface Generator<T> {
+public interface Factory<T> {
 
   /**
    * Generates an instance of {@code T} given the context of the injection.
diff --git a/src/com/google/inject/InternalFactoryToGeneratorAdapter.java b/src/com/google/inject/InternalFactoryToFactoryAdapter.java
similarity index 80%
rename from src/com/google/inject/InternalFactoryToGeneratorAdapter.java
rename to src/com/google/inject/InternalFactoryToFactoryAdapter.java
index afd9bfb..184f220 100644
--- a/src/com/google/inject/InternalFactoryToGeneratorAdapter.java
+++ b/src/com/google/inject/InternalFactoryToFactoryAdapter.java
@@ -19,12 +19,12 @@
 /**
  * @author crazybob@google.com (Bob Lee)
 */
-class InternalFactoryToGeneratorAdapter<T> implements InternalFactory<T> {
+class InternalFactoryToFactoryAdapter<T> implements InternalFactory<T> {
 
-  private final Generator<? extends T> factory;
+  private final Factory<? extends T> factory;
 
-  public InternalFactoryToGeneratorAdapter(
-      Generator<? extends T> factory) {
+  public InternalFactoryToFactoryAdapter(
+      Factory<? extends T> factory) {
     this.factory = factory;
   }
 
diff --git a/src/com/google/inject/package-info.java b/src/com/google/inject/package-info.java
index 8750d8a..57c2119 100644
--- a/src/com/google/inject/package-info.java
+++ b/src/com/google/inject/package-info.java
@@ -38,7 +38,7 @@
  * <dd>The object that Guice passes into your {@link com.google.inject.Module}
  *     to collect these bindings.
  *
- * <dt>{@link com.google.inject.Generator}
+ * <dt>{@link com.google.inject.Factory}
  * <dd>The interface you will implement when you need to customize exactly how
  *     Guice creates instances for a particular binding.
  *
diff --git a/src/com/google/inject/servlet/ServletModule.java b/src/com/google/inject/servlet/ServletModule.java
index 63df37b..ccbb153 100644
--- a/src/com/google/inject/servlet/ServletModule.java
+++ b/src/com/google/inject/servlet/ServletModule.java
@@ -18,7 +18,7 @@
 
 import com.google.inject.AbstractModule;
 import com.google.inject.TypeLiteral;
-import com.google.inject.Generator;
+import com.google.inject.Factory;
 import com.google.inject.Context;
 import static com.google.inject.servlet.ServletScopes.REQUEST;
 import static com.google.inject.servlet.ServletScopes.SESSION;
@@ -45,8 +45,8 @@
     scope(SessionScoped.class, SESSION);
 
     // Bind request.
-    Generator<HttpServletRequest> requestGenerator =
-        new Generator<HttpServletRequest>() {
+    Factory<HttpServletRequest> requestFactory =
+        new Factory<HttpServletRequest>() {
           public HttpServletRequest generate(Context context) {
             return GuiceFilter.getRequest();
           }
@@ -55,12 +55,12 @@
             return "RequestFactory";
           }
         };
-    bind(HttpServletRequest.class).to(requestGenerator);
-    bind(ServletRequest.class).to(requestGenerator);
+    bind(HttpServletRequest.class).to(requestFactory);
+    bind(ServletRequest.class).to(requestFactory);
 
     // Bind response.
-    Generator<HttpServletResponse> responseGenerator =
-        new Generator<HttpServletResponse>() {
+    Factory<HttpServletResponse> responseFactory =
+        new Factory<HttpServletResponse>() {
           public HttpServletResponse generate(Context context) {
             return GuiceFilter.getResponse();
           }
@@ -69,11 +69,11 @@
             return "ResponseFactory";
           }
         };
-    bind(HttpServletResponse.class).to(responseGenerator);
-    bind(ServletResponse.class).to(responseGenerator);
+    bind(HttpServletResponse.class).to(responseFactory);
+    bind(ServletResponse.class).to(responseFactory);
 
     // Bind session.
-    bind(HttpSession.class).to(new Generator<HttpSession>() {
+    bind(HttpSession.class).to(new Factory<HttpSession>() {
       public HttpSession generate(Context context) {
         return GuiceFilter.getRequest().getSession();
       }
@@ -86,7 +86,7 @@
     // Bind request parameters.
     bind(new TypeLiteral<Map<String, String[]>>() {})
         .annotatedWith(RequestParameters.class)
-        .to(new Generator<Map<String, String[]>>() {
+        .to(new Factory<Map<String, String[]>>() {
               @SuppressWarnings({"unchecked"})
               public Map<String, String[]> generate(Context context) {
                 return GuiceFilter.getRequest().getParameterMap();
diff --git a/test/com/google/inject/AllTests.java b/test/com/google/inject/AllTests.java
index be10283..6e2b4b7 100644
--- a/test/com/google/inject/AllTests.java
+++ b/test/com/google/inject/AllTests.java
@@ -42,14 +42,14 @@
     suite.addTestSuite(CircularDependencyTest.class);
     suite.addTestSuite(StaticInjectionTest.class);
     suite.addTestSuite(NotRequiredTest.class);
-    suite.addTestSuite(GeneratorTest.class);
+    suite.addTestSuite(FactoryTest.class);
     suite.addTestSuite(SuperclassTest.class);
     suite.addTestSuite(LocatorInjectionTest.class);
     suite.addTestSuite(PreloadingTest.class);
     suite.addTestSuite(ReflectionTest.class);
     suite.addTestSuite(ScopesTest.class);
     suite.addTestSuite(ImplicitBindingTest.class);
-    suite.addTestSuite(BoundGeneratorTest.class);
+    suite.addTestSuite(BoundFactoryTest.class);
 
     suite.addTestSuite(MatcherTest.class);
     suite.addTestSuite(ProxyFactoryTest.class);
diff --git a/test/com/google/inject/BoundGeneratorTest.java b/test/com/google/inject/BoundFactoryTest.java
similarity index 81%
rename from test/com/google/inject/BoundGeneratorTest.java
rename to test/com/google/inject/BoundFactoryTest.java
index 8a67e43..a15d4c0 100644
--- a/test/com/google/inject/BoundGeneratorTest.java
+++ b/test/com/google/inject/BoundFactoryTest.java
@@ -21,11 +21,11 @@
 /**
  * @author crazybob@google.com (Bob Lee)
  */
-public class BoundGeneratorTest extends TestCase {
+public class BoundFactoryTest extends TestCase {
 
-  public void testFooGenerator() throws CreationException {
+  public void testFooFactory() throws CreationException {
     ContainerBuilder cb = new ContainerBuilder();
-    cb.bind(Foo.class).toGenerator(FooGenerator.class);
+    cb.bind(Foo.class).toFactory(FooFactory.class);
     Container c = cb.create();
 
     Foo a = c.getInstance(Foo.class);
@@ -38,10 +38,10 @@
     assertNotSame(a.bar, b.bar);
   }
 
-  public void testContainerScopedFooGenerator()
+  public void testContainerScopedFooFactory()
       throws CreationException {
     ContainerBuilder cb = new ContainerBuilder();
-    cb.bind(Foo.class).toGenerator(ContainerScopedFooGenerator.class);
+    cb.bind(Foo.class).toFactory(ContainerScopedFooFactory.class);
     Container c = cb.create();
 
     Foo a = c.getInstance(Foo.class);
@@ -66,13 +66,13 @@
     }
   }
 
-  static class FooGenerator implements Generator<Foo> {
+  static class FooFactory implements Factory<Foo> {
 
     final Bar bar;
     int count = 0;
 
     @Inject
-    public FooGenerator(Bar bar) {
+    public FooFactory(Bar bar) {
       this.bar = bar;
     }
 
@@ -85,13 +85,13 @@
   }
 
   @ContainerScoped
-  static class ContainerScopedFooGenerator implements Generator<Foo> {
+  static class ContainerScopedFooFactory implements Factory<Foo> {
 
     final Bar bar;
     int count = 0;
 
     @Inject
-    public ContainerScopedFooGenerator(Bar bar) {
+    public ContainerScopedFooFactory(Bar bar) {
       this.bar = bar;
     }