aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/SuperField.java
blob: be80b3bd82e2d673283725eeb10287be128504f6 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import org.aspectj.testing.Tester;

public class SuperField {
    public static void main(String[] args) {
        Derived d = new Derived();
        Tester.checkAndClearEvents(new String[] {
            "set Base on <Derived>",
            "set Derived on <Derived>",
                });
        d.m1();
        Tester.checkAndClearEvents(new String[] {
            "get Derived on <Derived>",
            "Derived",
                });
        d.m2();
        Tester.checkAndClearEvents(new String[] {
            "get Derived on <Derived>",
            "Derived",
                });
        d.m3();
        Tester.checkAndClearEvents(new String[] {
            "get Base on <Derived>",
            "Base",
                });
        d.m4();
        Tester.checkAndClearEvents(new String[] {
            "get Base on <Derived>",
            "set BaseNew on <Derived>",
            "get BaseNew on <Derived>",
            "BaseNew",
                });
        Tester.printEvents();
    }
}

class Base {
    String s = "Base";
    public String toString() { return "<Base>"; }
}

class Derived extends Base {
    String s = "Derived";


    void m1() {
        Tester.event(s);
    }

    void m2() {
        Tester.event(this.s);
    }

    void m3() {
        Tester.event(super.s);
    }

    void m4() {
        super.s += "New";
        
        Tester.event(super.s);
    }

    public String toString() { return "<Derived>"; }
}

aspect A {
    after(Object o) returning (String v): target(o) && get(String s) {
        Tester.event("get " + v + " on " + o);
    }

    before(Object o, String v): target(o) && set(String s) && args(v) {
        Tester.event("set " + v + " on " + o);
    }


}