aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/FieldPatterns.java
blob: e64f24c57e2aa4b1ffa0bfa70036e3211ac12383 (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
40
41
42
43
44
45
46
47
48
49
50
import org.aspectj.testing.Tester;

public class FieldPatterns {
    public static void main(String[] args) {
	SuperC sc = new SuperC();
	C c = new C();
	SubC subc = new SubC();

	Tester.checkEqual(sc.name, "SuperC");
	Tester.checkEqual(sc.count, 1, "SuperC");

	Tester.checkEqual(c.name, "C");
	Tester.checkEqual(c.count, 1, "C");

	Tester.checkEqual(subc.name, "C");
	Tester.checkEqual(subc.count, 1, "SubC");

	Tester.checkEqual(((SuperC)c).name, "SuperC");
	Tester.checkEqual(c.count, 2, "C as SuperC");

        c.name = null;
    }
}


class SuperC {
    int count = 0;
    String name = "SuperC";
}

class C extends SuperC {
    String name = "C";
}

class SubC extends C {
}

aspect A {
    before(SuperC sc): get(String SuperC.name) && target(sc){
	sc.count++;
    }
    before(C c): get(String C.name) && target(c) {
	c.count++;
    }

    before(): set(String C.name) {
    }
}