Created
July 7, 2014 18:06
-
-
Save gissuebot/94317f28b0bf7470b830 to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 235, comment 8
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: src/com/google/inject/DefaultConstructionProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/DefaultConstructionProxyFactory.java (revision 661) | |
+++ src/com/google/inject/DefaultConstructionProxyFactory.java (working copy) | |
@@ -62,7 +62,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 661) | |
+++ 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,23 @@ | |
} | |
}; | |
+ public static Visibility forParameterTypes(Class<?>... parameterTypes) { | |
+ for (Class<?> type : parameterTypes) { | |
+ if (forType(type) == SAME_PACKAGE) { | |
+ return SAME_PACKAGE; | |
+ } | |
+ } | |
+ return PUBLIC; | |
+ } | |
+ | |
+ 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/ProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/ProxyFactory.java (revision 661) | |
+++ src/com/google/inject/ProxyFactory.java (working copy) | |
@@ -103,7 +103,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; | |
} | |
@@ -154,7 +154,7 @@ | |
final InjectionPoint injectionPoint) { | |
@SuppressWarnings("unchecked") // injection point's member must be a Constructor<T> | |
final Constructor<T> standardConstructor = (Constructor<T>) injectionPoint.getMember(); | |
- FastClass fastClass = newFastClass(clazz, Visibility.PUBLIC); | |
+ FastClass fastClass = newFastClass(clazz, Visibility.forConstructor(standardConstructor)); | |
final FastConstructor fastConstructor | |
= fastClass.getConstructor(standardConstructor.getParameterTypes()); | |
Index: src/com/google/inject/SingleMethodInjector.java | |
=================================================================== | |
--- src/com/google/inject/SingleMethodInjector.java (revision 661) | |
+++ src/com/google/inject/SingleMethodInjector.java (working copy) | |
@@ -54,7 +54,7 @@ | |
}; | |
} else { | |
FastClass fastClass = BytecodeGen.newFastClass( | |
- method.getDeclaringClass(), Visibility.forMember(method)); | |
+ method.getDeclaringClass(), Visibility.forMethod(method)); | |
final FastMethod fastMethod = fastClass.getMethod(method); | |
methodInvoker = new MethodInvoker() { | |
@@ -92,4 +92,4 @@ | |
errors.withSource(injectionPoint).errorInjectingMethod(cause); | |
} | |
} | |
-} | |
\ No newline at end of file | |
+} | |
Index: test/com/googlecode/guice/BytecodeGenTest.java | |
=================================================================== | |
--- test/com/googlecode/guice/BytecodeGenTest.java (revision 661) | |
+++ 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 661) | |
+++ 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 0) | |
+++ test/com/googlecode/guice/PackageVisibilityTestModule.java (revision 0) | |
@@ -0,0 +1,21 @@ | |
+package com.googlecode.guice; | |
+ | |
+import com.google.inject.AbstractModule; | |
+import com.google.inject.Inject; | |
+ | |
+public class PackageVisibilityTestModule extends AbstractModule { | |
+ | |
+ @Override | |
+ protected void configure() { | |
+ bind(PackagePrivateInterface.class).to(PackagePrivateImpl.class); | |
+ } | |
+ | |
+ public static class PublicUserOfPackagePrivate { | |
+ @Inject public PublicUserOfPackagePrivate(PackagePrivateInterface ppi) {} | |
+ @Inject public void acceptPackagePrivateParameter(PackagePrivateInterface ppi) {} | |
+ } | |
+ | |
+ interface PackagePrivateInterface {} | |
+ | |
+ static class PackagePrivateImpl implements PackagePrivateInterface {} | |
+} | |
Property changes on: test/com/googlecode/guice/PackageVisibilityTestModule.java | |
___________________________________________________________________ | |
Added: svn:eol-style | |
+ native | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment