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 --- .../generics/pointcuts/WithinCodeOverriding.aj | 68 ++++++++++++++++++++++ ...ithinCodePointcutMatchingParamAndReturnTypes.aj | 64 ++++++++++++++++++++ .../pointcuts/WithincodePointcutMatching.aj | 18 ++++++ 3 files changed, 150 insertions(+) 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/java5/generics/pointcuts') 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; + } + +} -- cgit v1.2.3