diff options
author | aclement <aclement> | 2005-01-31 11:32:01 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-01-31 11:32:01 +0000 |
commit | 110b3d31ac12ea19c73963577fdfe18c69e5f4db (patch) | |
tree | 189df97e701774865b739127f70f220a2ea25e05 | |
parent | 4501853bf4c480479a517a714805291d04febb98 (diff) | |
download | aspectj-110b3d31ac12ea19c73963577fdfe18c69e5f4db.tar.gz aspectj-110b3d31ac12ea19c73963577fdfe18c69e5f4db.zip |
AnnotationBinding testcases: call and execution. Also verifies annotations in packages work correctly.
16 files changed, 556 insertions, 0 deletions
diff --git a/tests/java5/annotations/binding/AtTarget1.aj b/tests/java5/annotations/binding/AtTarget1.aj new file mode 100644 index 000000000..9e7f3c3ac --- /dev/null +++ b/tests/java5/annotations/binding/AtTarget1.aj @@ -0,0 +1,34 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+@Colored(color="yellow")
+public class AtTarget1 {
+ public static void main(String[]argv) {
+ new AtTarget1().m();
+ }
+
+ @Colored(color="red")
+ public void m() {
+ System.err.println("method");
+ }
+
+}
+
+aspect X {
+ int adviceExecutions = 0;
+
+ before(Colored c): call(* *(..)) && !within(X) && @target(c) {
+ System.err.println(c.color());
+ adviceExecutions++;
+
+ if (!c.color().equals("yellow"))
+ throw new RuntimeException("Color should be yellow");
+
+ if (adviceExecutions>1)
+ throw new RuntimeException("Advice shouldn't be called more than once");
+ }
+
+}
+
diff --git a/tests/java5/annotations/binding/AtTarget2.aj b/tests/java5/annotations/binding/AtTarget2.aj new file mode 100644 index 000000000..2a1f43726 --- /dev/null +++ b/tests/java5/annotations/binding/AtTarget2.aj @@ -0,0 +1,58 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Material { String material(); }
+
+@Colored(color="yellow") @Material(material="wood")
+public class AtTarget2 {
+ public static void main(String[]argv) {
+ new AtTarget2().m();
+ new SubA().m();
+ new SubB().m();
+ }
+
+ @Colored(color="red")
+ public void m() {
+ System.err.println("method running\n");
+ }
+}
+
+@Material(material="metal") @Colored(color="green")
+class SubA extends AtTarget2 { }
+
+@Material(material="jelly") @Colored(color="magenta")
+class SubB extends SubA { }
+
+aspect X {
+ int adviceexecutions = 0;
+
+ before(Colored c,Material m): call(* *(..)) && !within(X) && @target(c) && @target(m) {
+ System.err.println("advice running ("+c.color()+","+m.material()+")");
+ adviceexecutions++;
+
+ if (adviceexecutions == 1) {
+ if (!c.color().equals("yellow"))
+ throw new RuntimeException("First advice execution, color should be yellow");
+ if (!m.material().equals("wood"))
+ throw new RuntimeException("First advice execution, material should be wood");
+ }
+ if (adviceexecutions == 2) {
+ if (!c.color().equals("green"))
+ throw new RuntimeException("Second advice execution, color should be green");
+ if (!m.material().equals("metal"))
+ throw new RuntimeException("Second advice execution, material should be metal");
+ }
+ if (adviceexecutions == 3) {
+ if (!c.color().equals("magenta"))
+ throw new RuntimeException("Third advice execution, color should be magenta");
+ if (!m.material().equals("jelly"))
+ throw new RuntimeException("Third advice execution, material should be jelly");
+ }
+ if (adviceexecutions > 3)
+ throw new RuntimeException("Advice should only run twice");
+ }
+}
+
diff --git a/tests/java5/annotations/binding/AtTarget3.aj b/tests/java5/annotations/binding/AtTarget3.aj new file mode 100644 index 000000000..87dcfc0ee --- /dev/null +++ b/tests/java5/annotations/binding/AtTarget3.aj @@ -0,0 +1,40 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }
+
+public class AtTarget3 {
+ public static void main(String[]argv) {
+ new A().m();
+ new B().m();
+ new C().m();
+ }
+}
+
+@Colored(color="yellow")
+class A {
+ public void m() { System.err.println("method"); }
+}
+
+class B extends A { }
+
+@Colored(color="blue") class C extends B { }
+
+aspect X {
+ int adviceexecutions = 0;
+
+ before(Colored c): call(* *(..)) && !within(X) && @target(c) {
+ System.err.println(c.color());
+ adviceexecutions++;
+ if (adviceexecutions == 1 && !c.color().equals("yellow"))
+ throw new RuntimeException("First advice execution, color should be yellow");
+
+ // The pointcut does 'match' on call to B.m() but at runtime the annotation check fails so the advice isn't run
+
+ if (adviceexecutions == 2 && !c.color().equals("blue"))
+ throw new RuntimeException("Second advice execution, color should be blue");
+
+ if (adviceexecutions > 2)
+ throw new RuntimeException("Advice should only run twice");
+ }
+}
+
diff --git a/tests/java5/annotations/binding/AtTarget4.aj b/tests/java5/annotations/binding/AtTarget4.aj new file mode 100644 index 000000000..177eb0d11 --- /dev/null +++ b/tests/java5/annotations/binding/AtTarget4.aj @@ -0,0 +1,41 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @Inherited @interface Colored { String color(); }
+
+public class AtTarget4 {
+ public static void main(String[]argv) {
+ new A().m();
+ new B().m();
+ new C().m();
+ }
+}
+
+@Colored(color="yellow")
+class A {
+ public void m() { System.err.println("method"); }
+}
+
+class B extends A { } // inherits yellow color :)
+
+@Colored(color="blue") class C extends B { }
+
+aspect X {
+ int adviceexecutions = 0;
+
+ before(Colored c): call(* *(..)) && !within(X) && @target(c) {
+ System.err.println(c.color() + thisJoinPoint);
+ adviceexecutions++;
+ if (adviceexecutions == 1 && !c.color().equals("yellow"))
+ throw new RuntimeException("First advice execution, color should be yellow");
+
+ if (adviceexecutions == 2 && !c.color().equals("yellow"))
+ throw new RuntimeException("Second advice execution, color should be yellow");
+
+ if (adviceexecutions == 3 && !c.color().equals("blue"))
+ throw new RuntimeException("Third advice execution, color should be blue");
+
+ if (adviceexecutions > 3)
+ throw new RuntimeException("Advice should only run twice");
+ }
+}
+
diff --git a/tests/java5/annotations/binding/CallAnnBinding.aj b/tests/java5/annotations/binding/CallAnnBinding.aj new file mode 100644 index 000000000..7b6e3c11b --- /dev/null +++ b/tests/java5/annotations/binding/CallAnnBinding.aj @@ -0,0 +1,41 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+public class CallAnnBinding {
+ public static void main(String[]argv) {
+ new CallAnnBinding().m1();
+ new CallAnnBinding().m2();
+ new CallAnnBinding().m3();
+ }
+
+ @Colored(color="red")
+ public void m1() {
+ System.err.println("method1");
+ }
+
+ @Colored(color="green")
+ public void m2() {
+ System.err.println("method2");
+ }
+
+ @Colored(color="blue")
+ public void m3() {
+ System.err.println("method3");
+ }
+
+}
+
+aspect X {
+ int i = 0;
+
+ before(Colored c): call(* *(..)) && !within(X) && @annotation(c) {
+ i++;
+ if (i==1 && !c.color().equals("red")) throw new RuntimeException("First time through should be red, but is "+c.color());
+ if (i==2 && !c.color().equals("green")) throw new RuntimeException("Second time through should be green, but is "+c.color());
+ if (i==3 && !c.color().equals("blue")) throw new RuntimeException("Third time through should be blue, but is "+c.color());
+ System.err.println(c.color());
+ }
+}
+
diff --git a/tests/java5/annotations/binding/CallAnnBinding2.aj b/tests/java5/annotations/binding/CallAnnBinding2.aj new file mode 100644 index 000000000..2a36d8084 --- /dev/null +++ b/tests/java5/annotations/binding/CallAnnBinding2.aj @@ -0,0 +1,47 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+public class CallAnnBinding2 {
+ public static void main(String[]argv) {
+ SecondaryClass sc = new SecondaryClass();
+ sc.m1(1);
+ sc.m2("hello");
+ sc.m3("hello",1);
+ }
+
+}
+
+class SecondaryClass {
+
+ @Colored(color="cyan")
+ public void m1(int i) {
+ }
+
+ @Colored(color="magenta")
+ public void m2(String s) {
+ }
+
+ @Colored(color="mauve")
+ public void m3(String s,int i) {
+ }
+}
+
+aspect X {
+ int i = 0;
+
+ before(Colored c): call(* SecondaryClass.*(..)) && !within(X) && @annotation(c) {
+ i++;
+ if (i==1) checkColor(1,c,"cyan");
+ if (i==2) checkColor(2,c,"magenta");
+ if (i==3) checkColor(3,c,"mauve");
+ System.err.println(c.color());
+ }
+
+ public void checkColor(int run, Colored c,String exp) {
+ if (!c.color().equals(exp))
+ throw new RuntimeException("Advice execution #"+run+" expected "+exp+" but got "+c.color());
+ }
+}
+
diff --git a/tests/java5/annotations/binding/CallAnnBinding3.aj b/tests/java5/annotations/binding/CallAnnBinding3.aj new file mode 100644 index 000000000..c7d0e589d --- /dev/null +++ b/tests/java5/annotations/binding/CallAnnBinding3.aj @@ -0,0 +1,77 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+public class CallAnnBinding3 {
+ public static void main(String[]argv) {
+ SecondaryClass sc = new SecondaryClass();
+
+ // tackle the primitives ...
+
+ sc.m1(1); // int
+ sc.m2(true); // boolean
+ sc.m3(new Byte("3").byteValue());// byte
+ sc.m4('a'); // char
+ sc.m5(new Long(444L).longValue()); // long
+ sc.m6(new Double(3.3).doubleValue()); // double
+ sc.m7(new Float(2.2).floatValue()); // float
+ sc.m8(new Short("2").shortValue()); // short
+
+ // how about darn arrays
+
+ sc.m9(new int[]{1,2,3},new String[]{"a","b"});
+
+ // and the ultimate ... double depth dastardly arrays
+
+ String a[][] = new String[5][];
+ a[0]= new String[3];
+ sc.m10(a);
+ }
+
+}
+
+class SecondaryClass {
+
+ @Colored(color="red") public void m1(int i) { }
+ @Colored(color="orange") public void m2(boolean b) {}
+ @Colored(color="yellow") public void m3(byte b) { }
+ @Colored(color="green") public void m4(char c) { }
+ @Colored(color="blue") public void m5(long l) { }
+ @Colored(color="indigo") public void m6(double d) { }
+ @Colored(color="violet") public void m7(float f) { }
+ @Colored(color="black") public void m8(short s) { }
+
+ @Colored(color="taupe") public void m9(int[] x,String[] ss) {}
+
+ @Colored(color="beige") public void m10(String[][] s) {}
+}
+
+aspect X {
+ int i = 0;
+
+ before(Colored c): call(* SecondaryClass.*(..)) && !within(X) && @annotation(c) {
+ i++;
+ if (i==1) checkColor(1,c,"red");
+ if (i==2) checkColor(2,c,"orange");
+ if (i==3) checkColor(3,c,"yellow");
+ if (i==4) checkColor(4,c,"green");
+ if (i==5) checkColor(5,c,"blue");
+ if (i==6) checkColor(6,c,"indigo");
+ if (i==7) checkColor(6,c,"violet");
+ if (i==8) checkColor(6,c,"black");
+
+ if (i==9) checkColor(6,c,"taupe");
+
+ if (i==10) checkColor(6,c,"beige");
+
+ if (i==11) throw new RuntimeException("Advice running more times than expected");
+ System.err.println(c.color());
+ }
+
+ public void checkColor(int run, Colored c,String exp) {
+ if (!c.color().equals(exp))
+ throw new RuntimeException("Advice execution #"+run+" expected "+exp+" but got "+c.color());
+ }
+}
+
diff --git a/tests/java5/annotations/binding/CallAnnBinding4.aj b/tests/java5/annotations/binding/CallAnnBinding4.aj new file mode 100644 index 000000000..1cd1d31fc --- /dev/null +++ b/tests/java5/annotations/binding/CallAnnBinding4.aj @@ -0,0 +1,44 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+interface Marker { @Colored(color="blue") public void m1(); public void m2(); }
+
+public class CallAnnBinding4 {
+ public static void main(String[]argv) {
+ Marker marker = new SecondaryClass();
+
+ // tackle the primitives ...
+
+ marker.m1();
+ marker.m2();
+
+ if (X.i!=1) throw new RuntimeException("Why did the advice not run once?");
+ }
+
+}
+
+class SecondaryClass implements Marker {
+
+ @Colored(color="red") public void m1() {}
+ @Colored(color="orange") public void m2() {}
+}
+
+aspect X {
+ public static int i = 0;
+
+ before(Colored c): call(* m*(..)) && !within(X) && @annotation(c) {
+ i++;
+ if (i==1) checkColor(1,c,"blue");
+
+ if (i==2) throw new RuntimeException("Advice running more times than expected");
+ System.err.println(c.color());
+ }
+
+ public void checkColor(int run, Colored c,String exp) {
+ if (!c.color().equals(exp))
+ throw new RuntimeException("Advice execution #"+run+" expected "+exp+" but got "+c.color());
+ }
+}
+
diff --git a/tests/java5/annotations/binding/CallAnnBinding5.aj b/tests/java5/annotations/binding/CallAnnBinding5.aj new file mode 100644 index 000000000..281cdbe0a --- /dev/null +++ b/tests/java5/annotations/binding/CallAnnBinding5.aj @@ -0,0 +1,39 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+interface Marker { public void m1(); public void m2(); }
+
+public class CallAnnBinding5 {
+ public static void main(String[]argv) {
+ SecondaryClass sc = new SecondaryClass();
+ sc.m1();
+ sc.m2();
+ if (X.i!=1) throw new RuntimeException("Why did the advice not run?");
+ }
+
+}
+
+class SecondaryClass {
+ @Colored(color="red") public void m1() { }
+ public void m2() {}
+}
+
+aspect X {
+ public static int i = 0;
+
+ before(Colored c): call(* SecondaryClass.*(..)) && !within(X) && @annotation(c) {
+ i++;
+ if (i==1) checkColor(1,c,"red");
+
+ if (i==11) throw new RuntimeException("Advice running more times than expected");
+ System.err.println(c.color());
+ }
+
+ public void checkColor(int run, Colored c,String exp) {
+ if (!c.color().equals(exp))
+ throw new RuntimeException("Advice execution #"+run+" expected "+exp+" but got "+c.color());
+ }
+}
+
diff --git a/tests/java5/annotations/binding/CallAnnBinding6.aj b/tests/java5/annotations/binding/CallAnnBinding6.aj new file mode 100644 index 000000000..6b83a7051 --- /dev/null +++ b/tests/java5/annotations/binding/CallAnnBinding6.aj @@ -0,0 +1,37 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+public class CallAnnBinding6 {
+ public static void main(String[]argv) {
+ A b = new B();
+ b.m();
+ if (X.i!=1) throw new RuntimeException("Why did the advice not run?");
+ }
+}
+
+class A {
+ @Colored(color="RedA") public void m() {}
+}
+class B extends A {
+ @Colored(color="RedB") public void m() {}
+}
+
+aspect X {
+ public static int i = 0;
+
+ before(Colored c): call(* m*(..)) && !within(X) && @annotation(c) {
+ i++;
+ if (i==1) checkColor(1,c,"RedA");
+
+ if (i==11) throw new RuntimeException("Advice running more times than expected");
+ System.err.println(c.color());
+ }
+
+ public void checkColor(int run, Colored c,String exp) {
+ if (!c.color().equals(exp))
+ throw new RuntimeException("Advice execution #"+run+" expected "+exp+" but got "+c.color());
+ }
+}
+
diff --git a/tests/java5/annotations/binding/ExecutionAnnBinding1.aj b/tests/java5/annotations/binding/ExecutionAnnBinding1.aj new file mode 100644 index 000000000..dcb319bf2 --- /dev/null +++ b/tests/java5/annotations/binding/ExecutionAnnBinding1.aj @@ -0,0 +1,44 @@ +import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color(); }
+
+public class ExecutionAnnBinding1 {
+ public static void main(String[]argv) {
+ new ExecutionAnnBinding1().m1();
+ new ExecutionAnnBinding1().m2();
+ new ExecutionAnnBinding1().m3();
+ }
+
+ @Colored(color="red")
+ public void m1() {
+ System.err.println("method1");
+ }
+
+ @Colored(color="green")
+ public void m2() {
+ System.err.println("method2");
+ }
+
+ @Colored(color="blue")
+ public void m3() {
+ System.err.println("method3");
+ }
+
+}
+
+aspect X {
+ int i = 0;
+
+ before(Colored c): execution(* *(..)) && !within(X) && @annotation(c) {
+ i++;
+ if (i==1 && !c.color().equals("red"))
+ throw new RuntimeException("First time through should be red, but is "+c.color());
+ if (i==2 && !c.color().equals("green"))
+ throw new RuntimeException("Second time through should be green, but is "+c.color());
+ if (i==3 && !c.color().equals("blue"))
+ throw new RuntimeException("Third time through should be blue, but is "+c.color());
+ System.err.println(c.color());
+ }
+}
+
diff --git a/tests/java5/annotations/binding/complexExample/A.java b/tests/java5/annotations/binding/complexExample/A.java new file mode 100644 index 000000000..92ffd35af --- /dev/null +++ b/tests/java5/annotations/binding/complexExample/A.java @@ -0,0 +1,16 @@ +package a.b.c; +import g.h.i.B; + +import d.e.f.*; + +public class A { + public static void main(String []argv) { + new A().a(); + new B().b(); + } + + @Color("blue") + public void a() { + System.err.println("a.b.c.A.a() running"); + } +} diff --git a/tests/java5/annotations/binding/complexExample/B.java b/tests/java5/annotations/binding/complexExample/B.java new file mode 100644 index 000000000..6bb11cbf2 --- /dev/null +++ b/tests/java5/annotations/binding/complexExample/B.java @@ -0,0 +1,8 @@ +package g.h.i; + +import d.e.f.*; + +public class B { + + @Color("red") public void b() { System.err.println("g.h.i.B.b running");} +} diff --git a/tests/java5/annotations/binding/complexExample/Color.java b/tests/java5/annotations/binding/complexExample/Color.java new file mode 100644 index 000000000..e0fca4e35 --- /dev/null +++ b/tests/java5/annotations/binding/complexExample/Color.java @@ -0,0 +1,3 @@ +package d.e.f; +import java.lang.annotation.*; +@Retention(RetentionPolicy.RUNTIME) public @interface Color {String value();} diff --git a/tests/java5/annotations/binding/complexExample/X.java b/tests/java5/annotations/binding/complexExample/X.java new file mode 100644 index 000000000..b442e3a99 --- /dev/null +++ b/tests/java5/annotations/binding/complexExample/X.java @@ -0,0 +1,13 @@ +// Color should be resolved via the import statement... +import d.e.f.Color; + +public aspect X { + + before(): call(* *(..)) && @annotation(@Color) { + System.err.println("Before call to "+thisJoinPoint); + } + + before(): execution(* *(..)) && @annotation(@Color) { + System.err.println("Before execution of "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/binding/complexExample/X2.java b/tests/java5/annotations/binding/complexExample/X2.java new file mode 100644 index 000000000..717f80108 --- /dev/null +++ b/tests/java5/annotations/binding/complexExample/X2.java @@ -0,0 +1,14 @@ +// Same as X but includes annotation binding +import d.e.f.Color; + +public aspect X2 { + + before(Color c): call(* *(..)) && @annotation(c) { + System.err.println("Before call to "+thisJoinPoint+" color is "+c); + } + + before(Color c): execution(* *(..)) && @annotation(c) { + System.err.println("Before execution of "+thisJoinPoint+" color is "+c); + } + +} |