Applied feedback from code reviews by Mike Ward and Giles Douglas.
http://code.google.com/p/google-guice/source/detail?r=633
git-svn-id: https://google-guice.googlecode.com/svn/trunk@642 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java b/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
index 27f73be..a694eb9 100644
--- a/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
+++ b/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
@@ -201,7 +201,7 @@
/** Makes the binding for {@code 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;
diff --git a/src/com/google/inject/internal/ProviderMethodsModule.java b/src/com/google/inject/internal/ProviderMethodsModule.java
index d102d63..c70e1e1 100644
--- a/src/com/google/inject/internal/ProviderMethodsModule.java
+++ b/src/com/google/inject/internal/ProviderMethodsModule.java
@@ -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 crazybob@google.com (Bob Lee)
+ * @author jessewilson@google.com (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
- 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;
- }
+ 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()) {
+ if (c.getName().equals("com.google.inject.privatemodules.PrivateModule")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/** See {@link 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));