aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-08-18 09:31:26 +0000
committeracolyer <acolyer>2005-08-18 09:31:26 +0000
commitf7a8c2e721fa01b1b78607a37e57e983f5349062 (patch)
tree66e395409f6612880afa5fba9334a807b0300e9c /tests/java5
parente88e1a38c43abbfabdb407d51a3dd122afede672 (diff)
downloadaspectj-f7a8c2e721fa01b1b78607a37e57e983f5349062.tar.gz
aspectj-f7a8c2e721fa01b1b78607a37e57e983f5349062.zip
tests for examples in the ajdk generics chapter
Diffstat (limited to 'tests/java5')
-rw-r--r--tests/java5/generics/ajdk/AfterReturningExamples.aj66
-rw-r--r--tests/java5/generics/ajdk/PointcutInGenericClassExample.aj31
-rw-r--r--tests/java5/generics/ajdk/WildcardArgsExamples.aj46
3 files changed, 143 insertions, 0 deletions
diff --git a/tests/java5/generics/ajdk/AfterReturningExamples.aj b/tests/java5/generics/ajdk/AfterReturningExamples.aj
new file mode 100644
index 000000000..8e24f9e7c
--- /dev/null
+++ b/tests/java5/generics/ajdk/AfterReturningExamples.aj
@@ -0,0 +1,66 @@
+import java.util.*;
+import org.aspectj.lang.annotation.SuppressAjWarnings;
+
+public aspect AfterReturningExamples {
+
+ after() returning : execution(* C.*(..)) {
+ System.out.println(thisJoinPointStaticPart);
+ }
+
+ pointcut executionOfAnyMethodReturningAList() : execution(List *(..));
+
+ // matches all three
+ after() returning(List<?> listOfSomeType) : executionOfAnyMethodReturningAList() {
+ for (Object element : listOfSomeType) {
+ System.out.println("raw " + element);
+ }
+ }
+
+ // matches bar and goo, with unchecked on goo
+ after() returning(List<Double> listOfDoubles) : execution(* C.*(..)) {
+ for(Double d : listOfDoubles) {
+ System.out.println("a1 " + d);
+ }
+ }
+
+ // matches only bar
+ after() returning(List<Double> listOfDoubles) : execution(List<Double> C.*(..)) {
+ for(Double d : listOfDoubles) {
+ System.out.println("a2 " + d);
+ }
+ }
+
+ // matches bar and goo, with no warning
+ @SuppressAjWarnings
+ after() returning(List<Double> listOfDoubles) : execution(* C.*(..)) {
+ for(Double d : listOfDoubles) {
+ System.out.println("a3 " + d);
+ }
+ }
+
+
+ public static void main(String[] args) {
+ List<Double> ld = new ArrayList<Double>();
+ ld.add(5.0d);
+ ld.add(10.0d);
+ List<String> ls = new ArrayList<String>();
+ ls.add("s1");
+ ls.add("s2");
+ C c = new C();
+ c.foo(ls);
+ c.bar(ld);
+ c.goo(ld);
+ }
+}
+
+
+
+class C {
+
+ public List<String> foo(List<String> listOfStrings) { return listOfStrings; }
+
+ public List<Double> bar(List<Double> listOfDoubles) { return listOfDoubles; }
+
+ public List<? extends Number> goo(List<? extends Number> listOfSomeNumberType) { return listOfSomeNumberType; }
+
+} \ No newline at end of file
diff --git a/tests/java5/generics/ajdk/PointcutInGenericClassExample.aj b/tests/java5/generics/ajdk/PointcutInGenericClassExample.aj
new file mode 100644
index 000000000..14740403a
--- /dev/null
+++ b/tests/java5/generics/ajdk/PointcutInGenericClassExample.aj
@@ -0,0 +1,31 @@
+public class PointcutInGenericClassExample<T> {
+
+ public pointcut foo() : execution(* T.*(..));
+
+}
+
+aspect A {
+
+ declare warning : PointcutInGenericClassExample<C>.foo()
+ : "parameterized with C";
+
+ declare warning : PointcutInGenericClassExample<D>.foo()
+ : "parameterized with D";
+
+// declare warning : PointcutInGenericClassExample.foo()
+// : "raw";
+
+
+}
+
+class C {
+
+ void bar() {}
+
+}
+
+class D {
+
+ void goo() {}
+
+} \ No newline at end of file
diff --git a/tests/java5/generics/ajdk/WildcardArgsExamples.aj b/tests/java5/generics/ajdk/WildcardArgsExamples.aj
new file mode 100644
index 000000000..207563844
--- /dev/null
+++ b/tests/java5/generics/ajdk/WildcardArgsExamples.aj
@@ -0,0 +1,46 @@
+import java.util.*;
+
+public aspect WildcardArgsExamples {
+
+ before(List<? extends Number> aListOfSomeNumberType)
+ : call(* foo(..)) && args(aListOfSomeNumberType) {
+ System.out.println("advice match at " + thisJoinPointStaticPart);
+ }
+
+ before(List<? extends Number> aListOfSomeNumberType)
+ : (call(* goo*(List<Number+>)) || call(* goo*(List<? extends Number>)))
+ && args(aListOfSomeNumberType) {
+ System.out.println("advice match 2 at " + thisJoinPointStaticPart);
+ }
+
+ public static void main(String[] args) {
+ C c = new C();
+ List<String> ls = new ArrayList<String>();
+ List<Double> ld = new ArrayList<Double>();
+ c.foo("hi");
+ c.foo(ls);
+ c.foo(ld);
+ List<Number> ln = new ArrayList<Number>();
+ c.goo1(ln);
+ c.goo2(ld);
+ c.goo3(ls);
+ List<? extends Number> lsn = ln;
+ c.goo4(lsn);
+ List l = new ArrayList();
+ c.goo5(l);
+ c.goo6(new Object());
+ }
+}
+
+ class C {
+
+ public void foo(Object anObject) {}
+
+ public void goo1(List<Number> ln) {}
+ public void goo2(List<Double> ld) {}
+ public void goo3(List<String> ls) {}
+ public void goo4(List<? extends Number> lsn) {}
+ public void goo5(List l) {}
+ public void goo6(Object o) {}
+ }
+