public void testGenericMethodSignatures() throws Exception { PointcutExpression ex = parser.parsePointcutExpression( "execution(* set*(java.util.List<org.aspectj.weaver.tools.Java15PointcutExpressionTest.C>))"); Method m = TestBean.class.getMethod("setFriends", List.class); ShadowMatch sm = ex.matchesMethodExecution(m); assertTrue("should match", sm.alwaysMatches()); }
public void testVarArgsMatching() throws Exception { PointcutExpression ex = parser.parsePointcutExpression("execution(* *(String...))"); Method usesVarArgs = D.class.getMethod("varArgs", String[].class); Method noVarArgs = D.class.getMethod("nonVarArgs", String[].class); ShadowMatch sm1 = ex.matchesMethodExecution(usesVarArgs); assertTrue("should match", sm1.alwaysMatches()); ShadowMatch sm2 = ex.matchesMethodExecution(noVarArgs); assertFalse("should not match", sm2.alwaysMatches()); }
public void testAtWithin() { PointcutExpression atWithin = parser.parsePointcutExpression( "@within(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atWithin.matchesMethodExecution(a); ShadowMatch sMatch2 = atWithin.matchesMethodExecution(b); assertTrue("does not match a", sMatch1.neverMatches()); assertTrue("matches b", sMatch2.alwaysMatches()); }
public void testAtAnnotation() { PointcutExpression atAnnotation = parser.parsePointcutExpression( "@annotation(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atAnnotation.matchesMethodCall(b, a); ShadowMatch sMatch2 = atAnnotation.matchesMethodCall(a, a); assertTrue("does not match call to b", sMatch1.neverMatches()); assertTrue("matches call to a", sMatch2.alwaysMatches()); }
public void testAtWithinCode() { PointcutExpression atWithinCode = parser.parsePointcutExpression( "@withincode(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atWithinCode.matchesMethodCall(a, b); ShadowMatch sMatch2 = atWithinCode.matchesMethodCall(a, a); assertTrue("does not match from b", sMatch1.neverMatches()); assertTrue("matches from a", sMatch2.alwaysMatches()); }
public void testAtArgs() { PointcutExpression atArgs = parser.parsePointcutExpression( "@args(..,org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atArgs.matchesMethodExecution(a); ShadowMatch sMatch2 = atArgs.matchesMethodExecution(c); assertTrue("never matches A", sMatch1.neverMatches()); assertTrue("maybe matches C", sMatch2.maybeMatches()); JoinPointMatch jp2 = sMatch2.matchesJoinPoint(new B(), new B(), new Object[] {new A(), new B()}); assertTrue("matches", jp2.matches()); atArgs = parser.parsePointcutExpression( "@args(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation,org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); sMatch1 = atArgs.matchesMethodExecution(a); sMatch2 = atArgs.matchesMethodExecution(c); assertTrue("never matches A", sMatch1.neverMatches()); assertTrue("maybe matches C", sMatch2.maybeMatches()); JoinPointMatch jp1 = sMatch2.matchesJoinPoint(new A(), new A(), new Object[] {new A(), new B()}); assertFalse("does not match", jp1.matches()); jp2 = sMatch2.matchesJoinPoint(new B(), new B(), new Object[] {new B(), new B()}); assertTrue("matches", jp2.matches()); }
public void testReferencePCsInOtherType() throws Exception { PointcutExpression ex = parser.parsePointcutExpression( "org.aspectj.weaver.tools.Java15PointcutExpressionTest.ExternalReferrer.d()", ExternalReferrer.class, new PointcutParameter[0]); ShadowMatch sm = ex.matchesMethodExecution(a); assertTrue("should match", sm.alwaysMatches()); sm = ex.matchesMethodExecution(b); assertTrue("does not match", sm.neverMatches()); }
public void testAtWithinCodeWithBinding() { PointcutParameter p1 = parser.createPointcutParameter("x", MyAnnotation.class); PointcutExpression atWithinCode = parser.parsePointcutExpression("@withincode(x)", A.class, new PointcutParameter[] {p1}); ShadowMatch sMatch2 = atWithinCode.matchesMethodCall(a, a); assertTrue("matches from a", sMatch2.alwaysMatches()); JoinPointMatch jpm = sMatch2.matchesJoinPoint(new A(), new A(), new Object[0]); assertEquals(1, jpm.getParameterBindings().length); MyAnnotation annOna = a.getAnnotation(MyAnnotation.class); assertEquals("MyAnnotation on a", annOna, jpm.getParameterBindings()[0].getBinding()); }
public void testReferencePointcutParams() { PointcutParameter p1 = parser.createPointcutParameter("x", A.class); PointcutExpression pc = parser.parsePointcutExpression("goo(x)", C.class, new PointcutParameter[] {p1}); ShadowMatch sMatch1 = pc.matchesMethodCall(a, b); ShadowMatch sMatch2 = pc.matchesMethodExecution(a); assertTrue("no match on call", sMatch1.neverMatches()); assertTrue("match on execution", sMatch2.maybeMatches()); A anA = new A(); JoinPointMatch jpm = sMatch2.matchesJoinPoint(anA, new A(), new Object[0]); assertTrue(jpm.matches()); assertEquals("should be bound to anA", anA, jpm.getParameterBindings()[0].getBinding()); }
public void testAtWithinWithBinding() { PointcutParameter p1 = parser.createPointcutParameter("x", MyAnnotation.class); PointcutExpression atWithin = parser.parsePointcutExpression("@within(x)", B.class, new PointcutParameter[] {p1}); ShadowMatch sMatch1 = atWithin.matchesMethodExecution(a); ShadowMatch sMatch2 = atWithin.matchesMethodExecution(b); assertTrue("does not match a", sMatch1.neverMatches()); assertTrue("matches b", sMatch2.alwaysMatches()); JoinPointMatch jpm = sMatch2.matchesJoinPoint(new B(), new B(), new Object[0]); assertTrue(jpm.matches()); assertEquals(1, jpm.getParameterBindings().length); MyAnnotation bAnnotation = B.class.getAnnotation(MyAnnotation.class); assertEquals("annotation on B", bAnnotation, jpm.getParameterBindings()[0].getBinding()); }
public void testExecutionWithClassFileRetentionAnnotation() { PointcutExpression pc1 = parser.parsePointcutExpression( "execution(@org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation * *(..))"); PointcutExpression pc2 = parser.parsePointcutExpression( "execution(@org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyClassFileRetentionAnnotation * *(..))"); ShadowMatch sMatch = pc1.matchesMethodExecution(a); assertTrue("matches", sMatch.alwaysMatches()); sMatch = pc2.matchesMethodExecution(a); assertTrue("no match", sMatch.neverMatches()); sMatch = pc1.matchesMethodExecution(b); assertTrue("no match", sMatch.neverMatches()); sMatch = pc2.matchesMethodExecution(b); assertTrue("matches", sMatch.alwaysMatches()); }
public void testAtArgsWithBinding() { PointcutParameter p1 = parser.createPointcutParameter("a", MyAnnotation.class); PointcutParameter p2 = parser.createPointcutParameter("b", MyAnnotation.class); PointcutExpression atArgs = parser.parsePointcutExpression("@args(..,a)", A.class, new PointcutParameter[] {p1}); ShadowMatch sMatch2 = atArgs.matchesMethodExecution(c); assertTrue("maybe matches C", sMatch2.maybeMatches()); JoinPointMatch jp2 = sMatch2.matchesJoinPoint(new B(), new B(), new Object[] {new A(), new B()}); assertTrue("matches", jp2.matches()); assertEquals(1, jp2.getParameterBindings().length); MyAnnotation bAnnotation = B.class.getAnnotation(MyAnnotation.class); assertEquals("annotation on B", bAnnotation, jp2.getParameterBindings()[0].getBinding()); atArgs = parser.parsePointcutExpression("@args(a,b)", A.class, new PointcutParameter[] {p1, p2}); sMatch2 = atArgs.matchesMethodExecution(c); assertTrue("maybe matches C", sMatch2.maybeMatches()); jp2 = sMatch2.matchesJoinPoint(new B(), new B(), new Object[] {new B(), new B()}); assertTrue("matches", jp2.matches()); assertEquals(2, jp2.getParameterBindings().length); assertEquals("annotation on B", bAnnotation, jp2.getParameterBindings()[0].getBinding()); assertEquals("annotation on B", bAnnotation, jp2.getParameterBindings()[1].getBinding()); }
public void testAtTarget() { PointcutExpression atTarget = parser.parsePointcutExpression( "@target(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atTarget.matchesMethodExecution(a); ShadowMatch sMatch2 = atTarget.matchesMethodExecution(b); assertTrue("maybe matches A", sMatch1.maybeMatches()); assertTrue("maybe matches B", sMatch2.maybeMatches()); JoinPointMatch jp1 = sMatch1.matchesJoinPoint(new A(), new A(), new Object[0]); assertFalse("does not match", jp1.matches()); JoinPointMatch jp2 = sMatch2.matchesJoinPoint(new B(), new B(), new Object[0]); assertTrue("matches", jp2.matches()); }
public void testReferencePointcutNoParams() { PointcutExpression pc = parser.parsePointcutExpression("foo()", C.class, new PointcutParameter[0]); ShadowMatch sMatch1 = pc.matchesMethodCall(a, b); ShadowMatch sMatch2 = pc.matchesMethodExecution(a); assertTrue("no match on call", sMatch1.neverMatches()); assertTrue("match on execution", sMatch2.alwaysMatches()); pc = parser.parsePointcutExpression( "org.aspectj.weaver.tools.Java15PointcutExpressionTest.C.foo()"); sMatch1 = pc.matchesMethodCall(a, b); sMatch2 = pc.matchesMethodExecution(a); assertTrue("no match on call", sMatch1.neverMatches()); assertTrue("match on execution", sMatch2.alwaysMatches()); }
public void testAtTargetWithBinding() { PointcutParameter param = parser.createPointcutParameter("a", MyAnnotation.class); B myB = new B(); MyAnnotation bAnnotation = B.class.getAnnotation(MyAnnotation.class); PointcutExpression atThis = parser.parsePointcutExpression("@target(a)", A.class, new PointcutParameter[] {param}); ShadowMatch sMatch1 = atThis.matchesMethodExecution(a); ShadowMatch sMatch2 = atThis.matchesMethodExecution(b); assertTrue("maybe matches A", sMatch1.maybeMatches()); assertTrue("maybe matches B", sMatch2.maybeMatches()); JoinPointMatch jp1 = sMatch1.matchesJoinPoint(new A(), new A(), new Object[0]); assertFalse("does not match", jp1.matches()); JoinPointMatch jp2 = sMatch2.matchesJoinPoint(myB, myB, new Object[0]); assertTrue("matches", jp2.matches()); assertEquals(1, jp2.getParameterBindings().length); assertEquals( "should be myB's annotation", bAnnotation, jp2.getParameterBindings()[0].getBinding()); }
public void testJavaLangMatching() throws Exception { PointcutExpression ex = parser.parsePointcutExpression("@within(java.lang.Deprecated)"); Method foo = GoldenOldie.class.getMethod("foo"); ShadowMatch sm1 = ex.matchesMethodExecution(foo); assertTrue("should match", sm1.alwaysMatches()); }