Browse Source

Annotation Binding - more test data.

tags/Root_AspectJ5_Development
aclement 19 years ago
parent
commit
fd3b7dc534

+ 43
- 0
tests/java5/annotations/binding/AdviceExecBinding.aj View File

@@ -0,0 +1,43 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
public class AdviceExecBinding {
public static void main(String[]argv) {
m1();
m2();
m3();
X.verifyRun();
}
static void m1() {}
static void m2() {}
static void m3() {}
}
aspect B {
@Colored(color="orange") before(): execution(* m1()) {}
@Colored(color="yellow") before(): execution(* m2()) {}
@Colored(color="brown") before(): execution(* m3()) {}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"orange","yellow","brown"};
static int i = 0; // Count of advice executions
before(Colored c): adviceexecution() && within(B) && @annotation(c) {
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);
}
}

+ 41
- 0
tests/java5/annotations/binding/CtorAnnBinding1.aj View File

@@ -0,0 +1,41 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
public class CtorAnnBinding1 {
public static void main(String[]argv) {
new C();
new C("hello");
new C(new int[]{1,2,3});
X.verifyRun();
}
static class C {
@Colored(color="red") public C() {System.err.println("<init>() running");}
@Colored(color="green") public C(String s) {System.err.println("<init>("+s+") running");}
@Colored(color="blue") public C(int[] is) {System.err.println("<init>(int[]) running");}
public C(boolean b) {System.err.println("<init>("+b+") running");}
}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"red","green","blue"};
static int i = 0; // Count of advice executions
before(Colored c): call(new(..)) && withincode(* main(..)) && @annotation(c) {
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);
}
}

+ 41
- 0
tests/java5/annotations/binding/CtorAnnBinding2.aj View File

@@ -0,0 +1,41 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
public class CtorAnnBinding2 {
public static void main(String[]argv) {
new C();
new C("hello");
new C(new int[]{1,2,3});
X.verifyRun();
}
static class C {
@Colored(color="red") public C() {System.err.println("<init>() running");}
@Colored(color="green") public C(String s) {System.err.println("<init>("+s+") running");}
@Colored(color="blue") public C(int[] is) {System.err.println("<init>(int[]) running");}
public C(boolean b) {System.err.println("<init>("+b+") running");}
}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"red","green","blue"};
static int i = 0; // Count of advice executions
before(Colored c): execution(new(..)) && within(CtorAnnBinding2) && @annotation(c) {
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);
}
}

+ 39
- 0
tests/java5/annotations/binding/FieldAnnBinding1.aj View File

@@ -0,0 +1,39 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color();}
public class FieldAnnBinding1 {
@Colored(color="red") static int i;
@Colored(color="blue") String s;
@Colored(color="green") boolean b;
public static void main(String[]argv) {
i = 5;
new FieldAnnBinding1().s = "abc";
new FieldAnnBinding1().b = true;
X.verifyRun();
}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"red","blue","green"};
static int i = 0; // Count of advice executions
before(Colored c): set(* *) && withincode(* main(..)) && @annotation(c) {
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);
}
}

+ 43
- 0
tests/java5/annotations/binding/FieldAnnBinding2.aj View File

@@ -0,0 +1,43 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color();}
public class FieldAnnBinding2 {
@Colored(color="red") static int i;
@Colored(color="blue") String s;
@Colored(color="green") boolean b;
public static void main(String[]argv) {
FieldAnnBinding2 fab = new FieldAnnBinding2();
i = 5;
fab.s = "abc";
fab.b = true;
System.err.println("i="+fab.i);
System.err.println("s="+fab.s);
System.err.println("b="+fab.b);
X.verifyRun();
}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"red","blue","green"};
static int i = 0; // Count of advice executions
before(Colored c): get(* *) && withincode(* main(..)) && @annotation(c) {
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);
}
}

+ 39
- 0
tests/java5/annotations/binding/FieldAnnBinding3.aj View File

@@ -0,0 +1,39 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color();}
public class FieldAnnBinding3 {
@Colored(color="red") String s[];
@Colored(color="blue") boolean b[];
public static void main(String[]argv) {
FieldAnnBinding3 fab = new FieldAnnBinding3();
fab.s = new String[]{"abc","def"};
fab.b = new boolean[]{true,false,true};
System.err.println("s="+fab.s);
System.err.println("b="+fab.b);
X.verifyRun();
}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"red","blue"};
static int i = 0; // Count of advice executions
before(Colored c): get(* *) && withincode(* main(..)) && @annotation(c) {
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);
}
}

+ 40
- 0
tests/java5/annotations/binding/HandlerBinding.aj View File

@@ -0,0 +1,40 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
public class HandlerBinding {
public static void main(String[]argv) {
try {
throw new AndyException();
} catch (AndyException ae) {
System.err.println(ae);
}
X.verifyRun();
}
@Colored(color="red") static class AndyException extends Exception {
public AndyException() {
}
}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"red"};
static int i = 0; // Count of advice executions
before(Colored c): handler(*) && !within(X) && @annotation(c) {
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);
}
}

+ 42
- 0
tests/java5/annotations/binding/InitBinding.aj View File

@@ -0,0 +1,42 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
public class InitBinding {
public static void main(String[]argv) {
new A();
new B();
new C();
X.verifyRun();
}
}
class A {
@Colored(color="orange") public A() {}
}
class B {
@Colored(color="yellow") public B() {}
}
class C {
@Colored(color="brown") public C() {}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"orange","yellow","brown"};
static int i = 0; // Count of advice executions
before(Colored c): preinitialization(new(..)) && !within(X) && @annotation(c) {
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);
}
}

+ 43
- 0
tests/java5/annotations/binding/PreInitBinding.aj View File

@@ -0,0 +1,43 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
public class PreInitBinding {
public static void main(String[]argv) {
new A();
new B();
new C();
X.verifyRun();
}
}
class A {
@Colored(color="orange") public A() {}
}
class B {
@Colored(color="yellow") public B() {}
}
class C {
@Colored(color="brown") public C() {}
}
aspect X {
// Expected color order
static String exp[] = new String[]{"orange","yellow","brown"};
static int i = 0; // Count of advice executions
before(Colored c): preinitialization(new(..)) && !within(X) && @annotation(c) {
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);
}
}

+ 37
- 0
tests/java5/annotations/binding/StaticInitBinding.aj View File

@@ -0,0 +1,37 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
public class StaticInitBinding {
public static void main(String[]argv) {
new A();
new B();
new C();
X.verifyRun();
}
}
@Colored(color="orange") class A {}
@Colored(color="yellow") class B {}
@Colored(color="brown") class C {}
aspect X {
// Expected color order
static String exp[] = new String[]{"orange","yellow","brown"};
static int i = 0; // Count of advice executions
before(Colored c): staticinitialization(*) && !within(X) && @annotation(c) {
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);
}
}

Loading…
Cancel
Save