diff options
Diffstat (limited to 'weaver/testsrc')
15 files changed, 760 insertions, 791 deletions
diff --git a/weaver/testsrc/BcweaverModuleTests15.java b/weaver/testsrc/BcweaverModuleTests15.java index dce28d325..4ca66cc11 100644 --- a/weaver/testsrc/BcweaverModuleTests15.java +++ b/weaver/testsrc/BcweaverModuleTests15.java @@ -20,6 +20,7 @@ import org.aspectj.weaver.TypeVariableReferenceTypeTestCase; import org.aspectj.weaver.TypeVariableTestCase; import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXTestCase; import org.aspectj.weaver.patterns.WildTypePatternResolutionTestCase; +import org.aspectj.weaver.tools.Java15PointcutExpressionTest; public class BcweaverModuleTests15 extends TestCase { public static Test suite() { @@ -31,6 +32,7 @@ public class BcweaverModuleTests15 extends TestCase { suite.addTestSuite(MemberTestCase15.class); suite.addTestSuite(BcelGenericSignatureToTypeXTestCase.class); suite.addTestSuite(WildTypePatternResolutionTestCase.class); + suite.addTestSuite(Java15PointcutExpressionTest.class); return suite; } diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java index ddb00a318..1e6176714 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java @@ -70,31 +70,6 @@ public class AndOrNotTestCase extends TestCase { } - public void testJoinPointMatch() { - Pointcut foo = makePointcut("this(org.aspectj.weaver.patterns.AndOrNotTestCase.Foo)").resolve(); - Pointcut bar = makePointcut("this(org.aspectj.weaver.patterns.AndOrNotTestCase.Bar)").resolve(); - Pointcut c = makePointcut("this(org.aspectj.weaver.patterns.AndOrNotTestCase.C)").resolve(); - - Factory f = new Factory("AndOrNotTestCase.java",AndOrNotTestCase.class); - - Signature methodSig = f.makeMethodSig("void aMethod()"); - JoinPoint.StaticPart jpsp = f.makeSJP(JoinPoint.METHOD_EXECUTION,methodSig,1); - JoinPoint jp = Factory.makeJP(jpsp,new Foo(),new Foo()); - - checkMatches(new AndPointcut(foo,bar),jp,null,FuzzyBoolean.NO); - checkMatches(new AndPointcut(foo,foo),jp,null,FuzzyBoolean.YES); - checkMatches(new AndPointcut(bar,foo),jp,null,FuzzyBoolean.NO); - checkMatches(new AndPointcut(bar,c),jp,null,FuzzyBoolean.NO); - - checkMatches(new OrPointcut(foo,bar),jp,null,FuzzyBoolean.YES); - checkMatches(new OrPointcut(foo,foo),jp,null,FuzzyBoolean.YES); - checkMatches(new OrPointcut(bar,foo),jp,null,FuzzyBoolean.YES); - checkMatches(new OrPointcut(bar,c),jp,null,FuzzyBoolean.NO); - - checkMatches(new NotPointcut(foo),jp,null,FuzzyBoolean.NO); - checkMatches(new NotPointcut(bar),jp,null,FuzzyBoolean.YES); - } - private Pointcut makePointcut(String pattern) { return new PatternParser(pattern).parsePointcut(); } @@ -104,32 +79,6 @@ public class AndOrNotTestCase extends TestCase { checkSerialization(pattern); } - private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { - assertEquals(expected,p.match(jp,jpsp)); - } - -// private void checkMatch(Pointcut p, Signature[] matches, boolean shouldMatch) { -// for (int i=0; i<matches.length; i++) { -// boolean result = p.matches(matches[i]); -// String msg = "matches " + p + " to " + matches[i] + " expected "; -// if (shouldMatch) { -// assertTrue(msg + shouldMatch, result); -// } else { -// assertTrue(msg + shouldMatch, !result); -// } -// } -// } -// -// public void testSerialization() throws IOException { -// String[] patterns = new String[] { -// "public * *(..)", "void *.foo(A, B)", "A b()" -// }; -// -// for (int i=0, len=patterns.length; i < len; i++) { -// checkSerialization(patterns[i]); -// } -// } - /** * Method checkSerialization. * @param string diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java index fd1bc3700..31313556f 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java @@ -10,11 +10,16 @@ *******************************************************************************/ package org.aspectj.weaver.patterns; +import java.lang.reflect.Method; + import junit.framework.TestCase; -import org.aspectj.lang.JoinPoint; -import org.aspectj.runtime.reflect.Factory; -import org.aspectj.util.FuzzyBoolean; +import org.aspectj.util.LangUtil; +import org.aspectj.weaver.tools.JoinPointMatch; +import org.aspectj.weaver.tools.PointcutExpression; +import org.aspectj.weaver.tools.PointcutParameter; +import org.aspectj.weaver.tools.PointcutParser; +import org.aspectj.weaver.tools.ShadowMatch; /** * @author colyer @@ -22,92 +27,135 @@ import org.aspectj.util.FuzzyBoolean; */ public class ArgsTestCase extends TestCase { - Pointcut wildcardArgs; - Pointcut oneA; - Pointcut oneAandaC; - Pointcut BthenAnything; - Pointcut singleArg; + PointcutExpression wildcardArgs; + PointcutExpression oneA; + PointcutExpression oneAandaC; + PointcutExpression BthenAnything; + PointcutExpression singleArg; - public void testMatchJP() { - Factory f = new Factory("ArgsTestCase.java",ArgsTestCase.A.class); - - JoinPoint.StaticPart jpsp1 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {A.class},new String[] {"a"},new Class[] {},null) ,1); - JoinPoint.StaticPart jpsp2 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {B.class},new String[] {"b"},new Class[] {},null),1); - JoinPoint.StaticPart jpsp3 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {A.class,C.class},new String[] {"a","c"},new Class[] {},null),1); - JoinPoint.StaticPart jpsp4 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {A.class,A.class},new String[] {"a","a2"},new Class[] {},null),1); - JoinPoint oneAArg = Factory.makeJP(jpsp1,new A(),new A(),new A()); - JoinPoint oneBArg = Factory.makeJP(jpsp2,new A(), new A(), new B()); - JoinPoint acArgs = Factory.makeJP(jpsp3,new A(), new A(), new A(), new C()); - JoinPoint baArgs = Factory.makeJP(jpsp4,new A(), new A(), new B(), new A()); + public void testMatchJP() throws Exception { - checkMatches(wildcardArgs,oneAArg,null,FuzzyBoolean.YES); - checkMatches(wildcardArgs,oneBArg,null,FuzzyBoolean.YES); - checkMatches(wildcardArgs,acArgs,null,FuzzyBoolean.YES); - checkMatches(wildcardArgs,baArgs,null,FuzzyBoolean.YES); + Method oneAArg = B.class.getMethod("x", new Class[] {A.class}); + Method oneBArg = B.class.getMethod("y",new Class[] {B.class}); + Method acArgs = C.class.getMethod("z",new Class[] {A.class,C.class}); + Method baArgs = C.class.getMethod("t",new Class[] {B.class, A.class}); - checkMatches(oneA,oneAArg,null,FuzzyBoolean.YES); - checkMatches(oneA,oneBArg,null,FuzzyBoolean.YES); - checkMatches(oneA,acArgs,null,FuzzyBoolean.NO); - checkMatches(oneA,baArgs,null,FuzzyBoolean.NO); + checkMatches(wildcardArgs.matchesMethodExecution(oneAArg),new B(), new B(), new Object[] {new A()} ); + checkMatches(wildcardArgs.matchesMethodExecution(oneBArg),new B(), new B(), new Object[] {new B()} ); + checkMatches(wildcardArgs.matchesMethodExecution(acArgs),new C(), new C(), new Object[] {new B(), new C()} ); + checkMatches(wildcardArgs.matchesMethodExecution(baArgs),new C(), new C(), new Object[] {new B(), new B()} ); - checkMatches(oneAandaC,oneAArg,null,FuzzyBoolean.NO); - checkMatches(oneAandaC,oneBArg,null,FuzzyBoolean.NO); - checkMatches(oneAandaC,acArgs,null,FuzzyBoolean.YES); - checkMatches(oneAandaC,baArgs,null,FuzzyBoolean.NO); - - checkMatches(BthenAnything,oneAArg,null,FuzzyBoolean.NO); - checkMatches(BthenAnything,oneBArg,null,FuzzyBoolean.YES); - checkMatches(BthenAnything,acArgs,null,FuzzyBoolean.NO); - checkMatches(BthenAnything,baArgs,null,FuzzyBoolean.YES); + checkMatches(oneA.matchesMethodExecution(oneAArg),new B(), new B(), new Object[] {new A()} ); + checkMatches(oneA.matchesMethodExecution(oneBArg),new B(), new B(), new Object[] {new B()} ); + checkNoMatch(oneA.matchesMethodExecution(acArgs),new C(), new C(), new Object[] {new B(), new C()}); + checkNoMatch(oneA.matchesMethodExecution(baArgs),new C(), new C(), new Object[] {new B(), new B()}); + + checkNoMatch(oneAandaC.matchesMethodExecution(oneAArg),new B(), new B(), new Object[] {new A()} ); + checkNoMatch(oneAandaC.matchesMethodExecution(oneBArg),new B(), new B(), new Object[] {new B()} ); + checkMatches(oneAandaC.matchesMethodExecution(acArgs),new C(), new C(), new Object[] {new B(), new C()}); + checkNoMatch(oneAandaC.matchesMethodExecution(baArgs),new C(), new C(), new Object[] {new B(), new B()}); - checkMatches(singleArg,oneAArg,null,FuzzyBoolean.YES); - checkMatches(singleArg,oneBArg,null,FuzzyBoolean.YES); - checkMatches(singleArg,acArgs,null,FuzzyBoolean.NO); - checkMatches(singleArg,baArgs,null,FuzzyBoolean.NO); + checkNoMatch(BthenAnything.matchesMethodExecution(oneAArg),new B(), new B(), new Object[] {new A()} ); + checkMatches(BthenAnything.matchesMethodExecution(oneBArg),new B(), new B(), new Object[] {new B()} ); + checkNoMatch(BthenAnything.matchesMethodExecution(acArgs),new C(), new C(), new Object[] {new A(), new C()}); + checkMatches(BthenAnything.matchesMethodExecution(baArgs),new C(), new C(), new Object[] {new B(), new B()}); + + checkMatches(singleArg.matchesMethodExecution(oneAArg),new B(), new B(), new Object[] {new A()} ); + checkMatches(singleArg.matchesMethodExecution(oneBArg),new B(), new B(), new Object[] {new B()} ); + checkNoMatch(singleArg.matchesMethodExecution(acArgs),new C(), new C(), new Object[] {new B(), new C()}); + checkNoMatch(singleArg.matchesMethodExecution(baArgs),new C(), new C(), new Object[] {new B(), new B()}); + + } + + public void testBinding() throws Exception { + + PointcutParser parser = new PointcutParser(); + PointcutParameter a = parser.createPointcutParameter("a",A.class); + A theParameter = new A(); + PointcutExpression bindA = parser.parsePointcutExpression("args(a,*)",A.class,new PointcutParameter[] {a}); + Method acArgs = C.class.getMethod("z",new Class[] {A.class,C.class}); + ShadowMatch sMatch = bindA.matchesMethodExecution(acArgs); + JoinPointMatch jpMatch = sMatch.matchesJoinPoint(new A(),new A(), new Object[] {theParameter}); + assertTrue("should match", jpMatch.matches()); + PointcutParameter[] bindings = jpMatch.getParameterBindings(); + assertTrue("one parameter",bindings.length == 1); + assertEquals("should be bound to the arg value",theParameter, bindings[0].getBinding()); + + PointcutParameter c = parser.createPointcutParameter("c", C.class); + C cParameter = new C(); + PointcutExpression bindAandC = parser.parsePointcutExpression("args(a,c)",A.class,new PointcutParameter[] {a,c}); + sMatch = bindAandC.matchesMethodExecution(acArgs); + jpMatch = sMatch.matchesJoinPoint(new A(),new A(), new Object[] {theParameter,cParameter}); + assertTrue("should match", jpMatch.matches()); + bindings = jpMatch.getParameterBindings(); + assertTrue("two parameters",bindings.length == 2); + assertEquals("should be bound to the a arg value",theParameter, bindings[0].getBinding()); + assertEquals("should be bound to the c arg value",cParameter, bindings[1].getBinding()); + assertEquals("a",bindings[0].getName()); + assertEquals("c",bindings[1].getName()); } - public void testMatchJPWithPrimitiveTypes() { + public void testMatchJPWithPrimitiveTypes() throws Exception { try { - Factory f = new Factory("ArgsTestCase.java",ArgsTestCase.A.class); - - Pointcut oneInt = new PatternParser("args(int)").parsePointcut().resolve(); - Pointcut oneInteger = new PatternParser("args(Integer)").parsePointcut().resolve(); - JoinPoint.StaticPart oneIntjp = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {int.class},new String[] {"i"},new Class[] {},null) ,1); - JoinPoint.StaticPart oneIntegerjp = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {Integer.class},new String[] {"i"},new Class[] {},null),1); + PointcutParser parser = new PointcutParser(); + PointcutExpression oneInt = parser.parsePointcutExpression("args(int)"); + PointcutExpression oneInteger = parser.parsePointcutExpression("args(Integer)"); - JoinPoint oneIntArg = Factory.makeJP(oneIntjp,new A(),new A(),new Integer(3)); - JoinPoint oneIntegerArg = Factory.makeJP(oneIntegerjp,new A(), new A(), new Integer(7)); + Method oneIntM = A.class.getMethod("anInt",new Class[] {int.class}); + Method oneIntegerM = A.class.getMethod("anInteger",new Class[] {Integer.class}); - checkMatches(oneInt,oneIntArg,null,FuzzyBoolean.YES); - checkMatches(oneInt,oneIntegerArg,null,FuzzyBoolean.NO); - checkMatches(oneInteger,oneIntArg,null,FuzzyBoolean.NO); - checkMatches(oneInteger,oneIntegerArg,null,FuzzyBoolean.YES); + if (LangUtil.is15VMOrGreater()) { + checkMatches(oneInt.matchesMethodExecution(oneIntM),new A(), new A(), new Object[] {new Integer(5)}); + checkMatches(oneInt.matchesMethodExecution(oneIntegerM),new A(), new A(), new Object[] {new Integer(5)}); + checkMatches(oneInteger.matchesMethodExecution(oneIntM),new A(), new A(), new Object[] {new Integer(5)}); + checkMatches(oneInteger.matchesMethodExecution(oneIntegerM),new A(), new A(), new Object[] {new Integer(5)}); + } else { + checkMatches(oneInt.matchesMethodExecution(oneIntM),new A(), new A(), new Object[] {new Integer(5)}); + checkNoMatch(oneInt.matchesMethodExecution(oneIntegerM),new A(), new A(), new Object[] {new Integer(5)}); + checkNoMatch(oneInteger.matchesMethodExecution(oneIntM),new A(), new A(), new Object[] {new Integer(5)}); + checkMatches(oneInteger.matchesMethodExecution(oneIntegerM),new A(), new A(), new Object[] {new Integer(5)}); + } } catch( Exception ex) { fail("Unexpected exception " + ex); } } + + private void checkMatches(ShadowMatch sMatch,Object thisOjb, Object targetObj, Object[] args) { + assertTrue("match expected",sMatch.matchesJoinPoint(thisOjb, targetObj, args).matches()); + } - private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { - assertEquals(expected,p.match(jp,jpsp)); + private void checkNoMatch(ShadowMatch sMatch,Object thisOjb, Object targetObj, Object[] args) { + assertFalse("no match expected",sMatch.matchesJoinPoint(thisOjb, targetObj, args).matches()); } - private static class A {}; - private static class B extends A {}; - private static class C {}; + private static class A { + public void anInt(int i) {} + public void anInteger(Integer i) {} + + }; + private static class B extends A { + public void x(A a) {} + public void y(B b) {} + }; + private static class C { + public void z(A a, C c) {} + public void t(B b, A a) {} + }; /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); - wildcardArgs = new PatternParser("args(..)").parsePointcut().resolve(); - oneA = new PatternParser("args(org.aspectj.weaver.patterns.ArgsTestCase.A)").parsePointcut().resolve(); - oneAandaC = new PatternParser("args(org.aspectj.weaver.patterns.ArgsTestCase.A,org.aspectj.weaver.patterns.ArgsTestCase.C)").parsePointcut().resolve(); - BthenAnything = new PatternParser("args(org.aspectj.weaver.patterns.ArgsTestCase.B,..)").parsePointcut().resolve(); - singleArg = new PatternParser("args(*)").parsePointcut().resolve(); + PointcutParser parser = new PointcutParser(); + wildcardArgs = parser.parsePointcutExpression("args(..)"); + oneA = parser.parsePointcutExpression("args(org.aspectj.weaver.patterns.ArgsTestCase.A)"); + oneAandaC = parser.parsePointcutExpression("args(org.aspectj.weaver.patterns.ArgsTestCase.A,org.aspectj.weaver.patterns.ArgsTestCase.C)"); + BthenAnything = parser.parsePointcutExpression("args(org.aspectj.weaver.patterns.ArgsTestCase.B,..)"); + singleArg = parser.parsePointcutExpression("args(*)"); } } diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/HandlerTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/HandlerTestCase.java deleted file mode 100644 index 9238f8bc9..000000000 --- a/weaver/testsrc/org/aspectj/weaver/patterns/HandlerTestCase.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.weaver.patterns; - -import java.io.IOException; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.runtime.reflect.Factory; -import org.aspectj.util.FuzzyBoolean; - -import junit.framework.TestCase; - - -public class HandlerTestCase extends TestCase { - - private Pointcut hEx; - private Pointcut hExPlus; - private Pointcut hIOEx; - - public void testHandlerMatch() { - Factory f = new Factory("HandlerTestCase.java",HandlerTestCase.class); - - JoinPoint.StaticPart jpsp1 = f.makeSJP(JoinPoint.EXCEPTION_HANDLER,f.makeCatchClauseSig(HandlerTestCase.class,Exception.class,"ex"),1); - JoinPoint ex = Factory.makeJP(jpsp1,this,this,new Exception()); - JoinPoint ioex = Factory.makeJP(jpsp1,this,this,new IOException()); - JoinPoint myex = Factory.makeJP(jpsp1,this,this,new MyException()); - - checkMatches(hEx,ex,null,FuzzyBoolean.YES); - checkMatches(hEx,ioex,null,FuzzyBoolean.NO); - checkMatches(hEx,myex,null,FuzzyBoolean.NO); - - checkMatches(hExPlus,ex,null,FuzzyBoolean.YES); - checkMatches(hExPlus,ioex,null,FuzzyBoolean.YES); - checkMatches(hExPlus,myex,null,FuzzyBoolean.YES); - - checkMatches(hIOEx,ex,null,FuzzyBoolean.NO); - checkMatches(hIOEx,ioex,null,FuzzyBoolean.YES); - checkMatches(hIOEx,myex,null,FuzzyBoolean.NO); - - } - - private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { - assertEquals(expected,p.match(jp,jpsp)); - } - - private static class MyException extends Exception {} - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - hEx = new PatternParser("handler(Exception)").parsePointcut().resolve(); - hExPlus = new PatternParser("handler(Exception+)").parsePointcut().resolve(); - hIOEx = new PatternParser("handler(java.io.IOException)").parsePointcut().resolve(); - } -} diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/KindedTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/KindedTestCase.java deleted file mode 100644 index 4313c10d7..000000000 --- a/weaver/testsrc/org/aspectj/weaver/patterns/KindedTestCase.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.weaver.patterns; - -import java.lang.reflect.Modifier; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.runtime.reflect.Factory; -import org.aspectj.util.FuzzyBoolean; - -import junit.framework.TestCase; - -/** - * @author colyer - * - */ -public class KindedTestCase extends TestCase { - - Pointcut callpc; - Pointcut exepc; - Pointcut exepcplus; - Pointcut exepcCons; - Pointcut adviceexepc; - Pointcut initpc; - Pointcut preinitpc; - Pointcut staticinitpc; - Pointcut getpc; - Pointcut setpc; - - public void testKindedMatch() { - Factory f = new Factory("KindedTestCase.java",KindedTestCase.class); - - // JoinPoints to match against... - JoinPoint.StaticPart calljp1 = f.makeSJP(JoinPoint.METHOD_CALL,f.makeMethodSig(0,"main",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],String.class),1); - JoinPoint.StaticPart calljp2 = f.makeSJP(JoinPoint.METHOD_CALL,f.makeMethodSig(0,"sayHi",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],String.class),1); - JoinPoint.StaticPart exejp1 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"main",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],String.class),1); - JoinPoint.StaticPart exejp2 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"sayHi",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],void.class),1); - JoinPoint.StaticPart execonsjp1 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,Hello.class,new Class[0],new String[0],new Class[0]),1); - JoinPoint.StaticPart execonsjp2 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,String.class,new Class[] {String.class},new String[]{"s"},new Class[0]),1); - JoinPoint.StaticPart initjp1 = f.makeSJP(JoinPoint.INITIALIZATION,f.makeConstructorSig(0,Hello.class,new Class[0],new String[0],new Class[0]),1); - JoinPoint.StaticPart initjp2 = f.makeSJP(JoinPoint.PREINTIALIZATION,f.makeConstructorSig(0,Hello.class,new Class[]{int.class, int.class},new String[]{"a","b"},new Class[0]),1); - JoinPoint.StaticPart initjp3 = f.makeSJP(JoinPoint.PREINTIALIZATION,f.makeConstructorSig(0,Hello.class,new Class[]{Integer.class, Integer.class},new String[]{"a","b"},new Class[0]),1); - JoinPoint.StaticPart sinitjp1 = f.makeSJP(JoinPoint.STATICINITIALIZATION,f.makeInitializerSig(Modifier.STATIC,Hello.class),1); - JoinPoint.StaticPart sinitjp2 = f.makeSJP(JoinPoint.STATICINITIALIZATION,f.makeInitializerSig(Modifier.STATIC,String.class),1); - JoinPoint.StaticPart getjp1 = f.makeSJP(JoinPoint.FIELD_GET,f.makeFieldSig(0,"x",Hello.class,int.class),1); - JoinPoint.StaticPart getjp2 = f.makeSJP(JoinPoint.FIELD_GET,f.makeFieldSig(0,"y",String.class,String.class),1); - JoinPoint.StaticPart setjp1 = f.makeSJP(JoinPoint.FIELD_SET,f.makeFieldSig(0,"x",Hello.class,int.class),1); - JoinPoint.StaticPart setjp2 = f.makeSJP(JoinPoint.FIELD_SET,f.makeFieldSig(0,"y",String.class,String.class),1); - JoinPoint.StaticPart advjp = f.makeSJP(JoinPoint.ADVICE_EXECUTION,f.makeAdviceSig(0,"foo",Hello.class,new Class[0],new String[0],new Class[0],void.class),1); - - checkMatches(callpc,calljp1,FuzzyBoolean.YES); - checkMatches(callpc,calljp2,FuzzyBoolean.NO); - checkMatches(callpc,exejp1,FuzzyBoolean.NO); - checkMatches(exepc,exejp1,FuzzyBoolean.NO); - checkMatches(exepc,exejp2,FuzzyBoolean.YES); - checkMatches(exepcplus,exejp1,FuzzyBoolean.NO); - checkMatches(exepcplus,exejp2,FuzzyBoolean.YES); - checkMatches(exepcCons,execonsjp1,FuzzyBoolean.YES); - checkMatches(exepcCons,execonsjp2,FuzzyBoolean.NO); - checkMatches(exepcCons,exejp1,FuzzyBoolean.NO); - checkMatches(initpc,initjp1,FuzzyBoolean.YES); - checkMatches(initpc,initjp2,FuzzyBoolean.NO); - checkMatches(preinitpc,initjp1,FuzzyBoolean.NO); - checkMatches(preinitpc,initjp2,FuzzyBoolean.YES); - checkMatches(preinitpc,initjp3,FuzzyBoolean.NO); - checkMatches(staticinitpc,sinitjp1,FuzzyBoolean.YES); - checkMatches(staticinitpc,sinitjp2,FuzzyBoolean.NO); - checkMatches(getpc,getjp1,FuzzyBoolean.YES); - checkMatches(getpc,getjp2,FuzzyBoolean.YES); - checkMatches(setpc,setjp1,FuzzyBoolean.YES); - checkMatches(setpc,setjp2,FuzzyBoolean.NO); - checkMatches(adviceexepc,advjp,FuzzyBoolean.YES); - } - - private void checkMatches(Pointcut p, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { - assertEquals(expected,p.match(jpsp)); - } - - protected void setUp() throws Exception { - super.setUp(); - callpc = new PatternParser("call(* main(..))").parsePointcut().resolve(); - exepc = new PatternParser("execution(void org.aspectj.weaver.patterns.KindedTestCase.Hello.sayHi(String))").parsePointcut().resolve(); - exepcplus = new PatternParser("execution(void Object+.sayHi(String))").parsePointcut().resolve(); - exepcCons = new PatternParser("execution(org.aspectj.weaver.patterns.KindedTestCase.Hello.new(..))").parsePointcut().resolve(); - initpc = new PatternParser("initialization(new(..))").parsePointcut().resolve(); - preinitpc = new PatternParser("preinitialization(*..H*.new(int,int))").parsePointcut().resolve(); - staticinitpc = new PatternParser("staticinitialization(org.aspectj.weaver.patterns.KindedTestCase.Hello)").parsePointcut().resolve(); - getpc = new PatternParser("get(* *)").parsePointcut().resolve(); - setpc = new PatternParser("set(int x)").parsePointcut().resolve(); - adviceexepc = new PatternParser("adviceexecution()").parsePointcut().resolve(); - } - - private static class Hello {}; -} diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/PatternsTests.java b/weaver/testsrc/org/aspectj/weaver/patterns/PatternsTests.java index db80087ef..171fc4044 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/PatternsTests.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/PatternsTests.java @@ -32,11 +32,7 @@ public class PatternsTests extends TestCase { suite.addTestSuite(TypePatternListTestCase.class); suite.addTestSuite(TypePatternTestCase.class); suite.addTestSuite(WithinTestCase.class); - suite.addTestSuite(PointcutTestCase.class); suite.addTestSuite(ArgsTestCase.class); - suite.addTestSuite(HandlerTestCase.class); - suite.addTestSuite(KindedTestCase.class); - suite.addTestSuite(WithinCodeTestCase.class); suite.addTestSuite(AnnotationPatternTestCase.class); suite.addTestSuite(AnnotationPatternMatchingTestCase.class); suite.addTestSuite(PointcutRewriterTest.class); diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java deleted file mode 100644 index 3a4477f9c..000000000 --- a/weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.weaver.patterns; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Map; -import java.util.Set; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.Signature; -import org.aspectj.runtime.reflect.Factory; -import org.aspectj.util.FuzzyBoolean; -import org.aspectj.weaver.IntMap; -import org.aspectj.weaver.ResolvedType; -import org.aspectj.weaver.Shadow; -import org.aspectj.weaver.ast.Test; - -import junit.framework.TestCase; - - -public class PointcutTestCase extends TestCase { - - public void testMatchJP() { - Pointcut p = new Pointcut() { - - public Object accept(PatternNodeVisitor visitor, Object data) { - return visitor.visit(this,data); - } - - public Set couldMatchKinds() { - return null; - } - - public FuzzyBoolean fastMatch(FastMatchInfo info) { - return null; - } - - public FuzzyBoolean fastMatch(Class targetClass) { - return null; - } - - protected FuzzyBoolean matchInternal(Shadow shadow) { - return null; - } - - protected void resolveBindings(IScope scope, Bindings bindings) { - } - - protected void resolveBindingsFromRTTI() {} - - protected Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) { - return null; - } - - public Pointcut parameterizeWith(Map typeVariableMap) { - return null; - } - - protected Test findResidueInternal(Shadow shadow, ExposedState state) { - return null; - } - - public void write(DataOutputStream s) throws IOException { - }}; - - Factory f = new Factory("PointcutTestCase.java",PointcutTestCase.class); - - Signature methodSig = f.makeMethodSig("void aMethod()"); - JoinPoint.StaticPart jpsp = f.makeSJP(JoinPoint.METHOD_EXECUTION,methodSig,1); - JoinPoint jp = Factory.makeJP(jpsp,this,this); - - try { - p.match(jp,null); - fail("Expected UnsupportedOperationException to be thrown"); - } catch (UnsupportedOperationException unEx) { - // ok - } - - try { - p.match(jpsp); - fail("Expected UnsupportedOperationException to be thrown"); - } catch (UnsupportedOperationException unEx) { - // ok - } - - } - -} diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ThisOrTargetTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ThisOrTargetTestCase.java index 31794bcfe..532e93e9e 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/ThisOrTargetTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/ThisOrTargetTestCase.java @@ -1,5 +1,6 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 2005 Contributors * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -7,21 +8,25 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * PARC initial implementation + * PARC initial implementation + * Adrian Colyer, runtime reflection extensions * ******************************************************************/ package org.aspectj.weaver.patterns; -import java.io.*; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.runtime.reflect.Factory; -import org.aspectj.util.FuzzyBoolean; -import org.aspectj.weaver.bcel.*; +import java.io.IOException; +import java.lang.reflect.Method; import junit.framework.TestCase; -import org.aspectj.weaver.*; + +import org.aspectj.weaver.World; +import org.aspectj.weaver.bcel.BcelWorld; +import org.aspectj.weaver.tools.JoinPointMatch; +import org.aspectj.weaver.tools.PointcutExpression; +import org.aspectj.weaver.tools.PointcutParameter; +import org.aspectj.weaver.tools.PointcutParser; +import org.aspectj.weaver.tools.ShadowMatch; /** * @author hugunin @@ -50,77 +55,71 @@ public class ThisOrTargetTestCase extends TestCase { } - public void testMatchJP() { - Factory f = new Factory("ThisOrTargetTestCase.java",ThisOrTargetTestCase.class); - - Pointcut thisEx = new PatternParser("this(Exception)").parsePointcut().resolve(); - Pointcut thisIOEx = new PatternParser("this(java.io.IOException)").parsePointcut().resolve(); + public void testMatchJP() throws Exception { + PointcutParser parser = new PointcutParser(); + PointcutExpression thisEx = parser.parsePointcutExpression("this(Exception)"); + PointcutExpression thisIOEx = parser.parsePointcutExpression("this(java.io.IOException)"); - Pointcut targetEx = new PatternParser("target(Exception)").parsePointcut().resolve(); - Pointcut targetIOEx = new PatternParser("target(java.io.IOException)").parsePointcut().resolve(); + PointcutExpression targetEx = parser.parsePointcutExpression("target(Exception)"); + PointcutExpression targetIOEx = parser.parsePointcutExpression("target(java.io.IOException)"); - JoinPoint.StaticPart jpsp1 = f.makeSJP(JoinPoint.EXCEPTION_HANDLER,f.makeCatchClauseSig(HandlerTestCase.class,Exception.class,"ex"),1); - JoinPoint thisExJP = Factory.makeJP(jpsp1,new Exception(),this); - JoinPoint thisIOExJP = Factory.makeJP(jpsp1,new IOException(),this); - JoinPoint targetExJP = Factory.makeJP(jpsp1,this,new Exception()); - JoinPoint targetIOExJP = Factory.makeJP(jpsp1,this,new IOException()); + Method toString = Object.class.getMethod("toString",new Class[0]); - checkMatches(thisEx,thisExJP,null,FuzzyBoolean.YES); - checkMatches(thisIOEx,thisExJP,null,FuzzyBoolean.NO); - checkMatches(targetEx,thisExJP,null,FuzzyBoolean.NO); - checkMatches(targetIOEx,thisExJP,null,FuzzyBoolean.NO); - - checkMatches(thisEx,thisIOExJP,null,FuzzyBoolean.YES); - checkMatches(thisIOEx,thisIOExJP,null,FuzzyBoolean.YES); - checkMatches(targetEx,thisIOExJP,null,FuzzyBoolean.NO); - checkMatches(targetIOEx,thisIOExJP,null,FuzzyBoolean.NO); - - checkMatches(thisEx,targetExJP,null,FuzzyBoolean.NO); - checkMatches(thisIOEx,targetExJP,null,FuzzyBoolean.NO); - checkMatches(targetEx,targetExJP,null,FuzzyBoolean.YES); - checkMatches(targetIOEx,targetExJP,null,FuzzyBoolean.NO); - - checkMatches(thisEx,targetIOExJP,null,FuzzyBoolean.NO); - checkMatches(thisIOEx,targetIOExJP,null,FuzzyBoolean.NO); - checkMatches(targetEx,targetIOExJP,null,FuzzyBoolean.YES); - checkMatches(targetIOEx,targetIOExJP,null,FuzzyBoolean.YES); + checkMatches(thisEx.matchesMethodCall(toString, toString),new Exception(),null,null); + checkNoMatch(thisIOEx.matchesMethodCall(toString, toString),new Exception(),null,null); + checkNoMatch(targetEx.matchesMethodCall(toString, toString),new Exception(),new Object(),null); + checkNoMatch(targetIOEx.matchesMethodCall(toString, toString),new Exception(),new Exception(),null); + + checkMatches(thisEx.matchesMethodCall(toString, toString),new IOException(),null,null); + checkMatches(thisIOEx.matchesMethodCall(toString, toString),new IOException(),null,null); + + checkNoMatch(thisEx.matchesMethodCall(toString, toString),new Object(),null,null); + checkNoMatch(thisIOEx.matchesMethodCall(toString, toString),new Exception(),null,null); + checkMatches(targetEx.matchesMethodCall(toString, toString),new Exception(),new Exception(),null); + checkNoMatch(targetIOEx.matchesMethodCall(toString, toString),new Exception(),new Exception(),null); + + checkMatches(targetIOEx.matchesMethodCall(toString, toString),new Exception(),new IOException(),null); } - private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { - assertEquals(expected,p.match(jp,jpsp)); - } + public void testBinding() throws Exception { + PointcutParser parser = new PointcutParser(); + PointcutParameter ex = parser.createPointcutParameter("ex", Exception.class); + PointcutParameter ioEx = parser.createPointcutParameter("ioEx", IOException.class); -// private Pointcut makePointcut(String pattern) { -// return new PatternParser(pattern).parsePointcut(); -// } - -// private void checkEquals(String pattern, Pointcut p) throws IOException { -// assertEquals(pattern, p, makePointcut(pattern)); -// checkSerialization(pattern); -// } + PointcutExpression thisEx = parser.parsePointcutExpression("this(ex)",Exception.class,new PointcutParameter[] {ex}); + + PointcutExpression targetIOEx = parser.parsePointcutExpression("target(ioEx)",Exception.class,new PointcutParameter[] {ioEx}); + Method toString = Object.class.getMethod("toString",new Class[0]); + + ShadowMatch sMatch = thisEx.matchesMethodCall(toString, toString); + Exception exceptionParameter = new Exception(); + IOException ioExceptionParameter = new IOException(); + JoinPointMatch jpMatch = sMatch.matchesJoinPoint(exceptionParameter, null, null); + assertTrue("should match",jpMatch.matches()); + PointcutParameter[] bindings = jpMatch.getParameterBindings(); + assertEquals("one binding",1,bindings.length); + assertEquals("should be exceptionParameter",exceptionParameter,bindings[0].getBinding()); + assertEquals("ex",bindings[0].getName()); + + sMatch = targetIOEx.matchesMethodCall(toString,toString); + jpMatch = sMatch.matchesJoinPoint(exceptionParameter, ioExceptionParameter, null); + assertTrue("should match",jpMatch.matches()); + bindings = jpMatch.getParameterBindings(); + assertEquals("one binding",1,bindings.length); + assertEquals("should be ioExceptionParameter",ioExceptionParameter,bindings[0].getBinding()); + assertEquals("ioEx",bindings[0].getName()); + + + } -// private void checkMatch(Pointcut p, Signature[] matches, boolean shouldMatch) { -// for (int i=0; i<matches.length; i++) { -// boolean result = p.matches(matches[i]); -// String msg = "matches " + p + " to " + matches[i] + " expected "; -// if (shouldMatch) { -// assertTrue(msg + shouldMatch, result); -// } else { -// assertTrue(msg + shouldMatch, !result); -// } -// } -// } -// -// public void testSerialization() throws IOException { -// String[] patterns = new String[] { -// "public * *(..)", "void *.foo(A, B)", "A b()" -// }; -// -// for (int i=0, len=patterns.length; i < len; i++) { -// checkSerialization(patterns[i]); -// } -// } + private void checkMatches(ShadowMatch sMatch, Object thisObj, Object targetObj, Object[] args) { + assertTrue("match expected",sMatch.matchesJoinPoint(thisObj, targetObj, args).matches()); + } + + private void checkNoMatch(ShadowMatch sMatch, Object thisObj, Object targetObj, Object[] args) { + assertFalse("no match expected",sMatch.matchesJoinPoint(thisObj, targetObj, args).matches()); + } /** * Method checkSerialization. diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/WithinCodeTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/WithinCodeTestCase.java deleted file mode 100644 index 1f81a0db3..000000000 --- a/weaver/testsrc/org/aspectj/weaver/patterns/WithinCodeTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.weaver.patterns; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.runtime.reflect.Factory; -import org.aspectj.util.FuzzyBoolean; - -import junit.framework.TestCase; - - -public class WithinCodeTestCase extends TestCase { - Pointcut withinCode1; - Pointcut withinCode2; - Pointcut withinCode3; - - public void testMatchJP() { - Factory f = new Factory("WithinCodeTestCase.java",WithinCodeTestCase.class); - - // JoinPoints to match against... - JoinPoint.StaticPart exejp1 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"toString",Object.class,new Class[] {},new String[] {},new Class[0],String.class),1); - JoinPoint.StaticPart exejp2 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"sayHi",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],void.class),1); - JoinPoint.StaticPart execonsjp1 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,Object.class,new Class[0],new String[0],new Class[0]),1); - JoinPoint.StaticPart execonsjp2 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,String.class,new Class[] {String.class},new String[]{"s"},new Class[0]),1); - - checkMatches(withinCode1,exejp1,FuzzyBoolean.YES); - checkMatches(withinCode1,exejp2,FuzzyBoolean.NO); - checkMatches(withinCode1,execonsjp1,FuzzyBoolean.NO); - checkMatches(withinCode1,execonsjp2,FuzzyBoolean.NO); - - checkMatches(withinCode2,exejp1,FuzzyBoolean.NO); - checkMatches(withinCode2,exejp2,FuzzyBoolean.NO); - checkMatches(withinCode2,execonsjp1,FuzzyBoolean.YES); - checkMatches(withinCode2,execonsjp2,FuzzyBoolean.YES); - - checkMatches(withinCode3,exejp1,FuzzyBoolean.NO); - checkMatches(withinCode3,exejp2,FuzzyBoolean.NO); - checkMatches(withinCode3,execonsjp1,FuzzyBoolean.NO); - checkMatches(withinCode3,execonsjp2,FuzzyBoolean.YES); - - } - - private void checkMatches(Pointcut p, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { - assertEquals(expected,p.match(null,jpsp)); - } - - protected void setUp() throws Exception { - super.setUp(); - withinCode1 = new PatternParser("withincode(String Object.toString())").parsePointcut().resolve(); - withinCode2 = new PatternParser("withincode(new(..))").parsePointcut().resolve(); - withinCode3 = new PatternParser("withincode(String.new(..))").parsePointcut().resolve(); - } - - private static class Hello {}; -} diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/WithinTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/WithinTestCase.java index 92283c5e6..cde6578ba 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/WithinTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/WithinTestCase.java @@ -70,28 +70,28 @@ public class WithinTestCase extends TestCase { } - public void testMatchJP() { - Factory f = new Factory("WithinTestCase.java",WithinTestCase.class); - - JoinPoint.StaticPart inString = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,String.class,new Class[] {String.class},new String[]{"s"},new Class[0]),1); - JoinPoint.StaticPart inObject = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,Object.class,new Class[] {},new String[]{},new Class[0]),1); - - Pointcut withinString = new PatternParser("within(String)").parsePointcut().resolve(); - Pointcut withinObject = new PatternParser("within(Object)").parsePointcut().resolve(); - Pointcut withinObjectPlus = new PatternParser("within(Object+)").parsePointcut().resolve(); - - checkMatches(withinString,inString,FuzzyBoolean.YES); - checkMatches(withinString,inObject,FuzzyBoolean.NO); - checkMatches(withinObject,inString,FuzzyBoolean.NO); - checkMatches(withinObject,inObject, FuzzyBoolean.YES); - checkMatches(withinObjectPlus,inString,FuzzyBoolean.YES); - checkMatches(withinObjectPlus,inObject,FuzzyBoolean.YES); - } - - private void checkMatches(Pointcut p, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { - assertEquals(expected,p.match(null,jpsp)); - } - +// public void testMatchJP() { +// Factory f = new Factory("WithinTestCase.java",WithinTestCase.class); +// +// JoinPoint.StaticPart inString = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,String.class,new Class[] {String.class},new String[]{"s"},new Class[0]),1); +// JoinPoint.StaticPart inObject = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,Object.class,new Class[] {},new String[]{},new Class[0]),1); +// +// Pointcut withinString = new PatternParser("within(String)").parsePointcut().resolve(); +// Pointcut withinObject = new PatternParser("within(Object)").parsePointcut().resolve(); +// Pointcut withinObjectPlus = new PatternParser("within(Object+)").parsePointcut().resolve(); +// +// checkMatches(withinString,inString,FuzzyBoolean.YES); +// checkMatches(withinString,inObject,FuzzyBoolean.NO); +// checkMatches(withinObject,inString,FuzzyBoolean.NO); +// checkMatches(withinObject,inObject, FuzzyBoolean.YES); +// checkMatches(withinObjectPlus,inString,FuzzyBoolean.YES); +// checkMatches(withinObjectPlus,inObject,FuzzyBoolean.YES); +// } +// +// private void checkMatches(Pointcut p, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { +// assertEquals(expected,p.match(null,jpsp)); +// } +// public Pointcut makePointcut(String pattern) { Pointcut pointcut0 = Pointcut.fromString(pattern); diff --git a/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java b/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java new file mode 100644 index 000000000..739f7841a --- /dev/null +++ b/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java @@ -0,0 +1,149 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.weaver.reflect; + +import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.World; + +import junit.framework.TestCase; + +public class ReflectionBasedReferenceTypeDelegateTest extends TestCase { + + private World world; + private ResolvedType objectType; + + public void testIsAspect() { + assertFalse(objectType.isAspect()); + } + + public void testIsAnnotationStyleAspect() { + assertFalse(objectType.isAnnotationStyleAspect()); + } + + public void testIsInterface() { + assertFalse(objectType.isInterface()); + assertTrue(world.resolve("java.io.Serializable").isInterface()); + } + + public void testIsEnum() { + assertFalse(objectType.isEnum()); + } + + public void testIsAnnotation() { + assertFalse(objectType.isAnnotation()); + } + + public void testIsAnnotationWithRuntimeRetention() { + assertFalse(objectType.isAnnotationWithRuntimeRetention()); + } + + public void testIsClass() { + assertTrue(objectType.isClass()); + assertFalse(world.resolve("java.io.Serializable").isClass()); + } + + public void testIsGeneric() { + assertFalse(objectType.isGenericType()); + } + + public void testIsExposedToWeaver() { + assertFalse(objectType.isExposedToWeaver()); + } + + public void testHasAnnotation() { + assertFalse(objectType.hasAnnotation(UnresolvedType.forName("Foo"))); + } + + public void testGetAnnotations() { + assertEquals("no entries",0,objectType.getAnnotations().length); + } + + public void testGetAnnotationTypes() { + assertEquals("no entries",0,objectType.getAnnotationTypes().length); + } + + public void testGetTypeVariables() { + assertEquals("no entries",0,objectType.getTypeVariables().length); + } + + public void testGetPerClause() { + assertNull(objectType.getPerClause()); + } + + public void testGetModifiers() { + assertEquals(Object.class.getModifiers(),objectType.getModifiers()); + } + + public void testGetSuperclass() { + assertNull(objectType.getSuperclass()); + assertEquals(objectType,world.resolve("java.lang.Class").getSuperclass()); + ResolvedType d = world.resolve("reflect.tests.D"); + assertEquals(world.resolve("reflect.tests.C"),d.getSuperclass()); + } + + public void testGetDeclaredMethods() { + ResolvedMember[] methods = objectType.getDeclaredMethods(); + assertEquals(13,methods.length); + + ResolvedType c = world.resolve("reflect.tests.C"); + methods = c.getDeclaredMethods(); + assertEquals(3,methods.length); + assertEquals("foo",methods[0].getName()); + assertEquals(world.resolve("java.lang.String"),methods[0].getReturnType()); + assertEquals(1, methods[0].getParameterTypes().length); + assertEquals(objectType,methods[0].getParameterTypes()[0]); + assertEquals(1,methods[0].getExceptions().length); + assertEquals(world.resolve("java.lang.Exception"),methods[0].getExceptions()[0]); + assertEquals("bar",methods[1].getName()); + assertEquals("init",methods[2].getName()); + + ResolvedType d = world.resolve("reflect.tests.D"); + methods = d.getDeclaredMethods(); + assertEquals(2,methods.length); + } + + public void testGetDeclaredFields() { + ResolvedMember[] fields = objectType.getDeclaredFields(); + assertEquals(0,fields.length); + + ResolvedType c = world.resolve("reflect.tests.C"); + fields = c.getDeclaredFields(); + + assertEquals(2,fields.length); + assertEquals("f",fields[0].getName()); + assertEquals("s",fields[1].getName()); + assertEquals(ResolvedType.INT,fields[0].getReturnType()); + assertEquals(world.resolve("java.lang.String"),fields[1].getReturnType()); + } + + public void testGetDeclaredInterfaces() { + ResolvedType[] interfaces = objectType.getDeclaredInterfaces(); + assertEquals(0,interfaces.length); + + ResolvedType d = world.resolve("reflect.tests.D"); + interfaces = d.getDeclaredInterfaces(); + assertEquals(1,interfaces.length); + assertEquals(world.resolve("java.io.Serializable"),interfaces[0]); +} + + public void testGetDeclaredPointcuts() { + ResolvedMember[] pointcuts = objectType.getDeclaredPointcuts(); + assertEquals(0,pointcuts.length); + } + + protected void setUp() throws Exception { + world = new ReflectionWorld(); + objectType = world.resolve("java.lang.Object"); + } +} diff --git a/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java b/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java new file mode 100644 index 000000000..8f0942725 --- /dev/null +++ b/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java @@ -0,0 +1,28 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.weaver.reflect; + +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.World; + +import junit.framework.TestCase; + +public class ReflectionWorldTest extends TestCase { + + public void testDelegateCreation() { + World world = new ReflectionWorld(); + ResolvedType rt = world.resolve("java.lang.Object"); + assertNotNull(rt); + assertEquals("Ljava/lang/Object;",rt.getSignature()); + } + +} diff --git a/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java b/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java index 6e3e3d35e..8dc6418f2 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java @@ -14,6 +14,8 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; +import org.aspectj.util.LangUtil; + import junit.framework.TestCase; public class PointcutExpressionTest extends TestCase { @@ -22,6 +24,7 @@ public class PointcutExpressionTest extends TestCase { Constructor asCons; Constructor bsCons; Constructor bsStringCons; + Constructor clientCons; Method a; Method aa; Method aaa; @@ -35,434 +38,467 @@ public class PointcutExpressionTest extends TestCase { public void testMatchesMethodCall() { PointcutExpression ex = p.parsePointcutExpression("call(* *..A.a*(..))"); - assertEquals("Should match call to A.a()",FuzzyBoolean.YES,ex.matchesMethodCall(a,Client.class,A.class,null)); - assertEquals("Should match call to A.aaa()",FuzzyBoolean.YES,ex.matchesMethodCall(aaa,Client.class,A.class,null)); - assertEquals("Should match call to B.aa()",FuzzyBoolean.YES,ex.matchesMethodCall(bsaa,Client.class,A.class,null)); - assertEquals("Should not match call to B.b()",FuzzyBoolean.NO,ex.matchesMethodCall(b,Client.class,A.class,null)); + assertTrue("Should match call to A.a()",ex.matchesMethodCall(a,a).alwaysMatches()); + assertTrue("Should match call to A.aaa()",ex.matchesMethodCall(aaa,a).alwaysMatches()); + assertTrue("Should match call to B.aa()",ex.matchesMethodCall(bsaa,a).alwaysMatches()); + assertTrue("Should not match call to B.b()",ex.matchesMethodCall(b,a).neverMatches()); ex = p.parsePointcutExpression("call(* *..A.a*(int))"); - assertEquals("Should match call to A.aa()",FuzzyBoolean.YES,ex.matchesMethodCall(aa,Client.class,A.class,null)); - assertEquals("Should not match call to A.a()",FuzzyBoolean.NO,ex.matchesMethodCall(a,Client.class,A.class,null)); + assertTrue("Should match call to A.aa()",ex.matchesMethodCall(aa,a).alwaysMatches()); + assertTrue("Should not match call to A.a()",ex.matchesMethodCall(a,a).neverMatches()); ex = p.parsePointcutExpression("call(void aaa(..)) && this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should match call to A.aaa() from Client",FuzzyBoolean.YES,ex.matchesMethodCall(aaa,Client.class,A.class,null)); + assertTrue("Should match call to A.aaa() from Client",ex.matchesMethodCall(aaa,foo).alwaysMatches()); ex = p.parsePointcutExpression("call(void aaa(..)) && this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Should match call to A.aaa() from B",FuzzyBoolean.YES,ex.matchesMethodCall(aaa,B.class,A.class,null)); - assertEquals("May match call to A.aaa() from A",FuzzyBoolean.MAYBE,ex.matchesMethodCall(aaa,A.class,A.class,null)); + assertTrue("Should match call to A.aaa() from B",ex.matchesMethodCall(aaa,b).alwaysMatches()); + assertTrue("May match call to A.aaa() from A",ex.matchesMethodCall(aaa,a).maybeMatches()); + assertFalse("May match call to A.aaa() from A",ex.matchesMethodCall(aaa,a).alwaysMatches()); ex = p.parsePointcutExpression("execution(* *.*(..))"); - assertEquals("Should not match call to A.aa",FuzzyBoolean.NO,ex.matchesMethodCall(aa,A.class,A.class,null)); + assertTrue("Should not match call to A.aa",ex.matchesMethodCall(aa,a).neverMatches()); // this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should match Client",FuzzyBoolean.YES,ex.matchesMethodCall(a,Client.class,A.class,null)); - assertEquals("Should not match A",FuzzyBoolean.NO,ex.matchesMethodCall(a,A.class,A.class,null)); + assertTrue("Should match Client",ex.matchesMethodCall(a,foo).alwaysMatches()); + assertTrue("Should not match A",ex.matchesMethodCall(a,a).neverMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Should maybe match B",FuzzyBoolean.MAYBE,ex.matchesMethodCall(bsaa,A.class,B.class,null)); + assertTrue("Should maybe match B",ex.matchesMethodCall(bsaa,a).maybeMatches()); + assertFalse("Should maybe match B",ex.matchesMethodCall(bsaa,a).alwaysMatches()); // target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should not match Client",FuzzyBoolean.NO,ex.matchesMethodCall(a,Client.class,A.class,null)); + assertTrue("Should not match Client",ex.matchesMethodCall(a,a).neverMatches()); ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesMethodCall(a,Client.class,A.class,null)); + assertTrue("Should match A",ex.matchesMethodCall(a,a).alwaysMatches()); ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Should maybe match A",FuzzyBoolean.MAYBE,ex.matchesMethodCall(aa,A.class,A.class,null)); + assertTrue("Should maybe match A",ex.matchesMethodCall(aa,a).maybeMatches()); + assertFalse("Should maybe match A",ex.matchesMethodCall(aa,a).alwaysMatches()); // test args ex = p.parsePointcutExpression("args(..,int)"); - assertEquals("Should match A.aa",FuzzyBoolean.YES,ex.matchesMethodCall(aa,A.class,A.class,null)); - assertEquals("Should match A.aaa",FuzzyBoolean.YES,ex.matchesMethodCall(aaa,A.class,A.class,null)); - assertEquals("Should not match A.a",FuzzyBoolean.NO,ex.matchesMethodCall(a,A.class,A.class,null)); + assertTrue("Should match A.aa",ex.matchesMethodCall(aa,a).alwaysMatches()); + assertTrue("Should match A.aaa",ex.matchesMethodCall(aaa,a).alwaysMatches()); + assertTrue("Should not match A.a",ex.matchesMethodCall(a,a).neverMatches()); // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesMethodCall(a,A.class,A.class,null)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesMethodCall(a,B.class,A.class,null)); + assertTrue("Matches in class A",ex.matchesMethodCall(a,a).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesMethodCall(a,b).neverMatches()); + assertTrue("Matches in class A",ex.matchesMethodCall(a,A.class).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesMethodCall(a,B.class).neverMatches()); // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Should match",FuzzyBoolean.YES,ex.matchesMethodCall(b,B.class,B.class,bsaa)); - assertEquals("Should not match",FuzzyBoolean.NO,ex.matchesMethodCall(b,B.class,B.class,b)); + assertTrue("Should match",ex.matchesMethodCall(b,bsaa).alwaysMatches()); + assertTrue("Should not match",ex.matchesMethodCall(b,b).neverMatches()); } public void testMatchesMethodExecution() { PointcutExpression ex = p.parsePointcutExpression("execution(* *..A.aa(..))"); - assertEquals("Should match execution of A.aa",FuzzyBoolean.YES,ex.matchesMethodExecution(aa,A.class)); - assertEquals("Should match execution of B.aa",FuzzyBoolean.YES,ex.matchesMethodExecution(bsaa,B.class)); - assertEquals("Should not match execution of A.a",FuzzyBoolean.NO,ex.matchesMethodExecution(a,B.class)); + assertTrue("Should match execution of A.aa",ex.matchesMethodExecution(aa).alwaysMatches()); + assertTrue("Should match execution of B.aa",ex.matchesMethodExecution(bsaa).alwaysMatches()); + assertTrue("Should not match execution of A.a",ex.matchesMethodExecution(a).neverMatches()); ex = p.parsePointcutExpression("call(* *..A.a*(int))"); - assertEquals("Should not match execution of A.a",FuzzyBoolean.NO,ex.matchesMethodExecution(a,B.class)); + assertTrue("Should not match execution of A.a",ex.matchesMethodExecution(a).neverMatches()); + // test this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesMethodExecution(a,A.class)); + assertTrue("Should match A",ex.matchesMethodExecution(a).alwaysMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesMethodExecution(a,A.class)); - assertEquals("Should match B",FuzzyBoolean.YES,ex.matchesMethodExecution(a,B.class)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesMethodExecution(a,Client.class)); + assertTrue("Maybe matches B",ex.matchesMethodExecution(a).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesMethodExecution(a).alwaysMatches()); + // test target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesMethodExecution(a,A.class)); + assertTrue("Should match A",ex.matchesMethodExecution(a).alwaysMatches()); ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesMethodExecution(a,A.class)); - assertEquals("Should match B",FuzzyBoolean.YES,ex.matchesMethodExecution(a,B.class)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesMethodExecution(a,Client.class)); + assertTrue("Maybe matches B",ex.matchesMethodExecution(a).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesMethodExecution(a).alwaysMatches()); + // test args ex = p.parsePointcutExpression("args(..,int)"); - assertEquals("Should match A.aa",FuzzyBoolean.YES,ex.matchesMethodExecution(aa,A.class)); - assertEquals("Should match A.aaa",FuzzyBoolean.YES,ex.matchesMethodExecution(aaa,A.class)); - assertEquals("Should not match A.a",FuzzyBoolean.NO,ex.matchesMethodExecution(a,A.class)); + assertTrue("Should match A.aa",ex.matchesMethodExecution(aa).alwaysMatches()); + assertTrue("Should match A.aaa",ex.matchesMethodExecution(aaa).alwaysMatches()); + assertTrue("Should not match A.a",ex.matchesMethodExecution(a).neverMatches()); + // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesMethodExecution(a,A.class)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesMethodExecution(bsaa,B.class)); + assertTrue("Matches in class A",ex.matchesMethodExecution(a).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesMethodExecution(bsaa).neverMatches()); + // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Should not match",FuzzyBoolean.NO,ex.matchesMethodExecution(a,A.class)); + assertTrue("Should not match",ex.matchesMethodExecution(a).neverMatches()); } public void testMatchesConstructorCall() { PointcutExpression ex = p.parsePointcutExpression("call(new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesConstructorCall(asCons,A.class,null)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesConstructorCall(bsStringCons,Client.class,null)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesConstructorCall(bsCons,Client.class,null)); + assertTrue("Should match A(String)", ex.matchesConstructorCall(asCons,b).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesConstructorCall(bsStringCons,b).alwaysMatches()); + assertTrue("Should not match B()",ex.matchesConstructorCall(bsCons,foo).neverMatches()); ex = p.parsePointcutExpression("call(*..A.new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesConstructorCall(asCons,A.class,null)); - assertEquals("Should not match B(String)", FuzzyBoolean.NO, ex.matchesConstructorCall(bsStringCons,Client.class,null)); + assertTrue("Should match A(String)", ex.matchesConstructorCall(asCons,b).alwaysMatches()); + assertTrue("Should not match B(String)",ex.matchesConstructorCall(bsStringCons,foo).neverMatches()); // this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should match Client",FuzzyBoolean.YES,ex.matchesConstructorCall(asCons,Client.class,null)); - assertEquals("Should not match A",FuzzyBoolean.NO,ex.matchesConstructorCall(asCons,A.class,null)); + assertTrue("Should match Client",ex.matchesConstructorCall(asCons,foo).alwaysMatches()); + assertTrue("Should not match A",ex.matchesConstructorCall(asCons,a).neverMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Should maybe match B",FuzzyBoolean.MAYBE,ex.matchesConstructorCall(asCons,A.class,null)); + assertTrue("Should maybe match B",ex.matchesConstructorCall(asCons,a).maybeMatches()); + assertFalse("Should maybe match B",ex.matchesConstructorCall(asCons,a).alwaysMatches()); // target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should not match Client",FuzzyBoolean.NO,ex.matchesConstructorCall(asCons,Client.class,null)); + assertTrue("Should not match Client",ex.matchesConstructorCall(asCons,foo).neverMatches()); ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesConstructorCall(asCons,A.class,null)); - ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Should maybe match A",FuzzyBoolean.MAYBE,ex.matchesConstructorCall(asCons,A.class,null)); + assertTrue("Should not match A (no target)",ex.matchesConstructorCall(asCons,a).neverMatches()); // args ex = p.parsePointcutExpression("args(String)"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesConstructorCall(asCons,A.class,null)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesConstructorCall(bsStringCons,Client.class,null)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesConstructorCall(bsCons,Client.class,null)); + assertTrue("Should match A(String)", ex.matchesConstructorCall(asCons,b).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesConstructorCall(bsStringCons,foo).alwaysMatches()); + assertTrue("Should not match B()", ex.matchesConstructorCall(bsCons,foo).neverMatches()); // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesConstructorCall(asCons,A.class,null)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesConstructorCall(asCons,B.class,null)); + assertTrue("Matches in class A",ex.matchesConstructorCall(asCons,a).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesConstructorCall(asCons,b).neverMatches()); // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Should match",FuzzyBoolean.YES,ex.matchesConstructorCall(bsCons,B.class,aa)); - assertEquals("Should not match",FuzzyBoolean.NO,ex.matchesConstructorCall(bsCons,B.class,b)); + assertTrue("Should match",ex.matchesConstructorCall(bsCons,aa).alwaysMatches()); + assertTrue("Should not match",ex.matchesConstructorCall(bsCons,b).neverMatches()); } public void testMatchesConstructorExecution() { PointcutExpression ex = p.parsePointcutExpression("execution(new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesConstructorExecution(asCons,A.class)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesConstructorExecution(bsStringCons,Client.class)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesConstructorExecution(bsCons,Client.class)); + assertTrue("Should match A(String)", ex.matchesConstructorExecution(asCons).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesConstructorExecution(bsStringCons).alwaysMatches()); + assertTrue("Should not match B()", ex.matchesConstructorExecution(bsCons).neverMatches()); ex = p.parsePointcutExpression("execution(*..A.new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesConstructorExecution(asCons,A.class)); - assertEquals("Should not match B(String)", FuzzyBoolean.NO, ex.matchesConstructorExecution(bsStringCons,Client.class)); + assertTrue("Should match A(String)",ex.matchesConstructorExecution(asCons).alwaysMatches()); + assertTrue("Should not match B(String)",ex.matchesConstructorExecution(bsStringCons).neverMatches()); + // test this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesConstructorExecution(asCons,A.class)); + assertTrue("Should match A",ex.matchesConstructorExecution(asCons).alwaysMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesConstructorExecution(asCons,A.class)); - assertEquals("Should match B",FuzzyBoolean.YES,ex.matchesConstructorExecution(asCons,B.class)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesConstructorExecution(asCons,Client.class)); + assertTrue("Maybe matches B",ex.matchesConstructorExecution(asCons).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesConstructorExecution(asCons).alwaysMatches()); + assertTrue("Should match B",ex.matchesConstructorExecution(bsCons).alwaysMatches()); + assertTrue("Does not match client",ex.matchesConstructorExecution(clientCons).neverMatches()); + // test target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesConstructorExecution(asCons,A.class)); + assertTrue("Should match A",ex.matchesConstructorExecution(asCons).alwaysMatches()); ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesConstructorExecution(asCons,A.class)); - assertEquals("Should match B",FuzzyBoolean.YES,ex.matchesConstructorExecution(asCons,B.class)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesConstructorExecution(asCons,Client.class)); + assertTrue("Maybe matches B",ex.matchesConstructorExecution(asCons).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesConstructorExecution(asCons).alwaysMatches()); + assertTrue("Should match B",ex.matchesConstructorExecution(bsCons).alwaysMatches()); + assertTrue("Does not match client",ex.matchesConstructorExecution(clientCons).neverMatches()); + // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesConstructorExecution(asCons,B.class)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesConstructorExecution(bsCons,B.class)); + assertTrue("Matches in class A",ex.matchesConstructorExecution(asCons).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesConstructorExecution(bsCons).neverMatches()); + // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Does not match",FuzzyBoolean.NO,ex.matchesConstructorExecution(bsCons,B.class)); + assertTrue("Does not match",ex.matchesConstructorExecution(bsCons).neverMatches()); + // args ex = p.parsePointcutExpression("args(String)"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesConstructorExecution(asCons,A.class)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesConstructorExecution(bsStringCons,Client.class)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesConstructorExecution(bsCons,Client.class)); + assertTrue("Should match A(String)",ex.matchesConstructorExecution(asCons).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesConstructorExecution(bsStringCons).alwaysMatches()); + assertTrue("Should not match B()", ex.matchesConstructorExecution(bsCons).neverMatches()); } public void testMatchesAdviceExecution() { PointcutExpression ex = p.parsePointcutExpression("adviceexecution()"); - assertEquals("Should match (advice) A.a",FuzzyBoolean.YES,ex.matchesAdviceExecution(a,A.class)); + assertTrue("Should match (advice) A.a",ex.matchesAdviceExecution(a).alwaysMatches()); // test this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should match Client",FuzzyBoolean.YES,ex.matchesAdviceExecution(a,Client.class)); + assertTrue("Should match Client",ex.matchesAdviceExecution(foo).alwaysMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesAdviceExecution(a,A.class)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesAdviceExecution(a,Client.class)); + assertTrue("Maybe matches B",ex.matchesAdviceExecution(a).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesAdviceExecution(a).alwaysMatches()); + assertTrue("Does not match client",ex.matchesAdviceExecution(foo).neverMatches()); + // test target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should match Client",FuzzyBoolean.YES,ex.matchesAdviceExecution(a,Client.class)); + assertTrue("Should match Client",ex.matchesAdviceExecution(foo).alwaysMatches()); ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesAdviceExecution(a,A.class)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesAdviceExecution(a,Client.class)); + assertTrue("Maybe matches B",ex.matchesAdviceExecution(a).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesAdviceExecution(a).alwaysMatches()); + assertTrue("Does not match client",ex.matchesAdviceExecution(foo).neverMatches()); + // test within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesAdviceExecution(a,A.class)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesAdviceExecution(b,B.class)); + assertTrue("Matches in class A",ex.matchesAdviceExecution(a).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesAdviceExecution(b).neverMatches()); + // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Does not match",FuzzyBoolean.NO,ex.matchesAdviceExecution(a,A.class)); + assertTrue("Does not match",ex.matchesAdviceExecution(a).neverMatches()); + // test args ex = p.parsePointcutExpression("args(..,int)"); - assertEquals("Should match A.aa",FuzzyBoolean.YES,ex.matchesAdviceExecution(aa,A.class)); - assertEquals("Should match A.aaa",FuzzyBoolean.YES,ex.matchesAdviceExecution(aaa,A.class)); - assertEquals("Should not match A.a",FuzzyBoolean.NO,ex.matchesAdviceExecution(a,A.class)); + assertTrue("Should match A.aa",ex.matchesAdviceExecution(aa).alwaysMatches()); + assertTrue("Should match A.aaa",ex.matchesAdviceExecution(aaa).alwaysMatches()); + assertTrue("Should not match A.a",ex.matchesAdviceExecution(a).neverMatches()); } public void testMatchesHandler() { PointcutExpression ex = p.parsePointcutExpression("handler(Exception)"); - assertEquals("Should match catch(Exception)",FuzzyBoolean.YES,ex.matchesHandler(Exception.class,Client.class,null)); - assertEquals("Should not match catch(Throwable)",FuzzyBoolean.NO,ex.matchesHandler(Throwable.class,Client.class,null)); + assertTrue("Should match catch(Exception)",ex.matchesHandler(Exception.class,Client.class).alwaysMatches()); + assertTrue("Should not match catch(Throwable)",ex.matchesHandler(Throwable.class,Client.class).neverMatches()); // test this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should match Client",FuzzyBoolean.YES,ex.matchesHandler(Exception.class,Client.class,null)); + assertTrue("Should match Client",ex.matchesHandler(Exception.class,foo).alwaysMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesHandler(Exception.class,A.class,null)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesHandler(Exception.class,Client.class,null)); - // target + assertTrue("Maybe matches B",ex.matchesHandler(Exception.class,a).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesHandler(Exception.class,a).alwaysMatches()); + assertTrue("Does not match client",ex.matchesHandler(Exception.class,foo).neverMatches()); + // target - no target for exception handlers ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("Should match Client",FuzzyBoolean.YES,ex.matchesHandler(Exception.class,Client.class,null)); - ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesHandler(Exception.class,A.class,null)); - assertEquals("Does not match client",FuzzyBoolean.NO,ex.matchesHandler(Exception.class,Client.class,null)); + assertTrue("Should match Client",ex.matchesHandler(Exception.class,foo).neverMatches()); // args ex = p.parsePointcutExpression("args(Exception)"); - assertEquals("Should match Exception",FuzzyBoolean.YES, ex.matchesHandler(Exception.class,Client.class,null)); - assertEquals("Should match RuntimeException",FuzzyBoolean.YES, ex.matchesHandler(RuntimeException.class,Client.class,null)); - assertEquals("Should not match String",FuzzyBoolean.NO,ex.matchesHandler(String.class,Client.class,null)); - assertEquals("Maybe matches Throwable",FuzzyBoolean.MAYBE,ex.matchesHandler(Throwable.class,Client.class,null)); + assertTrue("Should match Exception",ex.matchesHandler(Exception.class,foo).alwaysMatches()); + assertTrue("Should match RuntimeException",ex.matchesHandler(RuntimeException.class,foo).alwaysMatches()); + assertTrue("Should not match String",ex.matchesHandler(String.class,foo).neverMatches()); + assertTrue("Maybe matches Throwable",ex.matchesHandler(Throwable.class,foo).maybeMatches()); + assertFalse("Maybe matches Throwable",ex.matchesHandler(Throwable.class,foo).alwaysMatches()); // within ex = p.parsePointcutExpression("within(*..Client)"); - assertEquals("Matches in class Client",FuzzyBoolean.YES,ex.matchesHandler(Exception.class,Client.class,null)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesHandler(Exception.class,B.class,null)); + assertTrue("Matches in class Client",ex.matchesHandler(Exception.class,foo).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesHandler(Exception.class,b).neverMatches()); // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Matches within aa",FuzzyBoolean.YES,ex.matchesHandler(Exception.class,Client.class,aa)); - assertEquals("Does not match within b",FuzzyBoolean.NO,ex.matchesHandler(Exception.class,Client.class,b)); + assertTrue("Matches within aa",ex.matchesHandler(Exception.class,aa).alwaysMatches()); + assertTrue("Does not match within b",ex.matchesHandler(Exception.class,b).neverMatches()); } public void testMatchesInitialization() { PointcutExpression ex = p.parsePointcutExpression("initialization(new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesInitialization(asCons)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesInitialization(bsStringCons)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesInitialization(bsCons)); + assertTrue("Should match A(String)",ex.matchesInitialization(asCons).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesInitialization(bsStringCons).alwaysMatches()); + assertTrue("Should not match B()",ex.matchesInitialization(bsCons).neverMatches()); ex = p.parsePointcutExpression("initialization(*..A.new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesInitialization(asCons)); - assertEquals("Should not match B(String)", FuzzyBoolean.NO, ex.matchesInitialization(bsStringCons)); + assertTrue("Should match A(String)", ex.matchesInitialization(asCons).alwaysMatches()); + assertTrue("Should not match B(String)", ex.matchesInitialization(bsStringCons).neverMatches()); // test this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesInitialization(asCons)); + assertTrue("Should match A",ex.matchesInitialization(asCons).alwaysMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesInitialization(asCons)); + assertTrue("Maybe matches B",ex.matchesInitialization(asCons).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesInitialization(asCons).alwaysMatches()); + // test target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesInitialization(asCons)); + assertTrue("Should match A",ex.matchesInitialization(asCons).alwaysMatches()); ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesInitialization(asCons)); + assertTrue("Maybe matches B",ex.matchesInitialization(asCons).maybeMatches()); + assertFalse("Maybe matches B",ex.matchesInitialization(asCons).alwaysMatches()); // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesInitialization(asCons)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesInitialization(bsCons)); + assertTrue("Matches in class A",ex.matchesInitialization(asCons).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesInitialization(bsCons).neverMatches()); // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Does not match",FuzzyBoolean.NO,ex.matchesInitialization(bsCons)); + assertTrue("Does not match",ex.matchesInitialization(bsCons).neverMatches()); // args ex = p.parsePointcutExpression("args(String)"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesInitialization(asCons)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesInitialization(bsStringCons)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesInitialization(bsCons)); + assertTrue("Should match A(String)", ex.matchesInitialization(asCons).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesInitialization(bsStringCons).alwaysMatches()); + assertTrue("Should not match B()",ex.matchesInitialization(bsCons).neverMatches()); } public void testMatchesPreInitialization() { PointcutExpression ex = p.parsePointcutExpression("preinitialization(new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesPreInitialization(asCons)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesPreInitialization(bsStringCons)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesPreInitialization(bsCons)); + assertTrue("Should match A(String)",ex.matchesPreInitialization(asCons).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesPreInitialization(bsStringCons).alwaysMatches()); + assertTrue("Should not match B()",ex.matchesPreInitialization(bsCons).neverMatches()); ex = p.parsePointcutExpression("preinitialization(*..A.new(String))"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesPreInitialization(asCons)); - assertEquals("Should not match B(String)", FuzzyBoolean.NO, ex.matchesPreInitialization(bsStringCons)); + assertTrue("Should match A(String)", ex.matchesPreInitialization(asCons).alwaysMatches()); + assertTrue("Should not match B(String)", ex.matchesPreInitialization(bsStringCons).neverMatches()); // test this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesPreInitialization(asCons)); - ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesPreInitialization(asCons)); + assertTrue("No match, no this at preinit",ex.matchesPreInitialization(asCons).neverMatches()); + // test target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("Should match A",FuzzyBoolean.YES,ex.matchesPreInitialization(asCons)); - ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("Maybe matches B",FuzzyBoolean.MAYBE,ex.matchesPreInitialization(asCons)); + assertTrue("No match, no target at preinit",ex.matchesPreInitialization(asCons).neverMatches()); + // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesPreInitialization(asCons)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesPreInitialization(bsCons)); + assertTrue("Matches in class A",ex.matchesPreInitialization(asCons).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesPreInitialization(bsCons).neverMatches()); // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Does not match",FuzzyBoolean.NO,ex.matchesPreInitialization(bsCons)); + assertTrue("Does not match",ex.matchesPreInitialization(bsCons).neverMatches()); // args ex = p.parsePointcutExpression("args(String)"); - assertEquals("Should match A(String)",FuzzyBoolean.YES, ex.matchesPreInitialization(asCons)); - assertEquals("Should match B(String)", FuzzyBoolean.YES, ex.matchesPreInitialization(bsStringCons)); - assertEquals("Should not match B()", FuzzyBoolean.NO,ex.matchesPreInitialization(bsCons)); } + assertTrue("Should match A(String)", ex.matchesPreInitialization(asCons).alwaysMatches()); + assertTrue("Should match B(String)", ex.matchesPreInitialization(bsStringCons).alwaysMatches()); + assertTrue("Should not match B()",ex.matchesPreInitialization(bsCons).neverMatches()); + } public void testMatchesStaticInitialization() { // staticinit PointcutExpression ex = p.parsePointcutExpression("staticinitialization(*..A+)"); - assertEquals("Matches A",FuzzyBoolean.YES,ex.matchesStaticInitialization(A.class)); - assertEquals("Matches B",FuzzyBoolean.YES,ex.matchesStaticInitialization(B.class)); - assertEquals("Doesn't match Client",FuzzyBoolean.NO,ex.matchesStaticInitialization(Client.class)); + assertTrue("Matches A",ex.matchesStaticInitialization(A.class).alwaysMatches()); + assertTrue("Matches B",ex.matchesStaticInitialization(B.class).alwaysMatches()); + assertTrue("Doesn't match Client",ex.matchesStaticInitialization(Client.class).neverMatches()); // this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("No this",FuzzyBoolean.NO,ex.matchesStaticInitialization(A.class)); + assertTrue("No this",ex.matchesStaticInitialization(A.class).neverMatches()); // target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertEquals("No target",FuzzyBoolean.NO,ex.matchesStaticInitialization(A.class)); + assertTrue("No target",ex.matchesStaticInitialization(A.class).neverMatches()); + // args ex = p.parsePointcutExpression("args()"); - assertEquals("No args",FuzzyBoolean.NO,ex.matchesStaticInitialization(A.class)); + assertTrue("No args",ex.matchesStaticInitialization(A.class).alwaysMatches()); + ex = p.parsePointcutExpression("args(String)"); + assertTrue("No args",ex.matchesStaticInitialization(A.class).neverMatches()); + // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesStaticInitialization(A.class)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesStaticInitialization(B.class)); + assertTrue("Matches in class A",ex.matchesStaticInitialization(A.class).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesStaticInitialization(B.class).neverMatches()); + // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Does not match",FuzzyBoolean.NO,ex.matchesStaticInitialization(A.class)); + assertTrue("Does not match",ex.matchesStaticInitialization(A.class).neverMatches()); } public void testMatchesFieldSet() { PointcutExpression ex = p.parsePointcutExpression("set(* *..A+.*)"); - assertEquals("matches x",FuzzyBoolean.YES,ex.matchesFieldSet(x,Client.class,A.class,null)); - assertEquals("matches y",FuzzyBoolean.YES,ex.matchesFieldSet(y,Client.class,B.class,null)); - assertEquals("does not match n",FuzzyBoolean.NO,ex.matchesFieldSet(n,A.class,Client.class,null)); + assertTrue("matches x",ex.matchesFieldSet(x,a).alwaysMatches()); + assertTrue("matches y",ex.matchesFieldSet(y,foo).alwaysMatches()); + assertTrue("does not match n",ex.matchesFieldSet(n,foo).neverMatches()); // this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("matches Client",FuzzyBoolean.YES,ex.matchesFieldSet(x,Client.class,A.class,null)); - assertEquals("does not match A",FuzzyBoolean.NO,ex.matchesFieldSet(n,A.class,Client.class,null)); + assertTrue("matches Client",ex.matchesFieldSet(x,foo).alwaysMatches()); + assertTrue("does not match A",ex.matchesFieldSet(n,a).neverMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("maybe matches A",FuzzyBoolean.MAYBE,ex.matchesFieldSet(x,A.class,A.class,null)); + assertTrue("maybe matches A",ex.matchesFieldSet(x,a).maybeMatches()); + assertFalse("maybe matches A",ex.matchesFieldSet(x,a).alwaysMatches()); // target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("matches B",FuzzyBoolean.YES,ex.matchesFieldSet(y,Client.class,B.class,null)); - assertEquals("maybe matches A",FuzzyBoolean.MAYBE,ex.matchesFieldSet(x,Client.class,A.class,null)); + assertTrue("matches B",ex.matchesFieldSet(y,foo).alwaysMatches()); + assertTrue("maybe matches A",ex.matchesFieldSet(x,foo).maybeMatches()); + assertFalse("maybe matches A",ex.matchesFieldSet(x,foo).alwaysMatches()); // args ex = p.parsePointcutExpression("args(int)"); - assertEquals("matches x",FuzzyBoolean.YES,ex.matchesFieldSet(x,Client.class,A.class,null)); - assertEquals("matches y",FuzzyBoolean.YES,ex.matchesFieldSet(y,Client.class,B.class,null)); - assertEquals("does not match n",FuzzyBoolean.NO,ex.matchesFieldSet(n,A.class,Client.class,null)); + assertTrue("matches x",ex.matchesFieldSet(x,a).alwaysMatches()); + assertTrue("matches y",ex.matchesFieldSet(y,a).alwaysMatches()); + assertTrue("does not match n",ex.matchesFieldSet(n,a).neverMatches()); // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesFieldSet(x,A.class,A.class,null)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesFieldSet(x,B.class,A.class,null)); + assertTrue("Matches in class A",ex.matchesFieldSet(x,a).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesFieldSet(x,b).neverMatches()); // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Should match",FuzzyBoolean.YES,ex.matchesFieldSet(x,A.class,A.class,aa)); - assertEquals("Should not match",FuzzyBoolean.NO,ex.matchesFieldSet(x,A.class,A.class,b)); + assertTrue("Should match",ex.matchesFieldSet(x,aa).alwaysMatches()); + assertTrue("Should not match",ex.matchesFieldSet(x,b).neverMatches()); } public void testMatchesFieldGet() { PointcutExpression ex = p.parsePointcutExpression("get(* *..A+.*)"); - assertEquals("matches x",FuzzyBoolean.YES,ex.matchesFieldGet(x,Client.class,A.class,null)); - assertEquals("matches y",FuzzyBoolean.YES,ex.matchesFieldGet(y,Client.class,B.class,null)); - assertEquals("does not match n",FuzzyBoolean.NO,ex.matchesFieldGet(n,A.class,Client.class,null)); + assertTrue("matches x",ex.matchesFieldGet(x,a).alwaysMatches()); + assertTrue("matches y",ex.matchesFieldGet(y,foo).alwaysMatches()); + assertTrue("does not match n",ex.matchesFieldGet(n,foo).neverMatches()); // this ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)"); - assertEquals("matches Client",FuzzyBoolean.YES,ex.matchesFieldGet(x,Client.class,A.class,null)); - assertEquals("does not match A",FuzzyBoolean.NO,ex.matchesFieldGet(n,A.class,Client.class,null)); + assertTrue("matches Client",ex.matchesFieldGet(x,foo).alwaysMatches()); + assertTrue("does not match A",ex.matchesFieldGet(n,a).neverMatches()); ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("maybe matches A",FuzzyBoolean.MAYBE,ex.matchesFieldGet(x,A.class,A.class,null)); + assertTrue("maybe matches A",ex.matchesFieldGet(x,a).maybeMatches()); + assertFalse("maybe matches A",ex.matchesFieldGet(x,a).alwaysMatches()); // target ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); - assertEquals("matches B",FuzzyBoolean.YES,ex.matchesFieldGet(y,Client.class,B.class,null)); - assertEquals("maybe matches A",FuzzyBoolean.MAYBE,ex.matchesFieldGet(x,Client.class,A.class,null)); - // args + assertTrue("matches B",ex.matchesFieldGet(y,foo).alwaysMatches()); + assertTrue("maybe matches A",ex.matchesFieldGet(x,foo).maybeMatches()); + assertFalse("maybe matches A",ex.matchesFieldGet(x,foo).alwaysMatches()); + // args - no args at get join point ex = p.parsePointcutExpression("args(int)"); - assertEquals("matches x",FuzzyBoolean.NO,ex.matchesFieldGet(x,Client.class,A.class,null)); - assertEquals("matches y",FuzzyBoolean.NO,ex.matchesFieldGet(y,Client.class,B.class,null)); - assertEquals("does not match n",FuzzyBoolean.NO,ex.matchesFieldGet(n,A.class,Client.class,null)); + assertTrue("matches x",ex.matchesFieldGet(x,a).neverMatches()); // within ex = p.parsePointcutExpression("within(*..A)"); - assertEquals("Matches in class A",FuzzyBoolean.YES,ex.matchesFieldGet(x,A.class,A.class,null)); - assertEquals("Does not match in class B",FuzzyBoolean.NO,ex.matchesFieldGet(x,B.class,A.class,null)); + assertTrue("Matches in class A",ex.matchesFieldGet(x,a).alwaysMatches()); + assertTrue("Does not match in class B",ex.matchesFieldGet(x,b).neverMatches()); // withincode ex = p.parsePointcutExpression("withincode(* a*(..))"); - assertEquals("Should match",FuzzyBoolean.YES,ex.matchesFieldGet(x,A.class,A.class,aa)); - assertEquals("Should not match",FuzzyBoolean.NO,ex.matchesFieldGet(x,A.class,A.class,b)); + assertTrue("Should match",ex.matchesFieldGet(x,aa).alwaysMatches()); + assertTrue("Should not match",ex.matchesFieldGet(x,b).neverMatches()); } public void testArgsMatching() { // too few args PointcutExpression ex = p.parsePointcutExpression("args(*,*,*,*)"); - assertEquals("Too few args",FuzzyBoolean.NO,ex.matchesMethodExecution(foo,Client.class)); - assertEquals("Matching #args",FuzzyBoolean.YES,ex.matchesMethodExecution(bar,Client.class)); + assertTrue("Too few args",ex.matchesMethodExecution(foo).neverMatches()); + assertTrue("Matching #args",ex.matchesMethodExecution(bar).alwaysMatches()); // one too few + ellipsis ex = p.parsePointcutExpression("args(*,*,*,..)"); - assertEquals("Matches with ellipsis",FuzzyBoolean.YES,ex.matchesMethodExecution(foo,Client.class)); + assertTrue("Matches with ellipsis",ex.matchesMethodExecution(foo).alwaysMatches()); // exact number + ellipsis - assertEquals("Matches with ellipsis",FuzzyBoolean.YES,ex.matchesMethodExecution(bar,Client.class)); - assertEquals("Does not match with ellipsis",FuzzyBoolean.NO,ex.matchesMethodExecution(a,A.class)); + assertTrue("Matches with ellipsis",ex.matchesMethodExecution(bar).alwaysMatches()); + assertTrue("Does not match with ellipsis",ex.matchesMethodExecution(a).neverMatches()); // too many + ellipsis ex = p.parsePointcutExpression("args(*,..,*)"); - assertEquals("Matches with ellipsis",FuzzyBoolean.YES,ex.matchesMethodExecution(bar,Client.class)); - assertEquals("Does not match with ellipsis",FuzzyBoolean.NO,ex.matchesMethodExecution(a,A.class)); - assertEquals("Matches with ellipsis",FuzzyBoolean.YES,ex.matchesMethodExecution(aaa,A.class)); + assertTrue("Matches with ellipsis",ex.matchesMethodExecution(bar).alwaysMatches()); + assertTrue("Does not match with ellipsis",ex.matchesMethodExecution(a).neverMatches()); + assertTrue("Matches with ellipsis",ex.matchesMethodExecution(aaa).alwaysMatches()); // exact match ex = p.parsePointcutExpression("args(String,int,Number)"); - assertEquals("Matches exactly",FuzzyBoolean.YES,ex.matchesMethodExecution(foo,Client.class)); + assertTrue("Matches exactly",ex.matchesMethodExecution(foo).alwaysMatches()); // maybe match ex = p.parsePointcutExpression("args(String,int,Double)"); - assertEquals("Matches maybe",FuzzyBoolean.MAYBE,ex.matchesMethodExecution(foo,Client.class)); + assertTrue("Matches maybe",ex.matchesMethodExecution(foo).maybeMatches()); + assertFalse("Matches maybe",ex.matchesMethodExecution(foo).alwaysMatches()); // never match ex = p.parsePointcutExpression("args(String,Integer,Number)"); - assertEquals("Does not match",FuzzyBoolean.NO,ex.matchesMethodExecution(foo,Client.class)); + if (LangUtil.is15VMOrGreater()) { + assertTrue("matches",ex.matchesMethodExecution(foo).alwaysMatches()); + } else { + assertTrue("Does not match",ex.matchesMethodExecution(foo).neverMatches()); + } } - public void testMatchesDynamically() { - // everything other than this,target,args should just return true - PointcutExpression ex = p.parsePointcutExpression("call(* *.*(..)) && execution(* *.*(..)) &&" + - "get(* *) && set(* *) && initialization(new(..)) && preinitialization(new(..)) &&" + - "staticinitialization(X) && adviceexecution() && within(Y) && withincode(* *.*(..)))"); - assertTrue("Matches dynamically",ex.matchesDynamically(a,b,new Object[0])); - // this - ex = p.parsePointcutExpression("this(String)"); - assertTrue("String matches",ex.matchesDynamically("",this,new Object[0])); - assertFalse("Object doesn't match",ex.matchesDynamically(new Object(),this,new Object[0])); - ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertTrue("A matches",ex.matchesDynamically(new A(""),this,new Object[0])); - assertTrue("B matches",ex.matchesDynamically(new B(""),this,new Object[0])); - // target - ex = p.parsePointcutExpression("target(String)"); - assertTrue("String matches",ex.matchesDynamically(this,"",new Object[0])); - assertFalse("Object doesn't match",ex.matchesDynamically(this,new Object(),new Object[0])); - ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); - assertTrue("A matches",ex.matchesDynamically(this,new A(""),new Object[0])); - assertTrue("B matches",ex.matchesDynamically(this,new B(""),new Object[0])); - // args - ex = p.parsePointcutExpression("args(*,*,*,*)"); - assertFalse("Too few args",ex.matchesDynamically(null,null,new Object[]{a,b})); - assertTrue("Matching #args",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa})); - // one too few + ellipsis - ex = p.parsePointcutExpression("args(*,*,*,..)"); - assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa})); - // exact number + ellipsis - assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa})); - assertFalse("Does not match with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b})); - // too many + ellipsis - ex = p.parsePointcutExpression("args(*,..,*)"); - assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa})); - assertFalse("Does not match with ellipsis",ex.matchesDynamically(null,null,new Object[]{a})); - assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b})); - // exact match - ex = p.parsePointcutExpression("args(String,int,Number)"); - assertTrue("Matches exactly",ex.matchesDynamically(null,null,new Object[]{"",new Integer(5),new Double(5.0)})); - ex = p.parsePointcutExpression("args(String,Integer,Number)"); - assertTrue("Matches exactly",ex.matchesDynamically(null,null,new Object[]{"",new Integer(5),new Double(5.0)})); - // never match - ex = p.parsePointcutExpression("args(String,Integer,Number)"); - assertFalse("Does not match",ex.matchesDynamically(null,null,new Object[]{a,b,aa})); -} +// public void testMatchesDynamically() { +// // everything other than this,target,args should just return true +// PointcutExpression ex = p.parsePointcutExpression("call(* *.*(..)) && execution(* *.*(..)) &&" + +// "get(* *) && set(* *) && initialization(new(..)) && preinitialization(new(..)) &&" + +// "staticinitialization(X) && adviceexecution() && within(Y) && withincode(* *.*(..)))"); +// assertTrue("Matches dynamically",ex.matchesDynamically(a,b,new Object[0])); +// // this +// ex = p.parsePointcutExpression("this(String)"); +// assertTrue("String matches",ex.matchesDynamically("",this,new Object[0])); +// assertFalse("Object doesn't match",ex.matchesDynamically(new Object(),this,new Object[0])); +// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); +// assertTrue("A matches",ex.matchesDynamically(new A(""),this,new Object[0])); +// assertTrue("B matches",ex.matchesDynamically(new B(""),this,new Object[0])); +// // target +// ex = p.parsePointcutExpression("target(String)"); +// assertTrue("String matches",ex.matchesDynamically(this,"",new Object[0])); +// assertFalse("Object doesn't match",ex.matchesDynamically(this,new Object(),new Object[0])); +// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)"); +// assertTrue("A matches",ex.matchesDynamically(this,new A(""),new Object[0])); +// assertTrue("B matches",ex.matchesDynamically(this,new B(""),new Object[0])); +// // args +// ex = p.parsePointcutExpression("args(*,*,*,*)"); +// assertFalse("Too few args",ex.matchesDynamically(null,null,new Object[]{a,b})); +// assertTrue("Matching #args",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa})); +// // one too few + ellipsis +// ex = p.parsePointcutExpression("args(*,*,*,..)"); +// assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa})); +// // exact number + ellipsis +// assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa})); +// assertFalse("Does not match with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b})); +// // too many + ellipsis +// ex = p.parsePointcutExpression("args(*,..,*)"); +// assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa})); +// assertFalse("Does not match with ellipsis",ex.matchesDynamically(null,null,new Object[]{a})); +// assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b})); +// // exact match +// ex = p.parsePointcutExpression("args(String,int,Number)"); +// assertTrue("Matches exactly",ex.matchesDynamically(null,null,new Object[]{"",new Integer(5),new Double(5.0)})); +// ex = p.parsePointcutExpression("args(String,Integer,Number)"); +// assertTrue("Matches exactly",ex.matchesDynamically(null,null,new Object[]{"",new Integer(5),new Double(5.0)})); +// // never match +// ex = p.parsePointcutExpression("args(String,Integer,Number)"); +// assertFalse("Does not match",ex.matchesDynamically(null,null,new Object[]{a,b,aa})); +//} public void testGetPointcutExpression() { PointcutExpression ex = p.parsePointcutExpression("staticinitialization(*..A+)"); @@ -471,15 +507,17 @@ public class PointcutExpressionTest extends TestCase { public void testCouldMatchJoinPointsInType() { PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))"); - assertFalse("Could never match String",ex.couldMatchJoinPointsInType(String.class)); + assertTrue("Could maybe match String (as best we know at this point)",ex.couldMatchJoinPointsInType(String.class)); + assertTrue("Will always match B",ex.couldMatchJoinPointsInType(B.class)); + ex = p.parsePointcutExpression("within(org.aspectj.weaver.tools.PointcutExpressionTest.B)"); + assertFalse("Will never match String",ex.couldMatchJoinPointsInType(String.class)); assertTrue("Will always match B",ex.couldMatchJoinPointsInType(B.class)); - assertFalse("Does not match A",ex.couldMatchJoinPointsInType(A.class)); } public void testMayNeedDynamicTest() { PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))"); assertFalse("No dynamic test needed",ex.mayNeedDynamicTest()); - ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..)) && args(X)"); + ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..)) && args(org.aspectj.weaver.tools.PointcutExpressionTest.X)"); assertTrue("Dynamic test needed",ex.mayNeedDynamicTest()); } @@ -496,6 +534,7 @@ public class PointcutExpressionTest extends TestCase { y = B.class.getDeclaredField("y"); b = B.class.getMethod("b",new Class[0]); bsaa = B.class.getMethod("aa",new Class[]{int.class}); + clientCons = Client.class.getConstructor(new Class[0]); n = Client.class.getDeclaredField("n"); foo = Client.class.getDeclaredMethod("foo",new Class[]{String.class,int.class,Number.class}); bar = Client.class.getDeclaredMethod("bar",new Class[]{String.class,int.class,Integer.class,Number.class}); @@ -518,8 +557,11 @@ public class PointcutExpressionTest extends TestCase { } static class Client { + public Client() {} Number n; public void foo(String s, int i, Number n) {} public void bar(String s, int i, Integer i2, Number n) {} } + + static class X {} } diff --git a/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java b/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java index 92bb6ea55..131ec1975 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java @@ -12,6 +12,11 @@ package org.aspectj.weaver.tools; import java.util.HashSet; import java.util.Set; +import org.aspectj.bridge.AbortException; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessageHandler; +import org.aspectj.bridge.IMessage.Kind; + import junit.framework.TestCase; /** @@ -21,7 +26,7 @@ public class PointcutParserTest extends TestCase { public void testGetAllSupportedPointcutPrimitives() { Set s = PointcutParser.getAllSupportedPointcutPrimitives(); - assertEquals("Should be 14 elements in the set",14,s.size()); + assertEquals("Should be 21 elements in the set",21,s.size()); assertFalse("Should not contain if pcd",s.contains(PointcutPrimitive.IF)); assertFalse("Should not contain cflow pcd",s.contains(PointcutPrimitive.CFLOW)); assertFalse("Should not contain cflowbelow pcd",s.contains(PointcutPrimitive.CFLOW_BELOW)); @@ -30,7 +35,7 @@ public class PointcutParserTest extends TestCase { public void testEmptyConstructor() { PointcutParser parser = new PointcutParser(); Set s = parser.getSupportedPrimitives(); - assertEquals("Should be 14 elements in the set",14,s.size()); + assertEquals("Should be 21 elements in the set",21,s.size()); assertFalse("Should not contain if pcd",s.contains(PointcutPrimitive.IF)); assertFalse("Should not contain cflow pcd",s.contains(PointcutPrimitive.CFLOW)); assertFalse("Should not contain cflowbelow pcd",s.contains(PointcutPrimitive.CFLOW_BELOW)); @@ -50,14 +55,19 @@ public class PointcutParserTest extends TestCase { public void testParsePointcutExpression() { PointcutParser p = new PointcutParser(); - PointcutExpression pEx = p.parsePointcutExpression( - "(adviceexecution() || execution(* *.*(..)) || handler(Exception) || " + - "call(Foo Bar+.*(Goo)) || get(* foo) || set(Foo+ (Goo||Moo).s*) || " + - "initialization(Foo.new(..)) || preinitialization(*.new(Foo,..)) || " + - "staticinitialization(org.xzy.abc..*)) && (this(Foo) || target(Boo) ||" + - "args(A,B,C)) && !handler(X)"); - try { - pEx = p.parsePointcutExpression("gobble-de-gook()"); + IMessageHandler current = p.setCustomMessageHandler(new IgnoreWarningsMessageHandler()); + try { + p.parsePointcutExpression( + "(adviceexecution() || execution(* *.*(..)) || handler(Exception) || " + + "call(Foo Bar+.*(Goo)) || get(* foo) || set(Foo+ (Goo||Moo).s*) || " + + "initialization(Foo.new(..)) || preinitialization(*.new(Foo,..)) || " + + "staticinitialization(org.xzy.abc..*)) && (this(Foo) || target(Boo) ||" + + "args(A,B,C)) && !handler(X)"); + } finally { + p.setCustomMessageHandler(current); + } + try { + p.parsePointcutExpression("gobble-de-gook()"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) {} } @@ -65,7 +75,7 @@ public class PointcutParserTest extends TestCase { public void testParseExceptionErrorMessages() { PointcutParser p = new PointcutParser(); try { - PointcutExpression pEx = p.parsePointcutExpression("execution(int Foo.*(..) && args(Double)"); + p.parsePointcutExpression("execution(int Foo.*(..) && args(Double)"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { assertTrue("Pointcut is not well-formed message",ex.getMessage().startsWith("Pointcut is not well-formed: expecting ')' at character position 24")); @@ -99,9 +109,11 @@ public class PointcutParserTest extends TestCase { } public void testParseReferencePCDs() { - PointcutParser p = new PointcutParser(); + Set pcKinds = PointcutParser.getAllSupportedPointcutPrimitives(); + pcKinds.remove(PointcutPrimitive.REFERENCE); + PointcutParser p = new PointcutParser(pcKinds); try { - p.parsePointcutExpression("bananas(x)"); + p.parsePointcutExpression("bananas(String)"); fail("Expected UnsupportedPointcutPrimitiveException"); } catch(UnsupportedPointcutPrimitiveException ex) { assertTrue(ex.getUnsupportedPrimitive() == PointcutPrimitive.REFERENCE); @@ -208,4 +220,42 @@ public class PointcutParserTest extends TestCase { assertEquals("Staticinit",PointcutPrimitive.STATIC_INITIALIZATION,ex.getUnsupportedPrimitive()); } } + + public void testFormals() { + PointcutParser parser = new PointcutParser(); + PointcutParameter param = parser.createPointcutParameter("x",String.class); + PointcutExpression pc = parser.parsePointcutExpression("args(x)", null, new PointcutParameter[] {param} ); + assertEquals("args(x)",pc.getPointcutExpression()); + + try { + pc = parser.parsePointcutExpression("args(String)", null, new PointcutParameter[] {param} ); + fail("Expecting IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + assertTrue("formal unbound",ex.getMessage().indexOf("formal unbound") != -1); + } + + try { + pc = parser.parsePointcutExpression("args(y)"); + fail("Expecting IllegalArgumentException"); + } catch(IllegalArgumentException ex) { + assertTrue("no match for type name",ex.getMessage().indexOf("warning no match for this type name: y") != -1); + } + } + + private static class IgnoreWarningsMessageHandler implements IMessageHandler { + + public boolean handleMessage(IMessage message) throws AbortException { + if (message.getKind() != IMessage.WARNING) throw new RuntimeException("unexpected message: " + message.toString()); + return true; + } + + public boolean isIgnoring(Kind kind) { + if (kind != IMessage.ERROR) return true; + return false; + } + + public void dontIgnore(Kind kind) { + } + + } } diff --git a/weaver/testsrc/reflect/tests/C.java b/weaver/testsrc/reflect/tests/C.java new file mode 100644 index 000000000..f52043b5a --- /dev/null +++ b/weaver/testsrc/reflect/tests/C.java @@ -0,0 +1,33 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package reflect.tests; + +/** + * @author colyer + * Part of the testdata for the org.aspectj.weaver.reflect tests + */ +public class C { + + public String foo(Object a) throws Exception { + return null; + } + + private void bar() {} + + public int f; + private String s; +} + +class D extends C implements java.io.Serializable { + public int getNumberOfThingies() { return 0; } + private Object o; +}
\ No newline at end of file |