diff options
author | limpbizkit <limpbizkit@d779f126-a31b-0410-b53b-1d3aecad763e> | 2009-02-19 09:06:22 +0000 |
---|---|---|
committer | limpbizkit <limpbizkit@d779f126-a31b-0410-b53b-1d3aecad763e> | 2009-02-19 09:06:22 +0000 |
commit | bf0d876bb767f45c5cfbed3929e2cf6acd7d061a (patch) | |
tree | e63278fa3abfcb564b289d1105225a9bb6a419c9 | |
parent | 7c508c235dc7a3ec1c58a9f0600f6864279a29c3 (diff) | |
download | guice-bf0d876bb767f45c5cfbed3929e2cf6acd7d061a.tar.gz |
Removing all references to method interceptors from the non-AOPified Guice. This passes the full Guice test suite (other than the interceptor tests that are removed, and the tests that fail in the normal Guice build).
I still need to remove FastClass/FastMethod references. That should be substantially easier. (Although this was fairly straightforward)
I'm not sure about the variable names AOP and NO_AOP. Suggestions welcome.
git-svn-id: https://google-guice.googlecode.com/svn/trunk@851 d779f126-a31b-0410-b53b-1d3aecad763e
21 files changed, 88 insertions, 24 deletions
@@ -120,7 +120,18 @@ <taskdef name="munge" classname="MungeTask" classpath="lib/build/munge.jar"/> <mkdir dir="build/no_aop"/> <munge todir="build/no_aop"> - <fileset dir="." excludes="build/**/*"/> + <fileset dir="."> + <exclude name="build/**/*"/> + <exclude name="**/InterceptorBindingProcessor.java"/> + <exclude name="**/ProxyFactory.java"/> + <exclude name="**/InterceptorStackCallback.java"/> + <exclude name="**/InterceptorBinding.java"/> + <exclude name="**/MethodAspect.java"/> + <exclude name="**/MethodInterceptionTest.java"/> + <exclude name="**/BytecodeGenTest.java"/> + <exclude name="**/IntegrationTest.java"/> + <exclude name="**/MethodInterceptionTest.java"/> + </fileset> <arg value="-DNO_AOP" /> </munge> </target> diff --git a/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProvider2Test.java b/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProvider2Test.java index 4bae0e33..42bfaf5d 100644 --- a/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProvider2Test.java +++ b/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProvider2Test.java @@ -610,6 +610,7 @@ public class FactoryProvider2Test extends TestCase { } } + /*if[AOP]*/ public void testMethodInterceptorsOnAssistedTypes() { final AtomicInteger invocationCount = new AtomicInteger(); final MethodInterceptor interceptor = new MethodInterceptor() { @@ -635,6 +636,7 @@ public class FactoryProvider2Test extends TestCase { mustang.drive(); assertEquals(1, invocationCount.get()); } + /*end[AOP]*/ /** * Our factories aren't reusable across injectors. Although this behaviour isn't something we diff --git a/lib/build/munge.jar b/lib/build/munge.jar Binary files differindex e506709e..770cbd0e 100644 --- a/lib/build/munge.jar +++ b/lib/build/munge.jar diff --git a/src/com/google/inject/AbstractModule.java b/src/com/google/inject/AbstractModule.java index b9204eb2..60ec9e70 100644 --- a/src/com/google/inject/AbstractModule.java +++ b/src/com/google/inject/AbstractModule.java @@ -155,6 +155,7 @@ public abstract class AbstractModule implements Module { binder.requestStaticInjection(types); } + /*if[AOP]*/ /** * @see Binder#bindInterceptor(com.google.inject.matcher.Matcher, * com.google.inject.matcher.Matcher, @@ -165,6 +166,7 @@ public abstract class AbstractModule implements Module { MethodInterceptor... interceptors) { binder.bindInterceptor(classMatcher, methodMatcher, interceptors); } + /*end[AOP]*/ /** * Adds a dependency from this module to {@code key}. When the injector is diff --git a/src/com/google/inject/AbstractProcessor.java b/src/com/google/inject/AbstractProcessor.java index 9f583646..19704e92 100644 --- a/src/com/google/inject/AbstractProcessor.java +++ b/src/com/google/inject/AbstractProcessor.java @@ -76,9 +76,11 @@ abstract class AbstractProcessor implements ElementVisitor<Boolean> { return false; } + /*if[AOP]*/ public Boolean visitInterceptorBinding(InterceptorBinding interceptorBinding) { return false; } + /*end[AOP]*/ public Boolean visitScopeBinding(ScopeBinding scopeBinding) { return false; diff --git a/src/com/google/inject/ClassBindingImpl.java b/src/com/google/inject/ClassBindingImpl.java index bb500462..62d42277 100644 --- a/src/com/google/inject/ClassBindingImpl.java +++ b/src/com/google/inject/ClassBindingImpl.java @@ -70,9 +70,11 @@ class ClassBindingImpl<T> extends BindingImpl<T> implements ConstructorBinding<T return Dependency.forInjectionPoints(injectionPoints); } + /*if[AOP]*/ public Map<Method, List<MethodInterceptor>> getMethodInterceptors() { return lateBoundConstructor.constructorInjector.constructionProxy.getMethodInterceptors(); } + /*end[AOP]*/ @Override public String toString() { return new ToStringBuilder(ConstructorBinding.class) diff --git a/src/com/google/inject/ConstructionProxy.java b/src/com/google/inject/ConstructionProxy.java index cd3b4ac9..08a7960b 100644 --- a/src/com/google/inject/ConstructionProxy.java +++ b/src/com/google/inject/ConstructionProxy.java @@ -48,8 +48,10 @@ interface ConstructionProxy<T> { */ Constructor<T> getConstructor(); + /*if[AOP]*/ /** * Returns the interceptors applied to each method, in order of invocation. */ Map<Method, List<MethodInterceptor>> getMethodInterceptors(); + /*end[AOP]*/ } diff --git a/src/com/google/inject/DefaultConstructionProxyFactory.java b/src/com/google/inject/DefaultConstructionProxyFactory.java index aa1ade1d..4a41b4bc 100644 --- a/src/com/google/inject/DefaultConstructionProxyFactory.java +++ b/src/com/google/inject/DefaultConstructionProxyFactory.java @@ -43,18 +43,17 @@ class DefaultConstructionProxyFactory implements ConstructionProxyFactory { @SuppressWarnings("unchecked") // the injection point is for a constructor of T final Constructor<T> constructor = (Constructor<T>) injectionPoint.getMember(); - // We can't use FastConstructor if the constructor is non-public. - if (!Modifier.isPublic(constructor.getModifiers())) { - constructor.setAccessible(true); + /*if[AOP]*/ + // Use FastConstructor if the constructor is public. + if (Modifier.isPublic(constructor.getModifiers())) { return new ConstructionProxy<T>() { + Class<T> classToConstruct = constructor.getDeclaringClass(); + FastClass fastClass = newFastClass(classToConstruct, Visibility.forMember(constructor)); + final FastConstructor fastConstructor = fastClass.getConstructor(constructor); + + @SuppressWarnings("unchecked") public T newInstance(Object... arguments) throws InvocationTargetException { - try { - return constructor.newInstance(arguments); - } catch (InstantiationException e) { - throw new AssertionError(e); // shouldn't happen, we know this is a concrete type - } catch (IllegalAccessException e) { - throw new AssertionError(e); // a security manager is blocking us, we're hosed - } + return (T) fastConstructor.newInstance(arguments); } public InjectionPoint getInjectionPoint() { return injectionPoint; @@ -67,15 +66,21 @@ class DefaultConstructionProxyFactory implements ConstructionProxyFactory { } }; } + /*end[AOP]*/ - return new ConstructionProxy<T>() { - Class<T> classToConstruct = constructor.getDeclaringClass(); - FastClass fastClass = newFastClass(classToConstruct, Visibility.forMember(constructor)); - final FastConstructor fastConstructor = fastClass.getConstructor(constructor); + if (!Modifier.isPublic(constructor.getModifiers())) { + constructor.setAccessible(true); + } - @SuppressWarnings("unchecked") + return new ConstructionProxy<T>() { public T newInstance(Object... arguments) throws InvocationTargetException { - return (T) fastConstructor.newInstance(arguments); + try { + return constructor.newInstance(arguments); + } catch (InstantiationException e) { + throw new AssertionError(e); // shouldn't happen, we know this is a concrete type + } catch (IllegalAccessException e) { + throw new AssertionError(e); // a security manager is blocking us, we're hosed + } } public InjectionPoint getInjectionPoint() { return injectionPoint; @@ -83,9 +88,11 @@ class DefaultConstructionProxyFactory implements ConstructionProxyFactory { public Constructor<T> getConstructor() { return constructor; } + /*if[AOP]*/ public Map<Method, List<MethodInterceptor>> getMethodInterceptors() { return ImmutableMap.of(); } + /*end[AOP]*/ }; } } diff --git a/src/com/google/inject/InheritingState.java b/src/com/google/inject/InheritingState.java index 9a5d0c47..3de82cf2 100644 --- a/src/com/google/inject/InheritingState.java +++ b/src/com/google/inject/InheritingState.java @@ -40,7 +40,9 @@ class InheritingState implements State { = Collections.unmodifiableMap(explicitBindingsMutable); private final Map<Class<? extends Annotation>, Scope> scopes = Maps.newHashMap(); private final List<MatcherAndConverter> converters = Lists.newArrayList(); + /*if[AOP]*/ private final List<MethodAspect> methodAspects = Lists.newArrayList(); + /*end[AOP]*/ private final WeakKeySet blacklistedKeys = new WeakKeySet(); private final Object lock; @@ -100,6 +102,7 @@ class InheritingState implements State { return matchingConverter; } + /*if[AOP]*/ public void addMethodAspect(MethodAspect methodAspect) { methodAspects.add(methodAspect); } @@ -110,6 +113,7 @@ class InheritingState implements State { result.addAll(methodAspects); return result; } + /*end[AOP]*/ public void blacklist(Key<?> key) { parent.blacklist(key); diff --git a/src/com/google/inject/InjectorShell.java b/src/com/google/inject/InjectorShell.java index 365f1c10..051fad42 100644 --- a/src/com/google/inject/InjectorShell.java +++ b/src/com/google/inject/InjectorShell.java @@ -136,10 +136,15 @@ class InjectorShell { new MessageProcessor(errors).process(injector, elements); + /*if[AOP]*/ InterceptorBindingProcessor interceptors = new InterceptorBindingProcessor(errors); interceptors.process(injector, elements); interceptors.setupProxyFactory(injector); stopwatch.resetAndLog("Interceptors creation"); + /*end[AOP]*/ + /*if[NO_AOP] + injector.constructionProxyFactory = new DefaultConstructionProxyFactory(); + end[NO_AOP]*/ new ScopeBindingProcessor(errors).process(injector, elements); stopwatch.resetAndLog("Scopes creation"); diff --git a/src/com/google/inject/PrivateModule.java b/src/com/google/inject/PrivateModule.java index 98282e5c..13ebd852 100644 --- a/src/com/google/inject/PrivateModule.java +++ b/src/com/google/inject/PrivateModule.java @@ -179,10 +179,12 @@ public abstract class PrivateModule implements Module { binder.requestStaticInjection(types); } + /*if[AOP]*/ protected final void bindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors) { binder.bindInterceptor(classMatcher, methodMatcher, interceptors); } + /*end[AOP]*/ protected final void requireBinding(Key<?> key) { binder.getProvider(key); diff --git a/src/com/google/inject/State.java b/src/com/google/inject/State.java index e9759ac8..72d84791 100644 --- a/src/com/google/inject/State.java +++ b/src/com/google/inject/State.java @@ -71,6 +71,7 @@ interface State { return ImmutableSet.of(); } + /*if[AOP]*/ public void addMethodAspect(MethodAspect methodAspect) { throw new UnsupportedOperationException(); } @@ -78,6 +79,7 @@ interface State { public List<MethodAspect> getMethodAspects() { return ImmutableList.of(); } + /*end[AOP]*/ public void blacklist(Key<?> key) { } @@ -115,9 +117,11 @@ interface State { /** Returns all converters at this level only. */ Iterable<MatcherAndConverter> getConvertersThisLevel(); + /*if[AOP]*/ void addMethodAspect(MethodAspect methodAspect); List<MethodAspect> getMethodAspects(); + /*end[AOP]*/ /** * Forbids the corresponding injector from creating a binding to {@code key}. Child injectors diff --git a/src/com/google/inject/spi/ConstructorBinding.java b/src/com/google/inject/spi/ConstructorBinding.java index c10406fb..c70e4c5e 100644 --- a/src/com/google/inject/spi/ConstructorBinding.java +++ b/src/com/google/inject/spi/ConstructorBinding.java @@ -45,11 +45,13 @@ public interface ConstructorBinding<T> extends Binding<T>, HasDependencies { */ Set<InjectionPoint> getInjectionPoints(); + /*if[AOP]*/ /** * Returns the interceptors applied to each method, in the order that they will be applied. * * @return a possibly empty map */ Map<Method, List<MethodInterceptor>> getMethodInterceptors(); + /*end[AOP]*/ }
\ No newline at end of file diff --git a/src/com/google/inject/spi/DefaultElementVisitor.java b/src/com/google/inject/spi/DefaultElementVisitor.java index f97ac0b7..5afb7f02 100644 --- a/src/com/google/inject/spi/DefaultElementVisitor.java +++ b/src/com/google/inject/spi/DefaultElementVisitor.java @@ -45,9 +45,11 @@ public abstract class DefaultElementVisitor<V> implements ElementVisitor<V> { return visitElement(binding); } + /*if[AOP]*/ public V visitInterceptorBinding(InterceptorBinding interceptorBinding) { return visitElement(interceptorBinding); } + /*end[AOP]*/ public V visitScopeBinding(ScopeBinding scopeBinding) { return visitElement(scopeBinding); diff --git a/src/com/google/inject/spi/ElementVisitor.java b/src/com/google/inject/spi/ElementVisitor.java index c10f44cd..9f6df6c4 100644 --- a/src/com/google/inject/spi/ElementVisitor.java +++ b/src/com/google/inject/spi/ElementVisitor.java @@ -34,10 +34,12 @@ public interface ElementVisitor<V> { */ <T> V visitBinding(Binding<T> binding); + /*if[AOP]*/ /** * Visit a registration of interceptors for matching methods of matching classes. */ V visitInterceptorBinding(InterceptorBinding interceptorBinding); + /*end[AOP]*/ /** * Visit a registration of a scope annotation with the scope that implements it. diff --git a/src/com/google/inject/spi/Elements.java b/src/com/google/inject/spi/Elements.java index de3d2055..d63e626a 100644 --- a/src/com/google/inject/spi/Elements.java +++ b/src/com/google/inject/spi/Elements.java @@ -26,12 +26,12 @@ import com.google.inject.Binder; import com.google.inject.Binding; import com.google.inject.Key; import com.google.inject.Module; +import com.google.inject.PrivateBinder; import com.google.inject.PrivateModule; import com.google.inject.Provider; import com.google.inject.Scope; import com.google.inject.Stage; import com.google.inject.TypeLiteral; -import com.google.inject.PrivateBinder; import com.google.inject.binder.AnnotatedBindingBuilder; import com.google.inject.binder.AnnotatedConstantBindingBuilder; import com.google.inject.binder.AnnotatedElementBuilder; @@ -156,12 +156,14 @@ public final class Elements { this.privateElements = privateElements; } + /*if[AOP]*/ public void bindInterceptor( Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors) { elements.add(new InterceptorBinding(getSource(), classMatcher, methodMatcher, interceptors)); } + /*end[AOP]*/ public void bindScope(Class<? extends Annotation> annotationType, Scope scope) { elements.add(new ScopeBinding(getSource(), annotationType, scope)); diff --git a/src/com/google/inject/spi/ModuleWriter.java b/src/com/google/inject/spi/ModuleWriter.java index 41da5dd8..35fdd4f9 100644 --- a/src/com/google/inject/spi/ModuleWriter.java +++ b/src/com/google/inject/spi/ModuleWriter.java @@ -23,9 +23,9 @@ import com.google.inject.Binder; import com.google.inject.Binding; import com.google.inject.Key; import com.google.inject.Module; +import com.google.inject.PrivateBinder; import com.google.inject.Provider; import com.google.inject.Scope; -import com.google.inject.PrivateBinder; import com.google.inject.binder.ScopedBindingBuilder; import java.lang.annotation.Annotation; import java.util.List; @@ -67,10 +67,12 @@ public class ModuleWriter { return null; } + /*if[AOP]*/ public Void visitInterceptorBinding(InterceptorBinding element) { writeBindInterceptor(binder, element); return null; } + /*end[AOP]*/ public Void visitScopeBinding(ScopeBinding element) { writeBindScope(binder, element); @@ -117,12 +119,14 @@ public class ModuleWriter { binder.addError(element); } + /*if[AOP]*/ protected void writeBindInterceptor(Binder binder, InterceptorBinding element) { List<MethodInterceptor> interceptors = element.getInterceptors(); binder.withSource(element.getSource()).bindInterceptor( element.getClassMatcher(), element.getMethodMatcher(), interceptors.toArray(new MethodInterceptor[interceptors.size()])); } + /*end[AOP]*/ protected void writeBindScope(Binder binder, ScopeBinding element) { binder.withSource(element.getSource()).bindScope( diff --git a/test/com/google/inject/AllTests.java b/test/com/google/inject/AllTests.java index f3f2f61b..0031f4af 100644 --- a/test/com/google/inject/AllTests.java +++ b/test/com/google/inject/AllTests.java @@ -17,10 +17,10 @@ package com.google.inject; import com.google.inject.internal.FinalizableReferenceQueueTest; +import com.google.inject.internal.Jsr166HashMapTest; import com.google.inject.internal.LineNumbersTest; import com.google.inject.internal.MapMakerTestSuite; import com.google.inject.internal.UniqueAnnotationsTest; -import com.google.inject.internal.Jsr166HashMapTest; import com.google.inject.matcher.MatcherTest; import com.google.inject.name.NamesTest; import com.google.inject.spi.ElementsTest; @@ -59,10 +59,8 @@ public class AllTests { suite.addTestSuite(ImplicitBindingTest.class); suite.addTestSuite(InjectionPointTest.class); suite.addTestSuite(InjectorTest.class); - suite.addTestSuite(IntegrationTest.class); suite.addTestSuite(KeyTest.class); suite.addTestSuite(LoggerInjectionTest.class); - suite.addTestSuite(MethodInterceptionTest.class); suite.addTestSuite(ModuleTest.class); suite.addTestSuite(ModulesTest.class); suite.addTestSuite(NullableInjectionPointTest.class); @@ -97,7 +95,6 @@ public class AllTests { suite.addTestSuite(Jsr166HashMapTest.class); suite.addTestSuite(TypesTest.class); suite.addTestSuite(UniqueAnnotationsTest.class); - suite.addTestSuite(BytecodeGenTest.class); // matcher suite.addTestSuite(MatcherTest.class); @@ -111,6 +108,12 @@ public class AllTests { // util suite.addTestSuite(ProvidersTest.class); + /*if[AOP]*/ + suite.addTestSuite(IntegrationTest.class); + suite.addTestSuite(MethodInterceptionTest.class); + suite.addTestSuite(BytecodeGenTest.class); + /*end[AOP]*/ + return suite; } } diff --git a/test/com/google/inject/ParentInjectorTest.java b/test/com/google/inject/ParentInjectorTest.java index a04d2953..051940d4 100644 --- a/test/com/google/inject/ParentInjectorTest.java +++ b/test/com/google/inject/ParentInjectorTest.java @@ -110,6 +110,7 @@ public class ParentInjectorTest extends TestCase { assertSame(child.getInstance(A.class), child.getInstance(A.class)); } + /*if[AOP]*/ public void testInterceptorsInherited() { Injector parent = Guice.createInjector(new AbstractModule() { protected void configure() { @@ -126,6 +127,7 @@ public class ParentInjectorTest extends TestCase { assertNull(child.getInstance(C.class).interceptedMethod()); } + /*end[AOP]*/ public void testTypeConvertersInherited() { Injector parent = Guice.createInjector(bindListConverterModule); diff --git a/test/com/google/inject/internal/LineNumbersTest.java b/test/com/google/inject/internal/LineNumbersTest.java index efd2564a..5886196f 100644 --- a/test/com/google/inject/internal/LineNumbersTest.java +++ b/test/com/google/inject/internal/LineNumbersTest.java @@ -32,6 +32,7 @@ import org.aopalliance.intercept.MethodInvocation; */ public class LineNumbersTest extends TestCase { + /*if[AOP]*/ public void testCanHandleLineNumbersForGuiceGeneratedClasses() { try { Guice.createInjector(new AbstractModule() { @@ -54,6 +55,7 @@ public class LineNumbersTest extends TestCase { "at " + LineNumbersTest.class.getName(), ".configure(LineNumbersTest.java:"); } } + /*end[AOP]*/ static class A { @Inject A(B b) {} diff --git a/test/com/google/inject/spi/ElementsTest.java b/test/com/google/inject/spi/ElementsTest.java index d901182a..d2bd3cb5 100644 --- a/test/com/google/inject/spi/ElementsTest.java +++ b/test/com/google/inject/spi/ElementsTest.java @@ -23,12 +23,12 @@ import com.google.inject.Binding; import com.google.inject.BindingAnnotation; import com.google.inject.Key; import com.google.inject.Module; +import com.google.inject.PrivateBinder; import com.google.inject.Provider; import com.google.inject.Scope; import com.google.inject.Scopes; import com.google.inject.Singleton; import com.google.inject.TypeLiteral; -import com.google.inject.PrivateBinder; import com.google.inject.binder.AnnotatedBindingBuilder; import com.google.inject.binder.AnnotatedConstantBindingBuilder; import com.google.inject.binder.ConstantBindingBuilder; @@ -539,6 +539,7 @@ public class ElementsTest extends TestCase { ); } + /*if[AOP]*/ public void testBindIntercepor() { final Matcher<Class> classMatcher = Matchers.subclassesOf(List.class); final Matcher<Object> methodMatcher = Matchers.any(); @@ -565,6 +566,7 @@ public class ElementsTest extends TestCase { } ); } + /*end[AOP]*/ public void testBindScope() { checkModule( |