summaryrefslogtreecommitdiffstats
path: root/tests/new/AdviceThrowsCf.java
blob: 279bd2d55a2d251db7bfdc9afe70f9646c8152f9 (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
import org.aspectj.testing.Tester;
import java.io.IOException;

public class AdviceThrowsCf {
    public static void main(String[] args) {
        try {
            new C().m1();
            Tester.checkFailed("m1");
        } catch (CheckedExc ce) {
            Tester.checkEqual("b1", ce.getMessage(), "m1");
        }
        try {
            new C().m2();
            Tester.checkFailed("m2");
        } catch (UncheckedExc ce) {
            Tester.checkEqual("b3", ce.getMessage(), "m2");
        }
        try {
            new C().m3();
            Tester.checkFailed("m3");
        } catch (CheckedExc ce) {
            Tester.checkEqual("b1", ce.getMessage(), "m3");
        } catch (Exception e) {
            Tester.checkFailed("IOException");
            System.out.println("m3: " + e);
        }
        try {
            new C().m4();
            Tester.checkFailed("m4");
        } catch (UncheckedExc ce) {
            Tester.checkEqual("b3", ce.getMessage(), "m4");
        }
    }

    
}

class CheckedExc extends Exception {
    CheckedExc(String m) { super(m); }
}

class UncheckedExc extends RuntimeException {
    UncheckedExc(String m) { super(m); }
}


class C {
    int x=0;
    public void m1() throws CheckedExc {
        x += 1;
    }

    public void m2() throws UncheckedExc {
    }

    public void m3() throws IOException, CheckedExc {
    }

    public void m4() {
    }
}

aspect A {
    pointcut canThrowChecked(): call(* C.m1()) || call(* C.m3());
    pointcut canThrowChecked1(): call(* C.m*() throws CheckedExc);

    pointcut canThrowUnchecked(): call(* C.m*());


    before() throws CheckedExc: canThrowUnchecked() {  // ERR: m2 and m4
        throw new CheckedExc("b1");
    }

    before() throws CheckedExc: get(int C.x) { //ERR: all gets
    }
    before() throws CheckedExc: set(int C.x) { //ERR: all sets
    }
    before() throws CheckedExc: staticinitialization(C) { //ERR: can't throw
    }
    
    void around() throws CheckedExc: canThrowChecked() {
    	proceed();
    }
    
    void around() throws CheckedExc: canThrowUnchecked() {  // ERR: can't throw
    	proceed();
    }
    
    void around() throws UncheckedExc: canThrowUnchecked() || set(int C.x) { 
    	proceed();
    }

}