blob: 9e7f3c3acc9114d5184f4e4174c4cc798c282b6b (
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
|
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }
@Colored(color="yellow")
public class AtTarget1 {
public static void main(String[]argv) {
new AtTarget1().m();
}
@Colored(color="red")
public void m() {
System.err.println("method");
}
}
aspect X {
int adviceExecutions = 0;
before(Colored c): call(* *(..)) && !within(X) && @target(c) {
System.err.println(c.color());
adviceExecutions++;
if (!c.color().equals("yellow"))
throw new RuntimeException("Color should be yellow");
if (adviceExecutions>1)
throw new RuntimeException("Advice shouldn't be called more than once");
}
}
|