blob: 89703c6054fddc1c3c5129a38088c753bd849fd5 (
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 org.aspectj.testing.Tester;
import java.io.*;
/**
* Test for: PR #98
*/
public class IntroductionOfInitializer {
public static void main(String[] args) { test(); }
public static void test() {
Tester.checkEqual(Foo.a, "class", "zero instances");
Foo foo = new Foo();
Tester.checkEqual(Foo.a, "class-instance", "one instances");
foo = new Foo();
Tester.checkEqual(Foo.a, "class-instance-instance", "two instances");
}
}
aspect A {
private static String classValue = "class";
private static String instanceValue = "-instance";
after(): staticinitialization(Foo) {
Foo.a += classValue;
}
after(): initialization(Foo.new(..)) {
Foo.a += instanceValue;
}
}
class Foo {
static String a = "";
}
|