]> source.dussan.org Git - aspectj.git/commitdiff
Annotation Binding - more test data.
authoraclement <aclement>
Tue, 1 Feb 2005 08:03:33 +0000 (08:03 +0000)
committeraclement <aclement>
Tue, 1 Feb 2005 08:03:33 +0000 (08:03 +0000)
tests/java5/annotations/binding/AdviceExecBinding.aj [new file with mode: 0644]
tests/java5/annotations/binding/CtorAnnBinding1.aj [new file with mode: 0644]
tests/java5/annotations/binding/CtorAnnBinding2.aj [new file with mode: 0644]
tests/java5/annotations/binding/FieldAnnBinding1.aj [new file with mode: 0644]
tests/java5/annotations/binding/FieldAnnBinding2.aj [new file with mode: 0644]
tests/java5/annotations/binding/FieldAnnBinding3.aj [new file with mode: 0644]
tests/java5/annotations/binding/HandlerBinding.aj [new file with mode: 0644]
tests/java5/annotations/binding/InitBinding.aj [new file with mode: 0644]
tests/java5/annotations/binding/PreInitBinding.aj [new file with mode: 0644]
tests/java5/annotations/binding/StaticInitBinding.aj [new file with mode: 0644]

diff --git a/tests/java5/annotations/binding/AdviceExecBinding.aj b/tests/java5/annotations/binding/AdviceExecBinding.aj
new file mode 100644 (file)
index 0000000..6771928
--- /dev/null
@@ -0,0 +1,43 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class AdviceExecBinding {\r
+  public static void main(String[]argv) {\r
+    m1();\r
+    m2();\r
+    m3();\r
+    X.verifyRun();\r
+  }\r
+\r
+  static void m1() {}\r
+  static void m2() {}\r
+  static void m3() {}\r
+}\r
+\r
+aspect B {\r
+  @Colored(color="orange") before(): execution(* m1()) {}\r
+  @Colored(color="yellow") before(): execution(* m2()) {}\r
+  @Colored(color="brown")  before(): execution(* m3()) {}\r
+}\r
+\r
+aspect X {\r
\r
+  // Expected color order\r
+  static String exp[] = new String[]{"orange","yellow","brown"};\r
+  \r
+  static int i = 0; // Count of advice executions\r
+  \r
+  before(Colored c): adviceexecution() && within(B) && @annotation(c) {\r
+    System.err.println(thisJoinPoint+" color="+c.color());\r
+       if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+       i++;\r
+  }\r
+  \r
+  public static void verifyRun() {\r
+       if (X.i != exp.length)\r
+               throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+  }\r
+}\r
+\r
diff --git a/tests/java5/annotations/binding/CtorAnnBinding1.aj b/tests/java5/annotations/binding/CtorAnnBinding1.aj
new file mode 100644 (file)
index 0000000..613af3b
--- /dev/null
@@ -0,0 +1,41 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class CtorAnnBinding1 {\r
+  public static void main(String[]argv) {\r
+    new C();\r
+    new C("hello");\r
+    new C(new int[]{1,2,3});\r
+    X.verifyRun();\r
+  }\r
+\r
+  static class C {\r
+\r
+    @Colored(color="red")   public C() {System.err.println("<init>() running");}\r
+    @Colored(color="green") public C(String s) {System.err.println("<init>("+s+") running");}\r
+    @Colored(color="blue")  public C(int[] is) {System.err.println("<init>(int[]) running");}\r
+                            public C(boolean b) {System.err.println("<init>("+b+") running");}\r
+  }\r
+\r
+}\r
+\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"red","green","blue"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c): call(new(..)) && withincode(* main(..)) && @annotation(c) {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+}
\ No newline at end of file
diff --git a/tests/java5/annotations/binding/CtorAnnBinding2.aj b/tests/java5/annotations/binding/CtorAnnBinding2.aj
new file mode 100644 (file)
index 0000000..f67e874
--- /dev/null
@@ -0,0 +1,41 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class CtorAnnBinding2 {\r
+  public static void main(String[]argv) {\r
+    new C();\r
+    new C("hello");\r
+    new C(new int[]{1,2,3});\r
+    X.verifyRun();\r
+  }\r
+\r
+  static class C {\r
+\r
+    @Colored(color="red")   public C() {System.err.println("<init>() running");}\r
+    @Colored(color="green") public C(String s) {System.err.println("<init>("+s+") running");}\r
+    @Colored(color="blue")  public C(int[] is) {System.err.println("<init>(int[]) running");}\r
+    public C(boolean b) {System.err.println("<init>("+b+") running");}\r
+  }\r
+\r
+}\r
+\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"red","green","blue"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c): execution(new(..)) && within(CtorAnnBinding2) && @annotation(c) {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+}
\ No newline at end of file
diff --git a/tests/java5/annotations/binding/FieldAnnBinding1.aj b/tests/java5/annotations/binding/FieldAnnBinding1.aj
new file mode 100644 (file)
index 0000000..68f8c33
--- /dev/null
@@ -0,0 +1,39 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color();}\r
+\r
+public class FieldAnnBinding1 {\r
+\r
+  @Colored(color="red") static int i;\r
+\r
+  @Colored(color="blue") String s;\r
+\r
+  @Colored(color="green") boolean b;\r
+\r
+  public static void main(String[]argv) {\r
+    i = 5;\r
+    new FieldAnnBinding1().s = "abc";\r
+    new FieldAnnBinding1().b = true;\r
+    X.verifyRun();\r
+  }\r
+}\r
+\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"red","blue","green"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c): set(* *) && withincode(* main(..)) && @annotation(c)  {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+}\r
diff --git a/tests/java5/annotations/binding/FieldAnnBinding2.aj b/tests/java5/annotations/binding/FieldAnnBinding2.aj
new file mode 100644 (file)
index 0000000..5c52594
--- /dev/null
@@ -0,0 +1,43 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color();}\r
+\r
+public class FieldAnnBinding2 {\r
+\r
+  @Colored(color="red") static int i;\r
+\r
+  @Colored(color="blue") String s;\r
+\r
+  @Colored(color="green") boolean b;\r
+\r
+  public static void main(String[]argv) {\r
+    FieldAnnBinding2 fab = new FieldAnnBinding2();\r
+    i = 5;\r
+    fab.s = "abc";\r
+    fab.b = true;\r
+\r
+    System.err.println("i="+fab.i);\r
+    System.err.println("s="+fab.s);\r
+    System.err.println("b="+fab.b);\r
+    X.verifyRun();\r
+  }\r
+}\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"red","blue","green"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c): get(* *) && withincode(* main(..)) && @annotation(c) {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+}\r
diff --git a/tests/java5/annotations/binding/FieldAnnBinding3.aj b/tests/java5/annotations/binding/FieldAnnBinding3.aj
new file mode 100644 (file)
index 0000000..a6ccb68
--- /dev/null
@@ -0,0 +1,39 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color();}\r
+\r
+public class FieldAnnBinding3 {\r
+\r
+  @Colored(color="red")  String s[];\r
+\r
+  @Colored(color="blue") boolean b[];\r
+\r
+  public static void main(String[]argv) {\r
+    FieldAnnBinding3 fab = new FieldAnnBinding3();\r
+    fab.s = new String[]{"abc","def"};\r
+    fab.b = new boolean[]{true,false,true};\r
+\r
+    System.err.println("s="+fab.s);\r
+    System.err.println("b="+fab.b);\r
+    X.verifyRun();\r
+  }\r
+}\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"red","blue"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c): get(* *) && withincode(* main(..)) && @annotation(c) {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+}
\ No newline at end of file
diff --git a/tests/java5/annotations/binding/HandlerBinding.aj b/tests/java5/annotations/binding/HandlerBinding.aj
new file mode 100644 (file)
index 0000000..fc2d0d3
--- /dev/null
@@ -0,0 +1,40 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class HandlerBinding {\r
+  public static void main(String[]argv) {\r
+    try {\r
+      throw new AndyException();\r
+    } catch (AndyException ae) {\r
+      System.err.println(ae);\r
+    }\r
+    X.verifyRun();\r
+  }\r
+\r
+  @Colored(color="red") static class AndyException extends Exception {\r
+    public AndyException() {\r
+    }\r
+  }\r
+\r
+}\r
+\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"red"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c): handler(*) && !within(X) && @annotation(c) {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+       }\r
diff --git a/tests/java5/annotations/binding/InitBinding.aj b/tests/java5/annotations/binding/InitBinding.aj
new file mode 100644 (file)
index 0000000..87e8cac
--- /dev/null
@@ -0,0 +1,42 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class InitBinding {\r
+  public static void main(String[]argv) {\r
+    new A();\r
+    new B();\r
+    new C();\r
+    X.verifyRun();\r
+  }\r
+}\r
+\r
+class A {\r
+@Colored(color="orange") public A() {}\r
+}\r
+class B {\r
+@Colored(color="yellow") public B() {}\r
+}\r
+class C {\r
+@Colored(color="brown") public C() {}\r
+}\r
+\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"orange","yellow","brown"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c):  preinitialization(new(..)) && !within(X) && @annotation(c)  {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+       }\r
diff --git a/tests/java5/annotations/binding/PreInitBinding.aj b/tests/java5/annotations/binding/PreInitBinding.aj
new file mode 100644 (file)
index 0000000..92c6d1a
--- /dev/null
@@ -0,0 +1,43 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class PreInitBinding {\r
+  public static void main(String[]argv) {\r
+    new A();\r
+    new B();\r
+    new C();\r
+    X.verifyRun();\r
+  }\r
+}\r
+\r
+class A {\r
+@Colored(color="orange") public A() {}\r
+}\r
+class B {\r
+@Colored(color="yellow") public B() {}\r
+}\r
+class C {\r
+@Colored(color="brown") public C() {}\r
+}\r
+\r
+\r
+aspect X {\r
+        \r
+         // Expected color order\r
+         static String exp[] = new String[]{"orange","yellow","brown"};\r
+         \r
+         static int i = 0; // Count of advice executions\r
+         \r
+         before(Colored c): preinitialization(new(..)) && !within(X) && @annotation(c) {\r
+           System.err.println(thisJoinPoint+" color="+c.color());\r
+               if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+               i++;\r
+         }\r
+         \r
+         public static void verifyRun() {\r
+               if (X.i != exp.length)\r
+                       throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+         }\r
+       }\r
diff --git a/tests/java5/annotations/binding/StaticInitBinding.aj b/tests/java5/annotations/binding/StaticInitBinding.aj
new file mode 100644 (file)
index 0000000..7473daf
--- /dev/null
@@ -0,0 +1,37 @@
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class StaticInitBinding {\r
+  public static void main(String[]argv) {\r
+    new A();\r
+    new B();\r
+    new C();\r
+    X.verifyRun();\r
+  }\r
+}\r
+\r
+@Colored(color="orange") class A {}\r
+@Colored(color="yellow") class B {}\r
+@Colored(color="brown") class C {}\r
+\r
+\r
+aspect X {\r
\r
+  // Expected color order\r
+  static String exp[] = new String[]{"orange","yellow","brown"};\r
+  \r
+  static int i = 0; // Count of advice executions\r
+  \r
+  before(Colored c): staticinitialization(*) && !within(X) && @annotation(c) {\r
+    System.err.println(thisJoinPoint+" color="+c.color());\r
+       if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());\r
+       i++;\r
+  }\r
+  \r
+  public static void verifyRun() {\r
+       if (X.i != exp.length)\r
+               throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);\r
+  }\r
+}
\ No newline at end of file