blob: 17a0be5214568c71cba48c3f714666b7ddea3c60 (
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
|
import org.aspectj.testing.Tester;
public class WithinInners {
public static void main(String[] args) {
C c = new C();
c.getRunnable().run();
// 1.1 doesn't capture withincode and execution of local types
//(1.0 behavior)Tester.checkEqual(A.notes, "before-within:before-withincode:around-in:run:around-out:");
Tester.checkEqual(A.notes, "before-within:around-in:run:around-out:");
}
}
class C {
public C() {
class Inner {
public void write( String text ) {
System.out.println( "write( String )" );
System.out.println( text );
}
}
Inner i = new Inner();
String s = "TEXT";
i.write( s );
}
public Runnable getRunnable() {
return new Runnable() {
public void run() {
A.notes += "run:";
}
};
}
}
aspect A {
public static String notes = "";
/* These don't work because we can't give local types reasonable top-level names */
before(String s): call(void write(String)) && args(s) { //&& withincode(C.new()) {
System.out.println(s);
}
void around(String s): call(void write(String)) && args(s) && withincode(C.new()) {
proceed(s.toLowerCase());
}
/* These now work and are checked */
//XXX not being able to do this(c) is a pain
before(Runnable runnable): execution(void Runnable.run()) && target(runnable) && within(C) { // && this(c) {
//System.out.println("about to call Runnable.run in " + c + " on " + runnable);
notes += "before-within:";
}
before(): execution(void run()) && withincode(Runnable C.getRunnable()) {
//System.out.println("about to call Runnable.run in C");
notes += "before-withincode:";
}
void around(): execution(void run()) {
//System.out.println("about to call Runnable.run in C");
notes += "around-in:";
proceed();
notes += "around-out:";
}
}
|