blob: 9c129b5ce288874680960f3a855152acd8b2ac39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }
@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value(); }
@Colored(color="yellow") @Fruit("banana") class YB {}
@Colored(color="green") @Fruit("apple") class GA {}
@Colored(color="red") @Fruit("tomato") class RT {}
public class AtArgs4 {
public static void main(String[]argv) {
m(new YB(),new GA(),new RT());
X.verify();
}
public static void m(Object a,Object b,Object c) { }
}
aspect X {
static int count = 0;
before(Colored c1,Fruit f,Colored c2): call(* m(..)) && !within(X) && @args(c1,f,c2) {
System.err.println("Two colors:"+c1.color()+","+c2.color());
System.err.println("Fruit is:"+f.value());
count++;
if (!c1.color().equals("yellow"))
throw new RuntimeException("Color1 should be yellow");
if (!f.value().equals("apple"))
throw new RuntimeException("Fruit should be apple");
if (!c2.color().equals("red"))
throw new RuntimeException("Color2 should be red");
}
public static void verify() {
if (count!=1) throw new Error("Should be 1 run: "+count);
}
}
|