Set a bit in ProviderMethodsModule to see if we are generating provider methods for gin. If we are, skip fast class generation.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=71452336
diff --git a/core/src/com/google/inject/internal/ProviderMethod.java b/core/src/com/google/inject/internal/ProviderMethod.java
index 728d9a9..1a952ed 100644
--- a/core/src/com/google/inject/internal/ProviderMethod.java
+++ b/core/src/com/google/inject/internal/ProviderMethod.java
@@ -52,16 +52,17 @@
/**
* Creates a {@link ProviderMethod}.
*
- * <p>Ideally, we will use {@link FastClass} to invoke the actual method, since it is
- * significantly faster. However, this will fail if the method is {@code private} or
- * {@code protected}, since fastclass is subject to java access policies.
+ * <p>Unless {@code skipFastClassGeneration} is set, this will use {@link FastClass} to invoke
+ * the actual method, since it is significantly faster. However, this will fail if the method is
+ * {@code private} or {@code protected}, since fastclass is subject to java access policies.
*/
static <T> ProviderMethod<T> create(Key<T> key, Method method, Object instance,
ImmutableSet<Dependency<?>> dependencies, List<Provider<?>> parameterProviders,
- Class<? extends Annotation> scopeAnnotation) {
+ Class<? extends Annotation> scopeAnnotation, boolean skipFastClassGeneration) {
int modifiers = method.getModifiers();
/*if[AOP]*/
- if (!Modifier.isPrivate(modifiers) && !Modifier.isProtected(modifiers)) {
+ if (!skipFastClassGeneration && !Modifier.isPrivate(modifiers)
+ && !Modifier.isProtected(modifiers)) {
try {
// We use an index instead of FastMethod to save a stack frame.
return new FastClassProviderMethod<T>(
diff --git a/core/src/com/google/inject/internal/ProviderMethodsModule.java b/core/src/com/google/inject/internal/ProviderMethodsModule.java
index e36c9b7..1074bd2 100644
--- a/core/src/com/google/inject/internal/ProviderMethodsModule.java
+++ b/core/src/com/google/inject/internal/ProviderMethodsModule.java
@@ -50,30 +50,39 @@
public final class ProviderMethodsModule implements Module {
private final Object delegate;
private final TypeLiteral<?> typeLiteral;
+ private final boolean skipFastClassGeneration;
- private ProviderMethodsModule(Object delegate) {
+ private ProviderMethodsModule(Object delegate, boolean skipFastClassGeneration) {
this.delegate = checkNotNull(delegate, "delegate");
this.typeLiteral = TypeLiteral.get(this.delegate.getClass());
+ this.skipFastClassGeneration = skipFastClassGeneration;
}
/**
* Returns a module which creates bindings for provider methods from the given module.
*/
public static Module forModule(Module module) {
- return forObject(module);
+ return forObject(module, false);
}
/**
* Returns a module which creates bindings for provider methods from the given object.
* This is useful notably for <a href="http://code.google.com/p/google-gin/">GIN</a>
+ *
+ * <p>This will skip bytecode generation for provider methods, since it is assumed that callers
+ * are only interested in Module metadata.
*/
public static Module forObject(Object object) {
+ return forObject(object, true);
+ }
+
+ private static Module forObject(Object object, boolean skipFastClassGeneration) {
// avoid infinite recursion, since installing a module always installs itself
if (object instanceof ProviderMethodsModule) {
return Modules.EMPTY_MODULE;
}
- return new ProviderMethodsModule(object);
+ return new ProviderMethodsModule(object, skipFastClassGeneration);
}
public synchronized void configure(Binder binder) {
@@ -221,7 +230,7 @@
}
return ProviderMethod.create(key, method, delegate, ImmutableSet.copyOf(dependencies),
- parameterProviders, scopeAnnotation);
+ parameterProviders, scopeAnnotation, skipFastClassGeneration);
}
<T> Key<T> getKey(Errors errors, TypeLiteral<T> type, Member member, Annotation[] annotations) {