blob: 2a36d808457928985ceba733ebe2918e610f5560 (
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
41
42
43
44
45
46
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());
}
}
|