Author: limpbizkit
Date: Fri Oct 17 10:25:00 2008
New Revision: 642

Modified:
     
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
    trunk/src/com/google/inject/internal/ProviderMethodsModule.java

Log:
Applied feedback from code reviews by Mike Ward and Giles Douglas.
http://code.google.com/p/google-guice/source/detail?r=633


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
  
Fri Oct 17 10:25:00 2008
@@ -201,7 +201,7 @@

    /** Makes the binding for [EMAIL PROTECTED] key} available to other modules 
and the  
injector. */
    protected final <T> void expose(Key<T> key) {
-    checkState(exposes != null, "Cannot expose %s, private module is not  
ready");
+    checkState(exposes != null, "Cannot expose %s, private module is not  
ready", key);
      exposes.add(new Expose<T>(sourceProvider.get(), readyProvider, key));
    }

@@ -211,7 +211,7 @@
     * annotation.
     */
    protected final <T> ExposedKeyBuilder expose(Class<T> type) {
-    checkState(exposes != null, "Cannot expose %s, private module is not  
ready");
+    checkState(exposes != null, "Cannot expose %s, private module is not  
ready", type);
      Expose<T> expose = new Expose<T>(sourceProvider.get(), readyProvider,  
Key.get(type));
      exposes.add(expose);
      return expose;
@@ -223,7 +223,7 @@
     * annotation.
     */
    protected final <T> ExposedKeyBuilder expose(TypeLiteral<T> type) {
-    checkState(exposes != null, "Cannot expose %s, private module is not  
ready");
+    checkState(exposes != null, "Cannot expose %s, private module is not  
ready", type);
      Expose<T> expose = new Expose<T>(sourceProvider.get(), readyProvider,  
Key.get(type));
      exposes.add(expose);
      return expose;

Modified: trunk/src/com/google/inject/internal/ProviderMethodsModule.java
==============================================================================
--- trunk/src/com/google/inject/internal/ProviderMethodsModule.java      
(original)
+++ trunk/src/com/google/inject/internal/ProviderMethodsModule.java     Fri Oct 
 
17 10:25:00 2008
@@ -16,7 +16,9 @@

  package com.google.inject.internal;

+import com.google.common.base.Preconditions;
  import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkArgument;
  import com.google.common.collect.Lists;
  import com.google.inject.Binder;
  import com.google.inject.Key;
@@ -37,6 +39,7 @@
   * binding annotations on the provider method to configure the binding.
   *
   * @author [EMAIL PROTECTED] (Bob Lee)
+ * @author [EMAIL PROTECTED] (Jesse Wilson)
   */
  public final class ProviderMethodsModule implements Module {
    private final Module delegate;
@@ -57,19 +60,27 @@
      }

      // don't install provider methods for private modules, they take care  
of that manually
+    if (isPrivateModule(module)) {
+      return Modules.EMPTY_MODULE;
+    }
+
+    return new ProviderMethodsModule(module);
+  }
+
+  private static boolean isPrivateModule(Module module) {
+    // use the ugly class name to avoid an even uglier dependency. If  
private modules ever get
+    // incorporated into core, we could use a single instanceof instead of  
this loop
      for (Class<?> c = module.getClass(); c != Object.class; c =  
c.getSuperclass()) {
-      // use the ugly class name to avoid an even uglier dependency. If  
private modules ever get
-      // incorporated into core, we could use a single instanceof instead  
of this loop
        if  
(c.getName().equals("com.google.inject.privatemodules.PrivateModule")) {
-        return Modules.EMPTY_MODULE;
+        return true;
        }
      }
-
-    return new ProviderMethodsModule(module);
+    return false;
    }

    /** See [EMAIL PROTECTED] com.google.inject.privatemodules.PrivateModule}. 
*/
    public static ProviderMethodsModule forPrivateModule(Module  
privateModule) {
+    checkArgument(isPrivateModule(privateModule));
      return new ProviderMethodsModule(privateModule);
    }

@@ -81,7 +92,7 @@

    public List<ProviderMethod<?>> getProviderMethods(Binder binder) {
      List<ProviderMethod<?>> result = Lists.newArrayList();
-    for (Class c = delegate.getClass(); c != Object.class; c =  
c.getSuperclass()) {
+    for (Class<?> c = delegate.getClass(); c != Object.class; c =  
c.getSuperclass()) {
        for (Method method : c.getDeclaredMethods()) {
          if (method.isAnnotationPresent(Provides.class)) {
            result.add(createProviderMethod(binder, method));

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