aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/AdviceOrdering.java
blob: a5f4103c6f880aeb27894df6afff5476e9801b4f (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import org.aspectj.testing.*;

public class AdviceOrdering {
    public static void main(String[] args) { test(); }
    
    public static void test() {
        new C().m();
        T.checkAndReset("before:aroundStart:m:aroundEnd:after:afterReturning");

        new C().recur(2);
        T.checkAndReset("P&&!cflowbelow(P):P:recur-2:P:recur-1:P:recur-0");

        new C().a();
        T.checkAndReset("C1:C2:C3:C4:A3:A4:A1:A2:B1:a");
    }
}


class T {
    private static StringBuffer order = new StringBuffer();
    public static void add(String s) { 
        if (order.length() > 0) { order.append(':'); }
        order.append(s);
    }
    public static void reset() { order = new StringBuffer(); }

    public static void checkAndReset(String expectedValue) {
        Tester.checkEqual(order.toString(), expectedValue);
        order.setLength(0);
    }
}

class C {
    public void m() { T.add("m"); }
    public void a() { T.add("a"); }
    public void b() { T.add("b"); }
    public void c() { T.add("c"); }

    public void recur(int n) {
        T.add("recur-"+n);
        if (n > 0) recur(n-1);
    }
}

aspect A {
    pointcut cut() : target(C) && call(void m());

    before():            cut() { T.add("before"); }
    void around(): cut() {
        T.add("aroundStart");
        proceed();
        T.add("aroundEnd");
    }

    after():             cut() { T.add("after"); }
    after() returning(): cut() { T.add("afterReturning"); }

}

//check that P && !cflow(P) never matches anything regardless of ordering issues 
aspect FlowCheck {
    pointcut cut() : target(C) && call(void recur(int));
    
    before(): cut() && !cflow(cut()) {
        // should never run
        T.add("P&&!cflow(P)");
    }
    before(): cut() && !cflowbelow(cut()) {
        // should run once
        T.add("P&&!cflowbelow(P)");
    }

    before(): cut() && cflow(cut() && !cflow(cut())) {
        // should never run
        T.add("cflow(P&&!cflow(P))");
    }

    before(): cut() {
        T.add("P");
    }
}



// This cluster of aspects checks that the partial order rules work
//aspect A1 dominates A2, B1 {
aspect A1 { declare precedence: A1, A2 || B1;
    pointcut cut() : target(C) && call(void a());

    before(): A1.cut() { T.add("A1"); }
}

aspect A2 { declare precedence: A2, B1;
    before(): A1.cut() { T.add("A2"); }
}

aspect A3 { declare precedence: A3,  A4, A1;
    before(): A1.cut() { T.add("A3"); }
}

aspect A4 { declare precedence: A4, A1;
    before(): A1.cut() { T.add("A4"); }
}

aspect B1 {
    before(): A1.cut() { T.add("B1"); }
}



//aspect C1 dominates C2, C3 {
aspect C1 { declare precedence: C1, C2 || C3;
    before(): A1.cut() { T.add("C1"); }
}
aspect C2 { declare precedence: C2, C3;
    before(): A1.cut() { T.add("C2"); }
}
aspect C3 { declare precedence: C3, C4;
    before(): A1.cut() { T.add("C3"); }
}
//aspect C4 dominates A1, A2, A3, A4, B1 {
aspect C4 { declare precedence: C4, (A1 || A2 || A3 || A4 || B1);
    before(): A1.cut() { T.add("C4"); }
}