blob: 1aa66dc8522c132652e1805ca31659847d094f76 (
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
|
import org.aspectj.testing.Tester;
public class AdviceOnPrivileged {
public static void main(String[] args) {
C c1 = new C();
c1.getX();
Tester.check(!c1.gotXOutsideC, "normal field access");
C c2 = new C();
ExposeC.getX(c2);
Tester.check(c2.gotXOutsideC, "privileged field access");
}
}
class C {
public boolean gotXOutsideC = false;
private int x=1;
public int getX() { return x; }
}
aspect WatchGets {
before(C c): get(int C.x) && target(c) && !within(C) {
System.out.println("got C.x");
c.gotXOutsideC = true;
}
}
privileged aspect ExposeC {
public static int getX(C c) { return c.x; }
}
|