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

public class MultiDispatchCf {
    public static void main(String[] args) {
        C c = new C();

        Tester.event("**** exec ****");
        //MultiExec.enabled = true;
        run(new C());

        Tester.event("**** call ****");
        //MultiExec.enabled = false;
        //MultiCall.enabled = true;
        run(new C());

        Tester.event("**** both=call ****");
        //MultiExec.enabled = true;
        run(new C());

        Tester.printEvents();
    }
    
    static void run(C c) {
        Tester.event(c.doit("s1"));
        Tester.event(c.doit(new Integer(10)));
        Tester.event(c.doit(new Double(1.25)));

        Object o;
        o = "s2"; Tester.event(c.doit(o));
        o = new Integer(20); Tester.event(c.doit(o));
        o = new Double(2.25); Tester.event(c.doit(o));
    }
}


class C {
    String doit(Object o) {
        return "did-" + o.toString();
    }
}

aspect MultiCall {
    pointcut t1(String s): call(String C.doit(Object)) && args(s);

    String around(String s): t1(s) { return proceed(s); }
    String around(Object o): t1(o) { return proceed(o); }



    pointcut m(Object o): call(String C.doit(Object)) && args(o);

    String getPrefix() { return "call"; }

    String around(String s): m(s) {  //ERR
        return getPrefix() + "-string-" + s;
    }
    String around(Integer i): m(i) {   //ERR
        return getPrefix() + "-integer-" + i;
    }
    String around(Double d): m(d) {    //ERR
        return getPrefix()  + "-double-" + d;
    }
}

aspect MultiCreate {
    pointcut make(Object o): this(o) && execution(new(..));

    private interface I {}
    declare parents: C implements I;

    before(I i): make(i) {    //ERR: doesn't match Object
        System.out.println("new I: " + i);
    }
}