blob: 500a8b45cc4150d964fd1c7bc8973f64c08b07e6 (
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
|
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
@Colored(color="yellow")
public class AtThis1 {
public static void main(String[]argv) {
new AtThis1().m();
X.verify();
}
@Colored(color="red")
public void m() {
System.err.println("method");
}
}
aspect X {
static int count = 0;
before(Colored c): call(* *(..)) && !within(X) && @this(c) {
System.err.println(thisJoinPoint+" > "+c.color());
count++;
if (!c.color().equals("yellow"))
throw new RuntimeException("Color should be yellow");
}
public static void verify() {
if (count!=1) throw new Error("Should be 1 run: "+count);
}
}
|