Created
July 7, 2014 18:06
-
-
Save gissuebot/cbfc4f624556958a2bb2 to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 235, comment 7
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 621) | |
+++ 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 621) | |
+++ 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 621) | |
+++ 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 {} | |
Property changes on: test/com/googlecode/guice/PackageVisibilityTestModule.java | |
___________________________________________________________________ | |
Added: svn:mergeinfo | |
Index: src/com/google/inject/DefaultConstructionProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/DefaultConstructionProxyFactory.java (revision 621) | |
+++ src/com/google/inject/DefaultConstructionProxyFactory.java (working copy) | |
@@ -64,7 +64,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 621) | |
+++ 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/InjectorImpl.java | |
=================================================================== | |
--- src/com/google/inject/InjectorImpl.java (revision 621) | |
+++ src/com/google/inject/InjectorImpl.java (working copy) | |
@@ -791,7 +791,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 621) | |
+++ src/com/google/inject/ProxyFactory.java (working copy) | |
@@ -108,7 +108,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; | |
} | |
@@ -160,7 +160,7 @@ | |
final InjectionPoint injectionPoint) throws ErrorsException { | |
@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()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment