--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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