From 56fdece12db2228299df8f5e3481d8d3eeb2cbac Mon Sep 17 00:00:00 2001 From: acolyer Date: Wed, 10 Aug 2005 08:39:08 +0000 Subject: [PATCH] test cases for after throwing and after returning with generic and parameterized types. --- .../AfterReturningListOfSomething.aj | 51 +++++++++ .../AfterReturningListOfSomethingExtends.aj | 31 +++++ .../AfterReturningListOfSomethingSuper.aj | 36 ++++++ .../AfterReturningParameterized.aj | 65 +++++++++++ ...fterReturningParameterizedWithWildcards.aj | 40 +++++++ .../afterAdvice/AfterReturningRawType.aj | 37 ++++++ .../generics/afterAdvice/AfterThrowing.aj | 10 ++ .../systemtest/ajc150/GenericsTests.java | 28 +++++ .../org/aspectj/systemtest/ajc150/ajc150.xml | 107 +++++++++++++++++- 9 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 tests/java5/generics/afterAdvice/AfterReturningListOfSomething.aj create mode 100644 tests/java5/generics/afterAdvice/AfterReturningListOfSomethingExtends.aj create mode 100644 tests/java5/generics/afterAdvice/AfterReturningListOfSomethingSuper.aj create mode 100644 tests/java5/generics/afterAdvice/AfterReturningParameterized.aj create mode 100644 tests/java5/generics/afterAdvice/AfterReturningParameterizedWithWildcards.aj create mode 100644 tests/java5/generics/afterAdvice/AfterReturningRawType.aj create mode 100644 tests/java5/generics/afterAdvice/AfterThrowing.aj diff --git a/tests/java5/generics/afterAdvice/AfterReturningListOfSomething.aj b/tests/java5/generics/afterAdvice/AfterReturningListOfSomething.aj new file mode 100644 index 000000000..6d10b077a --- /dev/null +++ b/tests/java5/generics/afterAdvice/AfterReturningListOfSomething.aj @@ -0,0 +1,51 @@ +import java.util.*; + +public aspect AfterReturningListOfSomething { + + // returning(List) matches List, List, List, ... + + List rawList(List l) { return l;} + List listOfString(List ls) { return ls; } + List listOfSomething(List ls) { return ls; } + List listOfSomethingExtends(List ln) { return ln; } + List listOfSomethingSuper(List ln) { return ln; } + + // try a couple of nested variations too + Map,List>> mapit(Map,List>> m) { return m;} + HashSet setOf(HashSet sd) { return sd; } + + public static void main(String[] args) { + AfterReturningListOfSomething a = AfterReturningListOfSomething.aspectOf(); + a.rawList(null); + a.listOfString(null); + a.listOfSomething(null); + a.listOfSomethingExtends(null); + a.listOfSomethingSuper(null); + a.mapit(null); + a.setOf(null); + } + + after() returning(List aList) : execution(* *(..)) { + System.out.println("List matches " + thisJoinPointStaticPart); + } + + after() returning(Map aMap) : execution(* *(..)) { + System.out.println("wild map matches " + thisJoinPointStaticPart); + } + @org.aspectj.lang.annotation.SuppressAjWarnings + after() returning(HashMap,List>> aMap) : execution(* *(..)) { + System.out.println("nested wild map does not match " + thisJoinPointStaticPart); + } + + after() returning(Map,List>> aMap) : execution(* *(..)) { + System.out.println("exact wild map matches " + thisJoinPointStaticPart); + } + + after() returning(Set aSet) : execution(* *(..)) { + System.out.println("super type exact matches " + thisJoinPointStaticPart); + } + + after() returning(Set aSet) : execution(* *(..)) { + System.out.println("super wild type matches " + thisJoinPointStaticPart); + } +} \ No newline at end of file diff --git a/tests/java5/generics/afterAdvice/AfterReturningListOfSomethingExtends.aj b/tests/java5/generics/afterAdvice/AfterReturningListOfSomethingExtends.aj new file mode 100644 index 000000000..4ddcfdc93 --- /dev/null +++ b/tests/java5/generics/afterAdvice/AfterReturningListOfSomethingExtends.aj @@ -0,0 +1,31 @@ +import java.util.*; + +public aspect AfterReturningListOfSomethingExtends { + + // returning(List, List, not List + // matches List, List with unchecked warning + + List rawList(List l) { return l; } + List listOfString(List ls) { return ls; } + List listOfNumber(List ln) { return ln; } + List listOfDouble(List ld) { return ld; } + List listOfSomething(List ls) { return ls; } + List listOfSomethingExtends(List ln) { return ln; } + List listOfSomethingSuper(List ln) { return ln; } + + public static void main(String[] args) { + AfterReturningListOfSomethingExtends a = AfterReturningListOfSomethingExtends.aspectOf(); + a.rawList(new ArrayList()); + a.listOfString(null); + a.listOfNumber(null); + a.listOfDouble(null); + a.listOfSomething(new ArrayList()); + a.listOfSomethingExtends(null); + a.listOfSomethingSuper(null); + } + + after() returning(List ln) : execution(* *(..)) { + System.out.println("List matches " + thisJoinPointStaticPart); + } + +} \ No newline at end of file diff --git a/tests/java5/generics/afterAdvice/AfterReturningListOfSomethingSuper.aj b/tests/java5/generics/afterAdvice/AfterReturningListOfSomethingSuper.aj new file mode 100644 index 000000000..f877c3603 --- /dev/null +++ b/tests/java5/generics/afterAdvice/AfterReturningListOfSomethingSuper.aj @@ -0,0 +1,36 @@ +import java.util.*; + +public aspect AfterReturningListOfSomethingSuper { + + /* + * - returning(List) matches List, List + * does not match List + * matches List, List with unchecked warning + * matches List + * matches List with unchecked warning + */ + + List rawList(List l) { return l; } + List listOfObject(List ls) { return ls; } + List listOfNumber(List ln) { return ln; } + List listOfDouble(List ld) { return ld; } + List listOfSomething(List ls) { return ls; } + List listOfSomethingSuper(List ln) {return ln; } + List listOfSomethingExtendsNumber(List ln) { return ln; } + + public static void main(String[] args) { + AfterReturningListOfSomethingSuper a = AfterReturningListOfSomethingSuper.aspectOf(); + a.rawList(new ArrayList()); + a.listOfObject(null); + a.listOfNumber(null); + a.listOfDouble(null); + a.listOfSomething(new ArrayList()); + a.listOfSomethingSuper(null); + a.listOfSomethingExtendsNumber(new ArrayList()); + } + + after() returning(List ln) : execution(* *(..)) { + System.out.println("List matches " + thisJoinPointStaticPart); + } + +} \ No newline at end of file diff --git a/tests/java5/generics/afterAdvice/AfterReturningParameterized.aj b/tests/java5/generics/afterAdvice/AfterReturningParameterized.aj new file mode 100644 index 000000000..716379da1 --- /dev/null +++ b/tests/java5/generics/afterAdvice/AfterReturningParameterized.aj @@ -0,0 +1,65 @@ +import java.util.*; +/** + * - returning(List) matches List but not List + * - returning(List) matches List with unchecked warning + * - returning(List) matches List with unchecked warning + * - returning(List) matches List with unchecked warning + * - returning(List) matches List (String is final) + */ +public aspect AfterReturningParameterized { + + public static void main(String[] args) { + List ls = new ArrayList(); +// ls.add("one"); +// ls.add("two"); +// ls.add("three"); + + Generic g = new Generic(); + g.foo(ls); + g.bar(ls); + g.tada(ls); + g.afar(new ArrayList()); + g.something(ls); + + MustBeString mbs = new MustBeString(); + mbs.listit(ls); + } + + after() returning(List ls) : call(* *(..)) { + System.out.println("returning(List matched at " + thisJoinPointStaticPart); + ls.add("four"); + String s = ls.get(0); + } + +} + +class Generic { + + List foo(List lt) { + return lt; + } + + List bar(List ls) { + return ls; + } + + List tada(List l) { + return l; + } + + List afar(List ln) { + return ln; + } + + List something(List ls) { + return ls; + } +} + +class MustBeString { + + List listit(List lt) { + return lt; + } + +} \ No newline at end of file diff --git a/tests/java5/generics/afterAdvice/AfterReturningParameterizedWithWildcards.aj b/tests/java5/generics/afterAdvice/AfterReturningParameterizedWithWildcards.aj new file mode 100644 index 000000000..57bfd4531 --- /dev/null +++ b/tests/java5/generics/afterAdvice/AfterReturningParameterizedWithWildcards.aj @@ -0,0 +1,40 @@ +import java.util.*; + +public aspect AfterReturningParameterizedWithWildcards { + + /* + * - returning(List) matches List, List, List with unchecked warning + * matches List, List ok (since Double is final) + */ + + after() returning(List ld) : call(* *(..)) { + System.out.println("List matched at " + thisJoinPointStaticPart); + } + + public static void main(String[] args) { + C c = new C(); + List ld = new ArrayList(); + c.rawList(ld); + c.listOfSomething(ld); + c.listOfSomeNumber(ld); + c.listOfDouble(ld); + c.listOfSomeDouble(ld); + c.listOfString(new ArrayList()); + } +} + +class C { + + List rawList(List l) { return l;} + + List listOfSomething(List ls) { return ls; } + + List listOfSomeNumber(List ln) { return ln; } + + List listOfDouble(List ld) { return ld; } + + List listOfSomeDouble(List ld) { return ld; } + + List listOfString(List ls) { return ls; } + +} \ No newline at end of file diff --git a/tests/java5/generics/afterAdvice/AfterReturningRawType.aj b/tests/java5/generics/afterAdvice/AfterReturningRawType.aj new file mode 100644 index 000000000..06fc8482b --- /dev/null +++ b/tests/java5/generics/afterAdvice/AfterReturningRawType.aj @@ -0,0 +1,37 @@ +import java.util.*; +/** + * - returning(List) matches List, List, List + */ +public aspect AfterReturningRawType { + + after() returning(List l) : call(* *(..)) { + System.out.println("returning(List) match at " + thisJoinPointStaticPart); + } + + public static void main(String[] args) { + Generic g = new Generic(); + g.foo(new ArrayList()); + g.bar(new ArrayList()); + g.tada(new ArrayList()); + g.tada(new ArrayList()); + g.tada(new ArrayList()); + } + +} + +class Generic { + + List foo(List lt) { + return lt; + } + + List bar(List ls) { + return ls; + } + + List tada(List l) { + return l; + } + + +} \ No newline at end of file diff --git a/tests/java5/generics/afterAdvice/AfterThrowing.aj b/tests/java5/generics/afterAdvice/AfterThrowing.aj new file mode 100644 index 000000000..d04e42ea2 --- /dev/null +++ b/tests/java5/generics/afterAdvice/AfterThrowing.aj @@ -0,0 +1,10 @@ +public aspect AfterThrowing { + + // since a generic type may not be a subtype of throwable, this is always an + // error. + + after() throwing(java.util.List ls) : execution(* *(..)){ + + } + +} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java index a16a6f300..99d9c8087 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -543,6 +543,34 @@ public class GenericsTests extends XMLBasedAjcTestCase { runTest("generic wildcards in signature matching"); } + public void testAfterThrowing() { + runTest("after throwing with parameterized throw type"); + } + + public void testAfterReturningWithRawType() { + runTest("after returning with raw type and generic / parameterized sigs"); + } + + public void testAfterReturningParameterizedType() { + runTest("after returning with parameterized type and generic / parameterized sigs"); + } + + public void testAfterReturningParameterizedAndWildcards() { + runTest("after returning with parameterized type and wildcards"); + } + + public void testAfterReturningWithWildcardVar() { + runTest("after returning with generic wildcard"); + } + + public void testAfterReturningWithWildcardExtendsVar() { + runTest("after returning with generic wildcard extends"); + } + + public void testAfterReturningWithWildcardSuperVar() { + runTest("after returning with generic wildcard super"); + } + // --- helpers // Check the signature attribute on a class is correct diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 1605cccf4..c2faab4f6 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -3116,6 +3116,7 @@ + @@ -3202,9 +3203,113 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5