blob: d1e032e8bfb91724eadecef93a57956a1db4696f (
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
import java.lang.reflect.*;
public class TheWholeShow {
private int f;
public void foo() {}
private void bar() {}
public static void main(String[] args) {
Field[] twsFields = TheWholeShow.class.getDeclaredFields();
for (Field f : twsFields) {
if (!f.getName().equals("f") && !f.getName().equals("x")) {
if (!f.isSynthetic()) {
System.err.println("Found non-synthetic field: " + f.getName());
throw new IllegalStateException("Found non-synthetic field: " + f.getName());
}
if (!Modifier.isStatic(f.getModifiers()) && !Modifier.isTransient(f.getModifiers())) {
System.err.println("Found non-transient field: " + f.getName());
throw new IllegalStateException("Found non-transient field: " + f.getName());
}
}
}
Method[] twsMethods = TheWholeShow.class.getDeclaredMethods();
for (Method m: twsMethods) {
if (! (m.getName().equals("foo") || m.getName().equals("bar") || m.getName().equals("<init>") ||
m.getName().equals("main") || m.getName().equals("checkOnlyHasAdviceMembers") || m.getName().equals("getX")) ) {
if (!m.isSynthetic()) {
System.err.println("Found non-synthetic method: " + m.getName());
throw new IllegalStateException("Found non-synthetic method: " + m.getName());
}
}
}
checkOnlyHasAdviceMembers(MakeITDs.class);
checkOnlyHasAdviceMembers(Declares.class);
checkOnlyHasAdviceMembers(Advises.class);
checkOnlyHasAdviceMembers(PerObject.class);
checkOnlyHasAdviceMembers(PTW.class);
checkOnlyHasAdviceMembers(Priv.class);
}
private static void checkOnlyHasAdviceMembers(Class c) {
Method[] ms = c.getDeclaredMethods();
Field[] fs = c.getDeclaredFields();
for (Field f : fs) {
if (!f.isSynthetic()) {
System.err.println("Found non-synthetic field: " + f.getName() + " in " + c.getName());
throw new IllegalStateException("Found non-synthetic field: " + f.getName());
}
}
for (Method m : ms) {
if (!m.isSynthetic()) {
String name = m.getName();
if ( ! (name.startsWith("ajc$before") || name.startsWith("ajc$after") || name.startsWith("ajc$around") ||
name.startsWith("ajc$interMethod$"))) {
System.err.println("Found non-synthetic method: " + m.getName() + " in " + c.getName());
throw new IllegalStateException("Found non-synthetic method: " + m.getName());
} else if (name.startsWith("ajc$around") && name.endsWith("proceed")) {
System.err.println("Found non-synthetic method: " + m.getName() + " in " + c.getName());
throw new IllegalStateException("Found non-synthetic method: " + m.getName());
}
}
}
}
}
aspect MakeITDs {
public int TheWholeShow.x = 5;
private int TheWholeShow.y = 6;
int TheWholeShow.z = 7;
public int TheWholeShow.getX() { return x; }
private int TheWholeShow.getY() { return y; }
int TheWholeShow.getZ() { return z; }
}
aspect Declares {
interface Foo {}
declare parents : TheWholeShow implements Foo;
declare warning : execution(* TheWholeShow.notThere(..)) : "foo";
declare soft : Exception : execution(* TheWholeShow.foo(..));
}
aspect Advises {
pointcut pc() : execution(* TheWholeShow.*(..));
before() : pc() {}
Object around(Object tws) : pc() && this(tws) {
return proceed(new TheWholeShow());
}
after() : pc() {}
after() returning : pc() {}
after() throwing : pc() {}
}
aspect PerObject perthis(execution(* TheWholeShow.*(..))) {
}
aspect PTW pertypewithin(TheWholeShow) {}
aspect Cflow {
before() : set(* x) && cflow(execution(* TheWholeShow.*(..))) {}
}
privileged aspect Priv {
before(TheWholeShow tws) : execution(* TheWholeShow.foo()) && this(tws) {
tws.bar();
tws.f = 12;
}
}
|