blob: 21b1f1009f2ef2b4a6f294d47beeed73abe5ccc8 (
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
|
import org.aspectj.testing.Tester;
public class DeclaredExcs {
public static void main(String[] args) { test(); }
public static void test() {
Foo foo = new Foo();
Tester.checkEqual(foo.foo(), "success", "foo()");
try {
foo.bar(false);
} catch (Exception e) {
Tester.check(false, "shouldn't catch");
}
try {
Bar bar = new Bar(false);
} catch (MyException e) {
Tester.check(false, "shouldn't catch");
}
try {
Bar bar = Bar.getNewBar(true);
Tester.check(false, "shouldn't get here");
} catch (MyException e) {
Tester.check(true, "should catch");
}
}
}
class Foo {
public void bar(boolean throwIt) throws Exception {
if (throwIt) {
throw new MyException("you asked for it");
}
}
public String foo() {
try {
bar(false);
} catch (Exception exc) {
Tester.check(false, "shouldn't catch anything");
}
try {
bar(true);
} catch (MyException exc) {
return "success";
} catch (Exception e1) {
return "failure";
}
return "failure";
}
}
class Bar {
String value;
public static Bar getNewBar(boolean throwIt) throws MyException {
return new Bar(throwIt);
}
public Bar(boolean throwIt) throws MyException {
if (throwIt) {
throw new MyException("you asked for it from constructor");
}
value = "boolean";
}
public Bar(String value) {
this.value = value;
}
}
class MyException extends Exception {
public MyException(String label) {
super(label);
}
}
aspect A {
before (): this(*) && execution(* *(..)) || execution(new(..)) {
//System.out.println("entering: "+thisJoinPoint);
}
after (): this(*) && execution(* *(..)) || execution(new(..)) {
//System.out.println("exiting: "+thisJoinPoint);
}
Object around(): this(*) && call(* *(..)) {
//System.out.println("start around: "+thisJoinPoint);
Object ret = proceed();
//System.out.println("end around: "+thisJoinPoint);
return ret;
}
}
|