Created
July 7, 2014 18:06
-
-
Save gissuebot/290b7df1b6159d4272a4 to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 235, comment 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: test/com/googlecode/guice/BytecodeGenTest.java | |
=================================================================== | |
--- test/com/googlecode/guice/BytecodeGenTest.java (revision 609) | |
+++ test/com/googlecode/guice/BytecodeGenTest.java (working copy) | |
@@ -22,7 +22,7 @@ | |
import com.google.inject.Injector; | |
import com.google.inject.Module; | |
import static com.google.inject.matcher.Matchers.any; | |
-import com.googlecode.guice.PackageVisilibityTestModule.PublicUserOfPackagePrivate; | |
+import com.googlecode.guice.PackageVisibilityTestModule.PublicUserOfPackagePrivate; | |
import java.io.File; | |
import java.lang.ref.Reference; | |
import java.lang.ref.WeakReference; | |
@@ -54,10 +54,15 @@ | |
}; | |
public void testPackageVisibility() { | |
- Injector injector = Guice.createInjector(new PackageVisilibityTestModule()); | |
+ Injector injector = Guice.createInjector(new PackageVisibilityTestModule()); | |
injector.getInstance(PublicUserOfPackagePrivate.class); // This must pass. | |
} | |
+ public void testInterceptedPackageVisibility() { | |
+ Injector injector = Guice.createInjector(interceptorModule, new PackageVisibilityTestModule()); | |
+ injector.getInstance(PublicUserOfPackagePrivate.class); // This must pass. | |
+ } | |
+ | |
/** | |
* Custom URL classloader with basic visibility rules | |
*/ | |
Index: test/com/googlecode/guice/PackageVisilibityTestModule.java | |
=================================================================== | |
--- test/com/googlecode/guice/PackageVisilibityTestModule.java (revision 609) | |
+++ test/com/googlecode/guice/PackageVisilibityTestModule.java (working copy) | |
@@ -1,20 +0,0 @@ | |
-package com.googlecode.guice; | |
- | |
-import com.google.inject.AbstractModule; | |
-import com.google.inject.Inject; | |
- | |
-public class PackageVisilibityTestModule extends AbstractModule { | |
- | |
- @Override | |
- protected void configure() { | |
- bind(PackagePrivateInterface.class).to(PackagePrivateImpl.class); | |
- } | |
- | |
- public static class PublicUserOfPackagePrivate { | |
- @Inject public PublicUserOfPackagePrivate(PackagePrivateInterface ppi) {} | |
- } | |
- | |
- interface PackagePrivateInterface {} | |
- | |
- static class PackagePrivateImpl implements PackagePrivateInterface {} | |
-} | |
Index: test/com/googlecode/guice/PackageVisibilityTestModule.java | |
=================================================================== | |
--- test/com/googlecode/guice/PackageVisibilityTestModule.java (revision 609) | |
+++ test/com/googlecode/guice/PackageVisibilityTestModule.java (working copy) | |
@@ -3,7 +3,7 @@ | |
import com.google.inject.AbstractModule; | |
import com.google.inject.Inject; | |
-public class PackageVisilibityTestModule extends AbstractModule { | |
+public class PackageVisibilityTestModule extends AbstractModule { | |
@Override | |
protected void configure() { | |
@@ -12,6 +12,7 @@ | |
public static class PublicUserOfPackagePrivate { | |
@Inject public PublicUserOfPackagePrivate(PackagePrivateInterface ppi) {} | |
+ @Inject public void acceptPackagePrivateParameter(PackagePrivateInterface ppi) {} | |
} | |
interface PackagePrivateInterface {} | |
Index: src/com/google/inject/DefaultConstructionProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/DefaultConstructionProxyFactory.java (revision 609) | |
+++ src/com/google/inject/DefaultConstructionProxyFactory.java (working copy) | |
@@ -67,7 +67,7 @@ | |
return new ConstructionProxy<T>() { | |
Class<T> classToConstruct = constructor.getDeclaringClass(); | |
- FastClass fastClass = newFastClass(classToConstruct, Visibility.PUBLIC); | |
+ FastClass fastClass = newFastClass(classToConstruct, Visibility.forConstructor(constructor)); | |
final FastConstructor fastConstructor = fastClass.getConstructor(constructor); | |
@SuppressWarnings("unchecked") | |
Index: src/com/google/inject/internal/BytecodeGen.java | |
=================================================================== | |
--- src/com/google/inject/internal/BytecodeGen.java (revision 609) | |
+++ src/com/google/inject/internal/BytecodeGen.java (working copy) | |
@@ -17,7 +17,9 @@ | |
package com.google.inject.internal; | |
import static com.google.inject.internal.ReferenceType.WEAK; | |
+import java.lang.reflect.Constructor; | |
import java.lang.reflect.Member; | |
+import java.lang.reflect.Method; | |
import java.lang.reflect.Modifier; | |
import java.security.AccessController; | |
import java.security.PrivilegedAction; | |
@@ -78,7 +80,7 @@ | |
/** Use "-Dguice.custom.loader=false" to disable custom classloading. */ | |
static final boolean HOOK_ENABLED | |
- = "true".equals(System.getProperty("guice.custom.loader", "false")); | |
+ = "true".equals(System.getProperty("guice.custom.loader", "true")); | |
/** | |
* Weak cache of bridge class loaders that make the Guice implementation | |
@@ -183,6 +185,22 @@ | |
} | |
}; | |
+ public static Visibility forParameterTypes(Class<?>... parameterTypes) { | |
+ Visibility visibility = PUBLIC; | |
+ for (Class<?> type : parameterTypes) { | |
+ visibility = visibility.and(forType(type)); | |
+ } | |
+ return visibility; | |
+ } | |
+ | |
+ public static Visibility forConstructor(Constructor constructor) { | |
+ return forMember(constructor).and(forParameterTypes(constructor.getParameterTypes())); | |
+ } | |
+ | |
+ public static Visibility forMethod(Method method) { | |
+ return forMember(method).and(forParameterTypes(method.getParameterTypes())); | |
+ } | |
+ | |
public static Visibility forMember(Member member) { | |
return (member.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) != 0 | |
? PUBLIC | |
Index: src/com/google/inject/InjectorImpl.java | |
=================================================================== | |
--- src/com/google/inject/InjectorImpl.java (revision 609) | |
+++ src/com/google/inject/InjectorImpl.java (working copy) | |
@@ -849,7 +849,7 @@ | |
}; | |
} else { | |
FastClass fastClass = newFastClass(method.getDeclaringClass(), | |
- Visibility.forMember(method)); | |
+ Visibility.forMethod(method)); | |
final FastMethod fastMethod = fastClass.getMethod(method); | |
methodInvoker = new MethodInvoker() { | |
Index: src/com/google/inject/ProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/ProxyFactory.java (revision 609) | |
+++ src/com/google/inject/ProxyFactory.java (working copy) | |
@@ -124,7 +124,7 @@ | |
for (MethodAspect methodAspect : applicableAspects) { | |
for (MethodInterceptorsPair pair : methodInterceptorsPairs) { | |
if (methodAspect.matches(pair.method)) { | |
- visibility = visibility.and(Visibility.forMember(pair.method)); | |
+ visibility = visibility.and(Visibility.forMethod(pair.method)); | |
pair.addAll(methodAspect.interceptors()); | |
anyMatched = true; | |
} | |
@@ -174,7 +174,7 @@ | |
*/ | |
private <T> ConstructionProxy<T> createConstructionProxy(Errors errors, final Class<?> clazz, | |
final Constructor<T> standardConstructor) throws ErrorsException { | |
- FastClass fastClass = newFastClass(clazz, Visibility.PUBLIC); | |
+ FastClass fastClass = newFastClass(clazz, Visibility.forConstructor(standardConstructor)); | |
final FastConstructor fastConstructor | |
= fastClass.getConstructor(standardConstructor.getParameterTypes()); | |
final List<Parameter<?>> parameters = Parameter.forConstructor(standardConstructor, errors); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment