diff options
author | acolyer <acolyer> | 2005-08-04 13:19:47 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-08-04 13:19:47 +0000 |
commit | 7b2bd108b72dbe26c15be6e976fc499e0d8759fc (patch) | |
tree | 777c08df5b238b403e1ec7fe21de85a9633aaad3 /tests | |
parent | 7c1a5d72a8549771b076af20b4caff8e1da903bd (diff) | |
download | aspectj-7b2bd108b72dbe26c15be6e976fc499e0d8759fc.tar.gz aspectj-7b2bd108b72dbe26c15be6e976fc499e0d8759fc.zip |
improved and additional signature matching tests
Diffstat (limited to 'tests')
7 files changed, 213 insertions, 12 deletions
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<T> { + int x = 0; + + // withincode (void Generic.foo(Object)) + // withincode (void *.foo(Object)) + public void foo(T someObject) { + x = 1; + } + +} + +class SubGeneric<N extends Number> extends Generic<N> { + 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<String> { + 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<E> { + void bar(E anElement); +} + +class ParameterizedI implements I<Double> { + 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<T> { + int x; + public Generic(List<String> ls) { + x = 5; + } + public Generic(T t) { + x = 6; + } + + T foo() { x = 7; return null; } +} + +interface ISore<E> { + + void iSee(E anE); + +} + +interface I2 { + void ic2it(); +} + +class UglyBuilding implements ISore<String>, 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<Number> 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<T>.*(..)); // CE L 4 + pointcut tryWcParameterized() : withincode(* Generic<String>.*(..)); // CE L5 + pointcut badThrows() : withincode(* Generic.*(..) throws Ex*<String>); // CE L6 +} + + +class Generic<T> { + + 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 @@ <ajc-test dir="java5/bridgeMethods" pr="72766" title="Ignore bridge methods"> <compile files="AspectX.aj" inpath="testcode.jar" options="-showWeaveInfo"> <message kind="warning" line="7" text="pointcut did not match on the method call to a bridge method."/> + <message kind="warning" line="7" text="does not match because declaring type is Number"/> <message kind="weave" text="(AspectX.aj:18) advised by before advice from 'AspectX'"/> <message kind="weave" text="(Number.java:5) advised by before advice from 'AspectX'"/> </compile> @@ -1329,8 +1330,7 @@ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: @inherited"> <compile files="AnnotationInheritance.aj" options="-1.5"> <message kind="warning" line="16" text="annotatedMethodCall()"/> - <message kind="warning" line="16" text="c1MethodCall()"/> - <message kind="warning" line="17" text="c1MethodCall()"/> + <message kind="warning" line="17" text="annotatedMethodCall()"/> </compile> </ajc-test> @@ -2789,7 +2789,38 @@ <message kind="warning" line="52" text="the really wild show"/> </compile> </ajc-test> - + + <ajc-test dir="java5/generics/pointcuts" title="withincode with various parameterizations and generic types - errors"> + <compile files="WithincodePointcutMatching.aj" options="-1.5"> + <message kind="warning" line="4" text="no match for this type name: T"/> + <message kind="error" line="4" text="can't use parameterized type patterns for the declaring type of a withincode pointcut expression (use the raw type instead)"/> + <message kind="error" line="5" text="can't use parameterized type patterns for the declaring type of a withincode pointcut expression (use the raw type instead)"/> + <message kind="error" line="6" text="invalid throws pattern: a generic class may not be a direct or indirect subclass of Throwable"/> + </compile> + </ajc-test> + + <ajc-test dir="java5/generics/pointcuts" title="withincode with various parameterizations and generic types - matching"> + <compile files="WithinCodePointcutMatchingParamAndReturnTypes.aj" options="-1.5"> + <message kind="warning" line="31" text="raw param type matching in withincode ok"/> + <message kind="warning" line="32" text="raw param type matching in withincode ok"/> + <message kind="warning" line="63" text="raw return type matching in withincode ok"/> + <message kind="warning" line="34" text="erasure type matching in withincode ok"/> + <message kind="warning" line="35" text="erasure type matching in withincode ok"/> + <message kind="warning" line="38" text="erasure type matching in withincode ok"/> + <message kind="warning" line="58" text="withincode and parameterized method ok"/> + <message kind="warning" line="58" text="withincode and generic interface ok"/> + <message kind="warning" line="61" text="withincode and interface control test"/> + </compile> + </ajc-test> + + <ajc-test dir="java5/generics/pointcuts" title="withincode with overriding of inherited generic members"> + <compile files="WithinCodeOverriding.aj" options="-1.5"> + <message kind="warning" line="22" text="wildcard declaring type match on erasure"/> + <message kind="warning" line="35" text="wildcard declaring type match on erasure"/> + <message kind="warning" line="48" text="wildcard declaring type match on erasure"/> + </compile> + </ajc-test> + <ajc-test dir="java5/generics/pointcuts" title="execution pcd with raw type matching"> <compile files="GenericInterface.java,ConcreteImplementingClass.java,GenericImplementingClass.java,RawTypeMatching.aj" options="-1.5"> <message kind="warning" line="4" text="execution(* GenericInterface.*(..))"/> |