summaryrefslogtreecommitdiffstats
path: root/tests/new/DeclareSoft.java
blob: 095963f5be1f96cfb53d93ae8d75c7be8c45cdc2 (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
import org.aspectj.testing.Tester;
import java.io.*;
import org.aspectj.lang.*;

public class DeclareSoft {
    public static void main(String[] args) {
        new C().m1();
        try {
            new C().m2();
        } catch (SoftException se) {
            Tester.note("m2-soft");
        }

        try {
            new C().m3();
        } catch (SoftException se) {
            Tester.check(false, "already caught");
        }

        try {
            new C().throwIt();
        } catch (SoftException se) {
            Tester.note("throwIt-soft");
        } catch (Throwable t) {
            Tester.check(false, "should have been softened: " + t);
        }

        try {
            new C().pretendsToThrow();
        } catch (IOException ioe) {
            Tester.check(false, "bad IO");
        }

        Tester.check("m2-soft");
        Tester.check("around-m3");
    }
}

class C {
    public void throwIt() throws Throwable {
        throw makeThrowable();
    }

    public void pretendsToThrow() throws IOException, ClassNotFoundException {

    }

    private Throwable makeThrowable() {
        return new Exception("make me soft");
    }


    public void m1() {
    }

    public void m2() {
        new File("___hi").getCanonicalPath();
        new FileInputStream("___bye");
    }

    public void m3() {
        new FileInputStream("___bye");
        new File("___hi").getCanonicalPath();
    }
}

aspect B {
    declare soft: Exception: execution(* C.throwIt());

    declare soft: ClassNotFoundException: call(* C.pretendsToThrow());
}


aspect A {
    declare soft: IOException: execution(* C.*(..));

    void around(): execution(void C.m3()) {
        try {
            proceed();
        } catch (IOException ioe) {
            Tester.note("around-m3");
        }
    }
}