blob: 415cc31db06f1fed84d04791ac6eb5b06d2e7519 (
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
|
import org.aspectj.lang.annotation.*;
import java.lang.annotation.Annotation;
public class SimpleBefore {
public static void main(String []argv) {
Class x = X.class;
Aspect ann = (Aspect) x.getAnnotation(Aspect.class);
if (ann == null) {
throw new RuntimeException("could not see runtime visible annotation");
}
SimpleBefore instance = new SimpleBefore();
X.s.append("1");
instance.m();
if (!X.s.toString().equals("1b2"))
throw new RuntimeException("Either advice not run or ordering wrong, expected 1b2: "+X.s);
}
public void m() {
X.s.append("2");
}
@Aspect("issingleton()")
public static class X {
public static StringBuffer s = new StringBuffer("");
@Before("execution(* SimpleBefore.m())")
public void before() {
s.append("b");
}
}
}
|