--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }\r
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value(); }\r
+\r
+@Colored(color="yellow") @Fruit("banana") class YB {}\r
+@Colored(color="green") @Fruit("apple") class GA {}\r
+@Colored(color="red") @Fruit("tomato") class RT {}\r
+\r
+public class AtArgs1 {\r
+ public static void main(String[]argv) {\r
+ m(new YB(),new GA(),new RT());\r
+\r
+ X.verify();\r
+ }\r
+\r
+ public static void m(Object a,Object b,Object c) { }\r
+\r
+}\r
+\r
+aspect X {\r
+\r
+ static int count = 0;\r
+\r
+ before(Colored c1,Colored c2,Colored c3): call(* m(..)) && !within(X) && @args(c1,c2,c3) {\r
+ System.err.println("Colors are "+c1.color()+","+c2.color()+","+c3.color());\r
+ count++;\r
+ if (!c1.color().equals("yellow")) \r
+ throw new RuntimeException("Color1 should be yellow");\r
+ if (!c2.color().equals("green")) \r
+ throw new RuntimeException("Color2 should be green");\r
+ if (!c3.color().equals("red")) \r
+ throw new RuntimeException("Color3 should be red");\r
+ \r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=1) throw new Error("Should be 1 run: "+count);\r
+ }\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }\r
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value(); }\r
+\r
+@Colored(color="yellow") @Fruit("banana") class YB {}\r
+\r
+public class AtArgs2 {\r
+ public static void main(String[]argv) {\r
+ m(new YB());\r
+ if (!X.run) throw new Error("Advice should have run");\r
+ }\r
+\r
+ public static void m(Object a) {}\r
+\r
+}\r
+\r
+aspect X {\r
+ public static boolean run = false;\r
+ before(Colored c): call(* m(..)) && !within(X) && @args(c) {\r
+ System.err.println("Color is "+c.color());\r
+ run = true;\r
+ if (!c.color().equals("yellow")) \r
+ throw new RuntimeException("Color should be yellow: "+c.color());\r
+ }\r
+\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }\r
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value(); }\r
+\r
+@Colored(color="yellow") @Fruit("banana") class YB {}\r
+\r
+public class AtArgs3 {\r
+ public static void main(String[]argv) {\r
+ m(new YB());\r
+ if (!X.b)\r
+ throw new Error("Advice should have run");\r
+ }\r
+\r
+ public static void m(Object a) {}\r
+\r
+}\r
+\r
+aspect X {\r
+\r
+ static boolean b = false;\r
+\r
+ before(): call(* m(..)) && !within(X) && @args(@Colored) {\r
+ b=true;\r
+ }\r
+\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }\r
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value(); }\r
+\r
+@Colored(color="yellow") @Fruit("banana") class YB {}\r
+@Colored(color="green") @Fruit("apple") class GA {}\r
+@Colored(color="red") @Fruit("tomato") class RT {}\r
+\r
+public class AtArgs4 {\r
+ public static void main(String[]argv) {\r
+ m(new YB(),new GA(),new RT());\r
+ X.verify();\r
+ }\r
+\r
+ public static void m(Object a,Object b,Object c) { }\r
+\r
+}\r
+\r
+aspect X {\r
+ static int count = 0;\r
+\r
+ before(Colored c1,Fruit f,Colored c2): call(* m(..)) && !within(X) && @args(c1,f,c2) {\r
+ System.err.println("Two colors:"+c1.color()+","+c2.color());\r
+ System.err.println("Fruit is:"+f.value());\r
+ count++;\r
+ if (!c1.color().equals("yellow")) \r
+ throw new RuntimeException("Color1 should be yellow");\r
+ if (!f.value().equals("apple")) \r
+ throw new RuntimeException("Fruit should be apple");\r
+ if (!c2.color().equals("red")) \r
+ throw new RuntimeException("Color2 should be red");\r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=1) throw new Error("Should be 1 run: "+count);\r
+ }\r
+\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }\r
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value(); }\r
+\r
+@Colored(color="yellow") @Fruit("banana") class YB {}\r
+@Colored(color="green") @Fruit("apple") class GA {}\r
+@Colored(color="red") @Fruit("tomato") class RT {}\r
+\r
+public class AtArgs5 {\r
+ public static void main(String[]argv) {\r
+ m(new YB(),new GA(),new RT());\r
+ }\r
+\r
+ public static void m(Object a,Object b,Object c) { }\r
+\r
+}\r
+\r
+aspect X {\r
+ static int count = 0;\r
+\r
+ before(Colored c1,Fruit f,Colored c2): execution(* m(..)) && !within(X) && @args(c1,f,c2) {\r
+ System.err.println("Two colors:"+c1.color()+","+c2.color());\r
+ System.err.println("Fruit is:"+f.value());\r
+ count++;\r
+ if (!c1.color().equals("yellow")) \r
+ throw new RuntimeException("Color1 should be yellow");\r
+ if (!f.value().equals("apple")) \r
+ throw new RuntimeException("Fruit should be apple");\r
+ if (!c2.color().equals("red")) \r
+ throw new RuntimeException("Color2 should be red");\r
+ \r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=3) throw new Error("Should be 3 runs: "+count);\r
+ }\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+@Colored(color="yellow")\r
+public class AtThis1 {\r
+ public static void main(String[]argv) {\r
+ new AtThis1().m();\r
+ X.verify();\r
+ }\r
+\r
+ @Colored(color="red")\r
+ public void m() {\r
+ System.err.println("method");\r
+ }\r
+\r
+}\r
+\r
+aspect X {\r
+ static int count = 0;\r
+\r
+ before(Colored c): call(* *(..)) && !within(X) && @this(c) {\r
+ System.err.println(thisJoinPoint+" > "+c.color());\r
+ count++;\r
+ \r
+ if (!c.color().equals("yellow")) \r
+ throw new RuntimeException("Color should be yellow");\r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=1) throw new Error("Should be 1 run: "+count);\r
+ }\r
+\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Material { String material(); }\r
+\r
+@Colored(color="yellow") @Material(material="wood")\r
+public class AtThis2 {\r
+ public static void main(String[]argv) {\r
+ new AtThis2().start();\r
+ new SubA().start();\r
+ new SubB().start();\r
+ X.verify();\r
+ }\r
+\r
+ @Colored(color="red")\r
+ public void m() {\r
+ System.err.println("method running\n");\r
+ }\r
+ public void start() { m(); }\r
+}\r
+\r
+@Material(material="metal") @Colored(color="green")\r
+class SubA extends AtThis2 { }\r
+\r
+@Material(material="jelly") @Colored(color="magenta")\r
+class SubB extends SubA { }\r
+\r
+aspect X {\r
+ static int count = 0;\r
+\r
+ before(Colored c,Material m): call(* m(..)) && !within(X) && @this(c) && @this(m) {\r
+ System.err.println("advice running ("+c.color()+","+m.material()+")");\r
+ count++;\r
+ \r
+ if (count== 1) {\r
+ if (!c.color().equals("yellow"))\r
+ throw new RuntimeException("First advice execution, color should be yellow:"+c.color());\r
+ if (!m.material().equals("wood"))\r
+ throw new RuntimeException("First advice execution, material should be wood:"+m.material());\r
+ }\r
+ if (count == 2) {\r
+ if (!c.color().equals("green"))\r
+ throw new RuntimeException("Second advice execution, color should be green");\r
+ if (!m.material().equals("metal"))\r
+ throw new RuntimeException("Second advice execution, material should be metal");\r
+ }\r
+ if (count == 3) {\r
+ if (!c.color().equals("magenta"))\r
+ throw new RuntimeException("Third advice execution, color should be magenta");\r
+ if (!m.material().equals("jelly"))\r
+ throw new RuntimeException("Third advice execution, material should be jelly");\r
+ }\r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=3) throw new Error("Should be 3 runs: "+count);\r
+ }\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }\r
+\r
+public class AtThis3 {\r
+ public static void main(String[]argv) {\r
+ new A().start();\r
+ new B().start();\r
+ new C().start();\r
+ X.verify();\r
+ }\r
+}\r
+\r
+@Colored(color="yellow")\r
+class A {\r
+ public void start() { m();}\r
+ public void m() { System.err.println("method"); }\r
+}\r
+\r
+class B extends A { }\r
+\r
+@Colored(color="blue") class C extends B { }\r
+\r
+aspect X {\r
+ static int count = 0;\r
+\r
+ before(Colored c): call(* m(..)) && !within(X) && @this(c) {\r
+ System.err.println(c.color());\r
+ count++;\r
+ if (count == 1 && !c.color().equals("yellow"))\r
+ throw new RuntimeException("First advice execution, color should be yellow");\r
+ \r
+ // The pointcut does 'match' on call to B.m() but at runtime the\r
+ // annotation check fails so the advice isn't run\r
+\r
+ if (count == 2 && !c.color().equals("blue"))\r
+ throw new RuntimeException("Second advice execution, color should be blue");\r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=2) throw new Error("Should be 2 runs: "+count);\r
+ }\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @Inherited @interface Colored { String color(); }\r
+\r
+public class AtThis4 {\r
+ public static void main(String[]argv) {\r
+ new A().start();\r
+ new B().start();\r
+ new C().start();\r
+ X.verify();\r
+ }\r
+}\r
+\r
+@Colored(color="yellow")\r
+class A {\r
+ public void start() { m();} // Can't match @this() on calls from static method, \r
+ // hence this start() method...\r
+ public void m() { System.err.println("method"); }\r
+}\r
+\r
+class B extends A { } // inherits yellow color :)\r
+\r
+@Colored(color="blue") class C extends B { }\r
+\r
+aspect X {\r
+ static int count = 0;\r
+\r
+ before(Colored c): call(* m(..)) && !within(X) && @this(c) {\r
+ System.err.println(c.color() + thisJoinPoint);\r
+ count++;\r
+ if (count == 1 && !c.color().equals("yellow"))\r
+ throw new RuntimeException("First advice execution, color should be yellow");\r
+ \r
+ if (count == 2 && !c.color().equals("yellow"))\r
+ throw new RuntimeException("Second advice execution, color should be yellow");\r
+ \r
+ if (count == 3 && !c.color().equals("blue"))\r
+ throw new RuntimeException("Third advice execution, color should be blue");\r
+ \r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=3) throw new Error("Should be 3 runs: "+count);\r
+ }\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME) @Inherited @interface Colored { String color(); }\r
+\r
+public class AtThis5 {\r
+ public static void main(String[]argv) {\r
+ new A().start(new B());\r
+ new B().start(new C());\r
+ new C().start(new A());\r
+ X.verify();\r
+ }\r
+}\r
+\r
+@Colored(color="yellow")\r
+class A {\r
+ public void start(A a) { a.m();} // Can't match @this() on calls from static method, \r
+ // hence this start() method...\r
+ public void m() { System.err.println("method"); }\r
+}\r
+\r
+class B extends A { } // inherits yellow color :)\r
+\r
+@Colored(color="blue") class C extends B { }\r
+\r
+aspect X {\r
+ static int count = 0;\r
+\r
+ before(Colored cThis,Colored cTarg): \r
+ call(* m(..)) && !within(X) && @this(cThis) && @target(cTarg) {\r
+\r
+ count++;\r
+ if (count == 1 && \r
+ !(cThis.color().equals("yellow") && cTarg.color().equals("yellow")))\r
+ throw new RuntimeException("1st run, colors should be yellow:yellow but are "+\r
+ cThis.color()+":"+cTarg.color());\r
+ \r
+ if (count == 2 &&\r
+ !(cThis.color().equals("yellow") && cTarg.color().equals("blue")))\r
+ throw new RuntimeException("2nd run, colors should be yellow:blue but are "+\r
+ cThis.color()+":"+cTarg.color());\r
+ \r
+ if (count == 3 && \r
+ !(cThis.color().equals("blue") && cTarg.color().equals("yellow")))\r
+ throw new RuntimeException("3rd run, colors should be blue:yellow but are "+\r
+ cThis.color()+":"+cTarg.color());\r
+ \r
+ if (count > 3) \r
+ throw new RuntimeException("Advice should only run three times");\r
+ }\r
+\r
+ public static void verify() {\r
+ if (count!=3) throw new Error("Should be 3 runs: "+count);\r
+ }\r
+}\r
+\r
--- /dev/null
+import java.lang.annotation.*;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@interface Colored { String color(); }\r
+\r
+public class CallAnnBinding7 {\r
+ public static void main(String[]argv) {\r
+ new CallAnnBinding7().m1();\r
+ new CallAnnBinding7().m2();\r
+ new CallAnnBinding7().m3();\r
+ }\r
+\r
+ @Colored(color="red")\r
+ public void m1() {\r
+ System.err.println("method1");\r
+ }\r
+\r
+ @Colored(color="green")\r
+ public void m2() {\r
+ System.err.println("method2");\r
+ }\r
+\r
+ @Colored(color="blue")\r
+ public void m3() {\r
+ System.err.println("method3");\r
+ }\r
+\r
+}\r
+\r
+aspect X {\r
+ int i = 0;\r
+\r
+ pointcut p(Colored c): call(* *(..)) && !within(X) && @annotation(c);\r
+ \r
+ before(Colored c): p(c) {\r
+ i++;\r
+ if (i==1 && !c.color().equals("red")) throw new RuntimeException("First time through should be red, but is "+c.color());\r
+ if (i==2 && !c.color().equals("green")) throw new RuntimeException("Second time through should be green, but is "+c.color());\r
+ if (i==3 && !c.color().equals("blue")) throw new RuntimeException("Third time through should be blue, but is "+c.color());\r
+ System.err.println(c.color());\r
+ }\r
+}\r
+\r