aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/StaticTypeInIf.java
blob: cc2a8087bfe4a69050a0ef48452d325c7ca91988 (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
import org.aspectj.testing.Tester;

// we want to be doing tests based on dynamic type in if
public class StaticTypeInIf {
    public static void main(String[] args) {
	D d = new D();
	C c = new C();

	c.foo(c);
        Tester.checkAndClearEvents(new String[] {});

        A.setF(d, false);
	c.foo(d);
        Tester.checkAndClearEvents(new String[] {});
        A.setF(d, true);
	c.foo(d);
        Tester.checkAndClearEvents(new String[] {"args"});

        A.setF(d, false);
	d.foo(c);
        Tester.checkAndClearEvents(new String[] {});
        A.setF(d, true);
	d.foo(c);
        Tester.checkAndClearEvents(new String[] {"this", "target"});

        A.setF(d, false);
	d.foo(d);
        Tester.checkAndClearEvents(new String[] {});
        A.setF(d, true);
	d.foo(d);
        Tester.checkAndClearEvents(new String[] {"args", "this", "target"});

    }

}

class C {
    void foo(C c) {}
}

class D extends C {
    void foo(C c) {}
}


aspect A {
    private boolean D.f = false;

    static void setF(D d, boolean b) { d.f = b; }

    pointcut foo(D d): call(void C.foo(C)) && target(d) && if(d.f); 

    before (C c): foo(c) {
        Tester.event("target");
    }

    before (D d): if(d.f) && call(void C.foo(C)) && args(d) {
        Tester.event("args");

    }

    before (D d): execution(void C.foo(C)) && this(d) && if(d.f) {
        Tester.event("this");
    }
}