From 7b2bd108b72dbe26c15be6e976fc499e0d8759fc Mon Sep 17 00:00:00 2001 From: acolyer Date: Thu, 4 Aug 2005 13:19:47 +0000 Subject: improved and additional signature matching tests --- .../ajdkExamples/AnnotationInheritance.aj | 10 ++-- tests/java5/bridgeMethods/AspectX.aj | 6 +- .../generics/pointcuts/WithinCodeOverriding.aj | 68 ++++++++++++++++++++++ ...ithinCodePointcutMatchingParamAndReturnTypes.aj | 64 ++++++++++++++++++++ .../pointcuts/WithincodePointcutMatching.aj | 18 ++++++ .../aspectj/systemtest/ajc150/GenericsTests.java | 22 ++++++- tests/src/org/aspectj/systemtest/ajc150/ajc150.xml | 37 +++++++++++- 7 files changed, 213 insertions(+), 12 deletions(-) create mode 100644 tests/java5/generics/pointcuts/WithinCodeOverriding.aj create mode 100644 tests/java5/generics/pointcuts/WithinCodePointcutMatchingParamAndReturnTypes.aj create mode 100644 tests/java5/generics/pointcuts/WithincodePointcutMatching.aj (limited to 'tests') diff --git a/tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj b/tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj index 68c14269f..2ca13eba4 100644 --- a/tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj +++ b/tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj @@ -20,14 +20,14 @@ aspect X { - pointcut annotatedMethodCall() : - call(@SomeAnnotation * C1.aMethod()); //CW L16 + pointcut annotatedC2MethodCall() : + call(@SomeAnnotation * C2.aMethod()); // matches nothing - pointcut c1MethodCall() : // CW L16, L17 - call(* C1.aMethod()); + pointcut annotatedMethodCall() : // CW L16, L17 + call(@SomeAnnotation * aMethod()); + declare warning : annotatedC2MethodCall() : "annotatedC2MethodCall()"; declare warning : annotatedMethodCall() : "annotatedMethodCall()"; - declare warning : c1MethodCall() : "c1MethodCall()"; } @Inherited @interface SomeAnnotation {} \ No newline at end of file diff --git a/tests/java5/bridgeMethods/AspectX.aj b/tests/java5/bridgeMethods/AspectX.aj index fb4827023..12ecf12fc 100644 --- a/tests/java5/bridgeMethods/AspectX.aj +++ b/tests/java5/bridgeMethods/AspectX.aj @@ -4,11 +4,11 @@ public aspect AspectX { static Set matchedJps = new HashSet(); - before(): call(* compareTo(..)) { + before(): call(* Number.compareTo(..)) { matchedJps.add(new String("call() matched on "+thisJoinPoint.toString())); } - before(): execution(* compareTo(..)) { + before(): execution(* Number.compareTo(..)) { matchedJps.add(new String("execution() matched on "+thisJoinPoint.toString())); } @@ -22,7 +22,7 @@ public aspect AspectX { n1.compareTo("abc"); ^ 1 error - */ + */ Iterator i = matchedJps.iterator(); while (i.hasNext()) { diff --git a/tests/java5/generics/pointcuts/WithinCodeOverriding.aj b/tests/java5/generics/pointcuts/WithinCodeOverriding.aj new file mode 100644 index 000000000..ba7160968 --- /dev/null +++ b/tests/java5/generics/pointcuts/WithinCodeOverriding.aj @@ -0,0 +1,68 @@ +public aspect WithinCodeOverriding { + + // if a type overrides a generic method from a supertype, changing the + // signature in the process (for example, is a generic subtype with a + // narrowed type variable, or extends a parameterized super class, or + // implements a parameterized interface), then a type pattern of + // OriginalDeclaringType.erasureOfOriginalSignature matches, and a + // type pattern of *.erasureOfOriginalSignature matches, but + // a type pattern OverridingType.erasureOfOriginalSignature DOES NOT + // MATCH. + + declare warning : withincode(void *.foo(Object)) + : "wildcard declaring type match on erasure"; +} + +class Generic { + int x = 0; + + // withincode (void Generic.foo(Object)) + // withincode (void *.foo(Object)) + public void foo(T someObject) { + x = 1; + } + +} + +class SubGeneric extends Generic { + int y = 0; + + // withincode(void Generic.foo(Object)) + // withincode( void *.foo(Object)) + // withincode(void SubGeneric.foo(Number)) + // !withincode(void SubGeneric.foo(Object)) + public void foo(N someObject) { + y = 1; + } + +} + +class SubParameterized extends Generic { + int y = 0; + + // withincode(void Generic.foo(Object)) + // withincode( void *.foo(Object)) + // withincode(void SubParameterized.foo(String)) + // !withincode(void SubGeneric.foo(Object)) + public void foo(String someObject) { + y = 1; + } + +} + +interface I { + void bar(E anElement); +} + +class ParameterizedI implements I { + int x; + + // withincode(void I.bar(Object)) + // withincode(void *.bar(Object)) + // withincode(void ParameterizedI.bar(Double)) + // !withincode(void ParameterizedI.bar(Object)) + public void bar(Double d) { + x = 1; + } +} + diff --git a/tests/java5/generics/pointcuts/WithinCodePointcutMatchingParamAndReturnTypes.aj b/tests/java5/generics/pointcuts/WithinCodePointcutMatchingParamAndReturnTypes.aj new file mode 100644 index 000000000..a57e9f75d --- /dev/null +++ b/tests/java5/generics/pointcuts/WithinCodePointcutMatchingParamAndReturnTypes.aj @@ -0,0 +1,64 @@ +import java.util.*; + +public aspect WithinCodePointcutMatchingParamAndReturnTypes { + + // rule 3) a raw parameter pattern matches any parameterized type + declare warning : withincode(Generic.new(List)) + : "raw param type matching in withincode ok"; + declare warning : withincode(List UglyBuilding.foo()) + : "raw return type matching in withincode ok"; + + // rule 4) A param type declared using a type variable is matched by its erasure + declare warning : withincode(Generic.new(Object)) + : "erasure type matching in withincode ok"; + declare warning : withincode(Object Generic.foo()) + : "erasure type matching in withincode ok"; + + // rule 5) no join points in bridge methods + declare warning : withincode(void UglyBuilding.iSee(String)) + : "withincode and parameterized method ok"; + declare warning : withincode(* ISore.*(..)) + : "withincode and generic interface ok"; + declare warning : withincode(* I2.*(..)) + : "withincode and interface control test"; + declare warning : withincode(void UglyBuilding.iSee(Object)) + : "should be no join points for bridge methods"; +} + + +class Generic { + int x; + public Generic(List ls) { + x = 5; + } + public Generic(T t) { + x = 6; + } + + T foo() { x = 7; return null; } +} + +interface ISore { + + void iSee(E anE); + +} + +interface I2 { + void ic2it(); +} + +class UglyBuilding implements ISore, I2 { + + int y; + + // this class will have a bridge method with signature void iSee(Object), with a cast and call + // to the method below + public void iSee(String s) { + y = 2; + } + + public void ic2it() { y = 4; } + + List foo() { y = 1; return null; } +} \ No newline at end of file diff --git a/tests/java5/generics/pointcuts/WithincodePointcutMatching.aj b/tests/java5/generics/pointcuts/WithincodePointcutMatching.aj new file mode 100644 index 000000000..a1730c126 --- /dev/null +++ b/tests/java5/generics/pointcuts/WithincodePointcutMatching.aj @@ -0,0 +1,18 @@ +public aspect WithincodePointcutMatching { + + // rule 1) you can't use generic or parameterized type patterns in the declaring type position + pointcut tryWcGeneric() : withincode(* Generic.*(..)); // CE L 4 + pointcut tryWcParameterized() : withincode(* Generic.*(..)); // CE L5 + pointcut badThrows() : withincode(* Generic.*(..) throws Ex*); // CE L6 +} + + +class Generic { + + T foo = null; + + T getFoo() { + return foo; + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java index 04f9fa7f7..c9ceace53 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -79,7 +79,15 @@ public class GenericsTests extends XMLBasedAjcTestCase { * - type variables as params PASS * - parameterized types as params PASS * - no join points for init, preinit of parameterized types (as per staticinit) PASS - * execution, withincode + * withincode + * - no generic or parameterized declaring type patterns PASS + * - no parameterized throws patterns PASS + * - return type as type variable + * - return type as parameterized type + * - parameter as type variable + * - parameter as parameterized type + * - no join points within bridge methods + * execution * - wait till we get there! * call * - wait till we get there! @@ -344,6 +352,18 @@ public class GenericsTests extends XMLBasedAjcTestCase { runTest("init and preinit with parameterized parameter types"); } + public void testWithinCodePointcutErrors() { + runTest("withincode with various parameterizations and generic types - errors"); + } + + public void testWithinCodeMatching() { + runTest("withincode with various parameterizations and generic types - matching"); + } + + public void testWithinCodeOverrideMatchingWithGenericMembers() { + runTest("withincode with overriding of inherited generic members"); + } + public void testExecutionWithRawType() { runTest("execution pcd with raw type matching"); } diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 8d13d5ab2..7bd0776aa 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -12,6 +12,7 @@ + @@ -1329,8 +1330,7 @@ - - + @@ -2789,7 +2789,38 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3