blob: 63ae8f859a2a2e0cbf5efeab650a62e262e2c3fc (
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
|
import org.aspectj.testing.Tester;
public aspect InitializerAdvice {
public static void test() {
Tester.checkEqual(Foo.getStaticField(), "initialized", "static");
Tester.checkEqual(new Foo().getInstanceField(), "initialized", "instance");
}
public static void main(String[] args) { test(); }
/*static*/ before(): call(* *(..)) && this(Foo) {
System.out.println("entering");
}
}
class Foo {
static String staticField = "";
static {
staticField = "initialized";
}
String instanceField = "";
{
instanceField = "initialized";
}
public static String getStaticField() {
return staticField;
}
public String getInstanceField() {
return instanceField;
}
}
|