aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5
diff options
context:
space:
mode:
authoraclement <aclement>2005-02-17 09:10:50 +0000
committeraclement <aclement>2005-02-17 09:10:50 +0000
commit3534aad5edf1adc9d3167c5f70c141e1fbeafc94 (patch)
treea7f3ed0561e3cf14886854d18eec71037ed6aeb0 /tests/java5
parent200fd222d63578de1dc891fa211b7bcf03c7655d (diff)
downloadaspectj-3534aad5edf1adc9d3167c5f70c141e1fbeafc94.tar.gz
aspectj-3534aad5edf1adc9d3167c5f70c141e1fbeafc94.zip
Testcases for @within() and @withincode() binding.
Diffstat (limited to 'tests/java5')
-rw-r--r--tests/java5/annotations/binding/WithinBinding1.aj44
-rw-r--r--tests/java5/annotations/binding/WithinBinding2.aj46
-rw-r--r--tests/java5/annotations/binding/WithinCodeBinding1.aj44
3 files changed, 134 insertions, 0 deletions
diff --git a/tests/java5/annotations/binding/WithinBinding1.aj b/tests/java5/annotations/binding/WithinBinding1.aj
new file mode 100644
index 000000000..68b617c0d
--- /dev/null
+++ b/tests/java5/annotations/binding/WithinBinding1.aj
@@ -0,0 +1,44 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color();}
+
+@Colored(color="red")
+public class WithinBinding1 {
+
+ void mRed() {System.out.println("red"); }
+
+ void mBlue() {System.out.println("blue");}
+
+ void mGreen() {System.out.println("green");}
+
+ WithinBinding1() {
+ System.out.println("yellow");
+ }
+
+ public static void main(String[]argv) {
+ WithinBinding1 instance = new WithinBinding1();
+ instance.mRed();
+ instance.mBlue();
+ instance.mGreen();
+ X.verifyRun();
+ }
+}
+
+aspect X {
+
+ static int maxruns = 21; // there are 21 join points in a run of WithinBinding1.main()
+
+ static int i = 0; // Count of advice executions
+
+ before(Colored c): @within(c) {
+ System.err.println(thisJoinPoint+" color="+c.color());
+ if (!c.color().equals("red")) throw new RuntimeException("not red? "+c.color());
+ i++;
+ }
+
+ public static void verifyRun() {
+ if (X.i != maxruns)
+ throw new RuntimeException("Expected "+maxruns+" advice runs but did "+X.i);
+ }
+}
diff --git a/tests/java5/annotations/binding/WithinBinding2.aj b/tests/java5/annotations/binding/WithinBinding2.aj
new file mode 100644
index 000000000..8881a26b4
--- /dev/null
+++ b/tests/java5/annotations/binding/WithinBinding2.aj
@@ -0,0 +1,46 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color();}
+
+@Colored(color="red") class RedClass {
+ public void m() { System.err.println("RedClass.m() running"); }
+}
+
+@Colored(color="green") class GreenClass {
+ public GreenClass() { System.err.println("GreenClass.ctor() running"); }
+ public void m() { System.err.println("GreenClass.m() running"); }
+}
+
+class NormalClass {
+ public void m() { System.err.println("NormalClass.m() running"); }
+}
+
+
+public class WithinBinding2 {
+ public static void main(String[]argv) {
+ new RedClass().m();
+ new NormalClass().m();
+ new GreenClass().m();
+ X.verifyRun();
+ }
+}
+
+aspect X {
+
+ static int red = 0;
+ static int green=0;
+
+ before(Colored c): @within(c) {
+ System.err.println(thisJoinPoint+" color="+c.color());
+ if (c.color().startsWith("r")) red++;
+ else if (c.color().startsWith("g")) green++;
+ else throw new RuntimeException("Didn't expect this color: "+c.color());
+ }
+
+ public static void verifyRun() {
+ System.err.println(red+" "+green);
+ if (red!=7) throw new RuntimeException("Expected 7 red join points but got "+red);
+ if (green!=9) throw new RuntimeException("Expected 9 green join points but got "+green);
+ }
+}
diff --git a/tests/java5/annotations/binding/WithinCodeBinding1.aj b/tests/java5/annotations/binding/WithinCodeBinding1.aj
new file mode 100644
index 000000000..2754c15ea
--- /dev/null
+++ b/tests/java5/annotations/binding/WithinCodeBinding1.aj
@@ -0,0 +1,44 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Colored { String color();}
+
+public class WithinCodeBinding1 {
+
+ @Colored(color="red") void mRed() {System.out.println("red"); }
+
+ @Colored(color="blue") void mBlue() {System.out.println("blue");}
+
+ @Colored(color="green") void mGreen() {System.out.println("green");}
+
+ @Colored(color="yellow") WithinCodeBinding1() {
+ System.out.println("yellow");
+ }
+
+ public static void main(String[]argv) {
+ WithinCodeBinding1 instance = new WithinCodeBinding1();
+ instance.mRed();
+ instance.mBlue();
+ instance.mGreen();
+ X.verifyRun();
+ }
+}
+
+aspect X {
+
+ // Expected color order
+ static String exp[] = new String[]{"yellow","red","blue","green"};
+
+ static int i = 0; // Count of advice executions
+
+ before(Colored c): @withincode(c) && call(* println(..)) {
+ System.err.println(thisJoinPoint+" color="+c.color());
+ if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());
+ i++;
+ }
+
+ public static void verifyRun() {
+ if (X.i != exp.length)
+ throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);
+ }
+}