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
45pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-w
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");
    }
}