blob: e28ec25d86d43761ba7a691f91acffa5720e4a13 (
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
|
import org.aspectj.lang.*;
public aspect Singleton {
before(): execution(* Foo.*(..)) {}
public static void main(String []argv) {
print();
new Foo().m();
print();
}
public static void print() {
boolean b1 = Aspects14.hasAspect(Singleton.class);
boolean b2 = Singleton.hasAspect();
Object o1 = (b1?Aspects14.aspectOf(Singleton.class):null);
Object o2 = (b2?Singleton.aspectOf():null);
System.err.println("hasAspect? "+b1+" : "+b2);
System.err.println("aspectOf? "+o1+" : "+o2);
}
public String toString() { return "SingletonInstance"; }
}
class Foo {
public void m() { }
}
|