]> source.dussan.org Git - aspectj.git/commitdiff
new tests cases for args with generics and generic methods in general
authoracolyer <acolyer>
Tue, 9 Aug 2005 12:56:00 +0000 (12:56 +0000)
committeracolyer <acolyer>
Tue, 9 Aug 2005 12:56:00 +0000 (12:56 +0000)
tests/java5/generics/pointcuts/ArgsListOfSomething.aj [new file with mode: 0644]
tests/java5/generics/pointcuts/ArgsListOfSomethingExtends.aj [new file with mode: 0644]
tests/java5/generics/pointcuts/ArgsListOfSomethingSuper.aj [new file with mode: 0644]
tests/java5/generics/pointcuts/ArgsParameterized.aj [new file with mode: 0644]
tests/java5/generics/pointcuts/ArgsParameterizedWithWildcards.aj [new file with mode: 0644]
tests/java5/generics/pointcuts/GenericMethods.aj [new file with mode: 0644]
tests/java5/generics/pointcuts/GenericWildcardsInSignatureMatching.aj [new file with mode: 0644]
tests/java5/generics/pointcuts/RawArgs.aj [new file with mode: 0644]

diff --git a/tests/java5/generics/pointcuts/ArgsListOfSomething.aj b/tests/java5/generics/pointcuts/ArgsListOfSomething.aj
new file mode 100644 (file)
index 0000000..d7fc9ba
--- /dev/null
@@ -0,0 +1,51 @@
+import java.util.*;
+
+public aspect ArgsListOfSomething {
+       
+       // args(List<?>) matches List, List<String>, List<?>, ...
+               
+       void rawList(List l) {}
+       void listOfString(List<String> ls) {}
+       void listOfSomething(List<?> ls) {}
+       void listOfSomethingExtends(List<? extends Number> ln) {}
+       void listOfSomethingSuper(List<? super Double> ln) {}
+       
+       // try a couple of nested variations too
+       void mapit(Map<List<String>,List<List<Float>>> m) {}
+       void setOf(HashSet<Double> sd) {}
+       
+       public static void main(String[] args) {
+               ArgsListOfSomething a = ArgsListOfSomething.aspectOf();
+               a.rawList(null);
+               a.listOfString(null);
+               a.listOfSomething(null);
+               a.listOfSomethingExtends(null);
+               a.listOfSomethingSuper(null);
+               a.mapit(null);
+               a.setOf(null);
+       }
+       
+       before() : execution(* *(..)) && args(List<?>) {
+               System.out.println("List<?> matches " + thisJoinPointStaticPart);
+       }
+       
+       before() : execution(* *(..)) && args(Map<?,?>) {
+               System.out.println("wild map matches " + thisJoinPointStaticPart);
+       }
+       @org.aspectj.lang.annotation.SuppressAjWarnings
+       before() : execution(* *(..)) && args(HashMap<List<?>,List<List<?>>>) {
+               System.out.println("nested wild map does not match " + thisJoinPointStaticPart);
+       }
+       
+       before() : execution(* *(..)) && args(Map<List<String>,List<List<Float>>>) {
+               System.out.println("exact wild map matches " + thisJoinPointStaticPart);
+       }
+       
+       before() : execution(* *(..)) && args(Set<Double>) {
+               System.out.println("super type exact matches " + thisJoinPointStaticPart);
+       }
+       
+       before() : execution(* *(..)) && args(Set<?>) {
+               System.out.println("super wild type matches " + thisJoinPointStaticPart);
+       }
+}
\ No newline at end of file
diff --git a/tests/java5/generics/pointcuts/ArgsListOfSomethingExtends.aj b/tests/java5/generics/pointcuts/ArgsListOfSomethingExtends.aj
new file mode 100644 (file)
index 0000000..7db1c59
--- /dev/null
@@ -0,0 +1,31 @@
+import java.util.*;
+
+public aspect ArgsListOfSomethingExtends {
+       
+        // args(List<? extends Number) matches List<Number>, List<Double>, not List<String>
+        //                             matches List, List<?> with unchecked warning
+
+       void rawList(List l) {}
+       void listOfString(List<String> ls) {}
+       void listOfNumber(List<Number> ln) {}
+       void listOfDouble(List<Double> ld) {}
+       void listOfSomething(List<?> ls) {}
+       void listOfSomethingExtends(List<? extends Number> ln) {}
+       void listOfSomethingSuper(List<? super Double> ln) {}
+       
+       public static void main(String[] args) {
+               ArgsListOfSomethingExtends a = ArgsListOfSomethingExtends.aspectOf();
+               a.rawList(null);
+               a.listOfString(null);
+               a.listOfNumber(null);
+               a.listOfDouble(null);
+               a.listOfSomething(null);
+               a.listOfSomethingExtends(null);
+               a.listOfSomethingSuper(null);
+       }
+       
+       before() : execution(* *(..)) && args(List<? extends Number>) {
+               System.out.println("List<? extends Number> matches " + thisJoinPointStaticPart);
+       }
+       
+}
\ No newline at end of file
diff --git a/tests/java5/generics/pointcuts/ArgsListOfSomethingSuper.aj b/tests/java5/generics/pointcuts/ArgsListOfSomethingSuper.aj
new file mode 100644 (file)
index 0000000..54bb5d7
--- /dev/null
@@ -0,0 +1,36 @@
+import java.util.*;
+
+public aspect ArgsListOfSomethingSuper {
+       
+       /*
+        *   - args(List<? super Number>) matches List<Object>, List<Number>
+     *                               does not match List<Double>
+        *                                matches List, List<?> with unchecked warning
+        *                                matches List<? super Number>
+        *                                matches List<? extends Number> with unchecked warning
+        */
+       
+       void rawList(List l) {}
+       void listOfObject(List<Object> ls) {}
+       void listOfNumber(List<Number> ln) {}
+       void listOfDouble(List<Double> ld) {}
+       void listOfSomething(List<?> ls) {}
+       void listOfSomethingSuper(List<? super Number> ln) {}
+       void listOfSomethingExtendsNumber(List<? extends Number> ln) {}
+       
+       public static void main(String[] args) {
+               ArgsListOfSomethingSuper a = ArgsListOfSomethingSuper.aspectOf();
+               a.rawList(null);
+               a.listOfObject(null);
+               a.listOfNumber(null);
+               a.listOfDouble(null);
+               a.listOfSomething(null);
+               a.listOfSomethingSuper(null);
+               a.listOfSomethingExtendsNumber(null);
+       }
+       
+       before() : execution(* *(..)) && args(List<? super Number>) {
+               System.out.println("List<? super Number> matches " + thisJoinPointStaticPart);
+       }
+       
+}
\ No newline at end of file
diff --git a/tests/java5/generics/pointcuts/ArgsParameterized.aj b/tests/java5/generics/pointcuts/ArgsParameterized.aj
new file mode 100644 (file)
index 0000000..afa6eef
--- /dev/null
@@ -0,0 +1,65 @@
+import java.util.*;
+/**
+ *   - args(List<String>) matches List<String> but not List<Number>
+ *   - args(List<String>) matches List with unchecked warning
+ *   - args(List<String>) matches List<?> with unchecked warning
+ *   - args(List<String>) matches List<T> with unchecked warning
+ *   - args(List<String>) matches List<T extends String> (String is final)
+ */
+public aspect ArgsParameterized {
+
+       public static void main(String[] args) {
+                List<String> ls = new ArrayList<String>();
+//              ls.add("one");
+//              ls.add("two");
+//              ls.add("three");
+                
+                Generic<String> g = new Generic<String>();
+                g.foo(ls);
+                g.bar(ls);
+                g.tada(ls);
+                g.afar(new ArrayList<Number>());
+                g.something(ls);
+                
+                MustBeString<String> mbs = new MustBeString<String>();
+                mbs.listit(ls);
+        }
+       
+       before(List<String> ls) : call(* *(..)) && args(ls) {
+               System.out.println("args(List<String> matched at " + thisJoinPointStaticPart);
+               ls.add("four");
+               String s = ls.get(0);
+       }
+       
+}
+
+class Generic<T> {
+       
+       void foo(List<T> lt) {
+               ;
+       }
+       
+       void bar(List<String> ls) {
+               ;
+       }
+       
+       void tada(List l) {
+               ;
+       }
+       
+       void afar(List<Number> ln) {
+               ;
+       }
+       
+       void something(List<?> ls) {
+               ;
+       }
+}
+
+class MustBeString<T extends String> {
+       
+       void listit(List<T> lt) {
+               ;
+       }
+       
+}
\ No newline at end of file
diff --git a/tests/java5/generics/pointcuts/ArgsParameterizedWithWildcards.aj b/tests/java5/generics/pointcuts/ArgsParameterizedWithWildcards.aj
new file mode 100644 (file)
index 0000000..dcbd9a9
--- /dev/null
@@ -0,0 +1,40 @@
+import java.util.*;
+
+public aspect ArgsParameterizedWithWildcards {
+
+       /*
+        *   - args(List<Double>) matches List, List<?>, List<? extends Number> with unchecked warning
+        *                        matches List<Double>, List<? extends Double> ok (since Double is final)
+        */
+
+       before() : execution(* *(..)) && args(List<Double>) {
+               System.out.println("List<Double> matched at " + thisJoinPointStaticPart);
+       }
+       
+       public static void main(String[] args) {
+               C c = new C();
+               List<Double> ld = new ArrayList<Double>();
+               c.rawList(ld);
+               c.listOfSomething(ld);
+               c.listOfSomeNumber(ld);
+               c.listOfDouble(ld);
+               c.listOfSomeDouble(ld);
+               c.listOfString(new ArrayList<String>());
+       }
+}
+
+class C {
+       
+       void rawList(List l) {}
+       
+       void listOfSomething(List<?> ls) {}
+       
+       void listOfSomeNumber(List<? extends Number> ln) {}
+       
+       void listOfDouble(List<Double> ld) {}
+       
+       void listOfSomeDouble(List<? extends Double> ld) {}
+       
+       void listOfString(List<String> ls) {}
+       
+}
\ No newline at end of file
diff --git a/tests/java5/generics/pointcuts/GenericMethods.aj b/tests/java5/generics/pointcuts/GenericMethods.aj
new file mode 100644 (file)
index 0000000..c126461
--- /dev/null
@@ -0,0 +1,42 @@
+import java.util.*;
+
+public aspect GenericMethods {
+       
+       declare warning : execution(Object whoAmI(Object))
+                         : "static generic method match";
+       
+       declare warning : withincode(Number myFavourite(List))
+                         : "instance generic method match";
+       
+       // should we have an XLint to explain why the pointcut below does not match?
+       declare warning : execution(* myFavourite(List<Number>))
+                         : "no match because erasure is List";
+       
+}
+
+class PlainClassWithGenericMethods {
+       
+       public static <T> T whoAmI(T t) {
+               return t;
+       }
+       
+       public <S extends Number> S myFavourite(List<S> ls) {
+               return ls.get(0);
+       }
+       
+       
+}
+
+class GenericClassWithGenericMethods<N> {
+       
+       N n;
+       
+       public static <T> T whoAmI(T t) {
+               return t;
+       }
+       
+       public <S extends Number> S myFavourite(List<S> ls) {
+               return ls.get(0);
+       }
+               
+}
\ No newline at end of file
diff --git a/tests/java5/generics/pointcuts/GenericWildcardsInSignatureMatching.aj b/tests/java5/generics/pointcuts/GenericWildcardsInSignatureMatching.aj
new file mode 100644 (file)
index 0000000..5761891
--- /dev/null
@@ -0,0 +1,39 @@
+import java.util.*; import java.io.*;
+
+public class GenericWildcardsInSignatureMatching {
+       
+       List<?> aList = new ArrayList<String>();
+       
+       void foo(Map<? extends Number,List<List<String>>> map) {
+               ;
+       }
+       
+       List<? super Double> findOne(List<? super Double> ld) {
+               return ld;
+       }
+       
+       void anyOrder(List<? super Double> l) {}
+       
+}
+
+
+aspect WildcardMatcher {
+       
+       declare warning : set(List<?> *) : "set of a list";
+       
+       declare warning : execution(* foo(Map<? extends Number,List<List<String>>>))
+                         : "exact nested wildcard match";
+       
+       declare warning : execution(* foo(Map<? extends Object+,List<List+>>))
+                         : "wildcard nested wildcard match";
+       
+       declare warning : execution(List<? super Double> findOne(List<? super Double>))
+                         : "super";
+       
+       declare warning : execution(* anyOrder(List<? super Object+>))
+                         : "super wild match";
+
+       declare warning : execution(* anyOrder(List<?>))
+                                 : "no match - signature is different";
+
+}
\ No newline at end of file
diff --git a/tests/java5/generics/pointcuts/RawArgs.aj b/tests/java5/generics/pointcuts/RawArgs.aj
new file mode 100644 (file)
index 0000000..6a126db
--- /dev/null
@@ -0,0 +1,37 @@
+import java.util.*;
+/**
+ *   - args(List) matches List, List<T>, List<String>
+ */
+public aspect RawArgs {
+       
+       before() : args(List) && call(* *(..)) {
+               System.out.println("args(List) match at " + thisJoinPointStaticPart);
+       }
+       
+       public static void main(String[] args) {
+               Generic<Double> g = new Generic<Double>();
+               g.foo(new ArrayList<Double>());
+               g.bar(new ArrayList<String>());
+               g.tada(new ArrayList());
+               g.tada(new ArrayList<String>());
+               g.tada(new ArrayList<Double>());
+       }
+       
+}
+
+class Generic<T> {
+       
+       void foo(List<T> lt) {
+               ;
+       }
+       
+       void bar(List<String> ls) {
+               ;
+       }
+       
+       void tada(List l) {
+               ;
+       }
+       
+       
+}
\ No newline at end of file