Author: limpbizkit
Date: Wed Oct 15 17:21:29 2008
New Revision: 636

Modified:
     
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
     
trunk/extensions/privatemodules/test/com/google/inject/privatemodules/PrivateModuleTest.java

Log:
Implementation-level docs for PrivateModules

Modified:  
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
==============================================================================
---  
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
  
(original)
+++  
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
  
Wed Oct 15 17:21:29 2008
@@ -82,7 +82,7 @@
   * </pre>
   *
   * <p>Private modules are implemented with [EMAIL PROTECTED]  
Injector#createChildInjector(Module[]) parent
- * injectors.} Types that inject an [EMAIL PROTECTED] Injector} will be 
provided with  
the child injector. This
+ * injectors}. Types that inject an [EMAIL PROTECTED] Injector} will be 
provided with  
the child injector. This
   * injector includes private bindings that are not available from the  
parent injector.
   *
   * @author [EMAIL PROTECTED] (Jesse Wilson)
@@ -101,6 +101,28 @@
    /** Like abstract module, the binder of the current private module */
    private Binder privateBinder;

+  /*
+   * This implementation is complicated in order to satisfy two different  
roles in one class:
+   *
+   *  1. As a public module (the one that installs this), we bind only the  
exposed keys. This is the
+   *     role we play first, when configure() is called by the installing  
binder. It collects the
+   *     exposed keys and their corresponding providers by executing  
itself as a private module.
+   *
+   *  2. As a private module, we bind everything. This is performed our  
own indirect re-entrant call
+   *     to configure() via the Elements.getElements() API.
+   *
+   * Throwing further wrenches into the mix:
+   *
+   *  o Provider methods. The ProviderMethodsModule class special cases  
modules that extend
+   *    PrivateModules to skip them by default. We have our own provider  
methods backdoor API
+   *    called ProviderMethodsModule.forPrivateModule so provider methods  
are only applied when
+   *    we're running as a private module. We also need to iterate through  
the provider methods
+   *    by hand to gather the ones with the @Exposed annotation
+   *
+   *  o Injector creation time. Dependencies can flow freely between child  
and parent injectors.
+   *    When providers are being exercised, we need to make sure the child  
injector construction
+   *    has started.
+   */
    public final synchronized void configure(Binder binder) {
      // when 'exposes' is null, we're being run for the public injector
      if (exposes == null) {
@@ -130,6 +152,7 @@
      }
    }

+
    private void configurePublicBindings(Binder publicBinder) {
      exposes = Sets.newLinkedHashSet();
      Key<Ready> readyKey = Key.get(Ready.class, UniqueAnnotations.create());
@@ -141,7 +164,7 @@

        for (Expose<?> expose : exposes) {
          if (!privatelyBoundKeys.contains(expose.key)) {
-          publicBinder.addError("Could not expose() at %s%n %s must be  
explicitly bound.",
+          publicBinder.addError("Could not expose() at %s%n %s must be  
explicitly bound.",
                expose.source, expose.key);
          } else {
            expose.configure(publicBinder);

Modified:  
trunk/extensions/privatemodules/test/com/google/inject/privatemodules/PrivateModuleTest.java
==============================================================================
---  
trunk/extensions/privatemodules/test/com/google/inject/privatemodules/PrivateModuleTest.java
     
(original)
+++  
trunk/extensions/privatemodules/test/com/google/inject/privatemodules/PrivateModuleTest.java
     
Wed Oct 15 17:21:29 2008
@@ -191,18 +191,18 @@
              return "A";
            }

-          @Provides @Exposed @Named("abc") String provideC(@Named("ab")  
String ab) {
+          @Provides @Exposed @Named("abc") String provideAbc(@Named("ab")  
String ab) {
              return ab + "C";
            }
          },
          new AbstractModule() {
            protected void configure() {}

-          @Provides @Named("ab") String provideB(@Named("a") String a) {
+          @Provides @Named("ab") String provideAb(@Named("a") String a) {
              return a + "B";
            }

-          @Provides @Named("abcd") String provideD(@Named("abc") String  
abc) {
+          @Provides @Named("abcd") String provideAbcd(@Named("abc") String  
abc) {
              return abc + "D";
            }
          }
@@ -220,7 +220,7 @@
              return "A";
            }

-          @Provides @Exposed @Named("abc") String provideC(@Named("ab")  
String ab) {
+          @Provides @Exposed @Named("abc") String provideAbc(@Named("ab")  
String ab) {
              return ab + "C";
            }
          },
@@ -235,11 +235,11 @@
              }).asEagerSingleton();
            }

-          @Provides @Named("ab") String provideB(@Named("a") String a) {
+          @Provides @Named("ab") String provideAb(@Named("a") String a) {
              return a + "B";
            }

-          @Provides @Named("abcd") String provideD(@Named("abc") String  
abc) {
+          @Provides @Named("abcd") String provideAbcd(@Named("abc") String  
abc) {
              return abc + "D";
            }
          }
@@ -253,11 +253,11 @@
          new AbstractModule() {
            protected void configure() {}

-          @Provides @Named("ab") String provideB(@Named("a") String a) {
+          @Provides @Named("ab") String provideAb(@Named("a") String a) {
              return a + "B";
            }

-          @Provides @Named("abcd") String provideD(@Named("abc") String  
abc) {
+          @Provides @Named("abcd") String provideAbcd(@Named("abc") String  
abc) {
              return abc + "D";
            }
          },
@@ -277,7 +277,7 @@
              return "A";
            }

-          @Provides @Exposed @Named("abc") String provideC(@Named("ab")  
String ab) {
+          @Provides @Exposed @Named("abc") String provideAbc(@Named("ab")  
String ab) {
              return ab + "C";
            }
          }

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