aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/HoldProceed.java
blob: 1f14060d73dd510c57924ceba1914f02a04b65e2 (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
import org.aspectj.testing.Tester;
import java.util.*;


public class HoldProceed {
    public static void main(String[] args) {
        C c = new C();
        c.m1(); c.m2(); c.m1();
        Tester.check("m");
        Tester.checkEqual(A.buf.toString(), "");
        A.runProceeds();
        Tester.checkEqual(A.buf.toString(), "m1:b:m2:m1:");
        A.runProceeds();
        Tester.checkEqual(A.buf.toString(), "m1:b:m2:m1:m1:b:m2:m1:");

        try {
            c.m3();
        } catch (Exception e) {
            Tester.check(false, "shouldn't throw anything");
        }

        try {
            A.runProceeds();
        } catch (Error err) {  //??? this is an odd test for the fact that Exception is wrapped
            Tester.note("caught err");
        }
        Tester.check("caught err");
    }
}

class C {
    public void m1() {A. buf.append("m1:"); }
    public void m2() {A. buf.append("m2:"); }
    public void m3() throws Exception { throw new Exception("from m3"); }
}

aspect A {
    static StringBuffer buf = new StringBuffer();

    static List heldProceeds = new LinkedList();

    int cnt = 0;

    void around (): call(void C.m*()) {
        heldProceeds.add(new Runnable() { public void run() { proceed(); cnt++; } });

        class MyRun implements Runnable {
            public void run() { System.out.println("run"); }
            public void m() { Tester.note("m"); } 
        }

        MyRun mr = new MyRun();
        mr.m();
    }

    before(): call(void C.m2()) {
        new Runnable() {
                public void run() { buf.append("b:"); }
                }.run();
    }
    
    public static void runProceeds() {
        for (Iterator i = heldProceeds.iterator(); i.hasNext(); ) {
            ((Runnable)i.next()).run();
        }
    }
}