blob: 62d079b92d312cfe5b5c0ff6b4a3eba6c8e01aad (
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
|
// TESTING: multiple instances causing factory invocation multiple times (but is cached)
import org.aspectj.lang.annotation.*;
public class CaseE {
private String id;
public static void main(String[]argv) {
CaseE cea = new CaseE("a");
CaseE ceb = new CaseE("b");
((I)cea).methodOne();
((I)ceb).methodTwo();
((I)cea).methodOne();
((I)ceb).methodTwo();
}
public CaseE(String id) {
this.id=id;
}
public String toString() {
return "CaseE instance: "+id;
}
}
aspect X {
@DeclareMixin("CaseE")
public I createImplementation(Object o) {
System.out.println("Delegate factory invoked for "+o.toString());
return new Implementation(o);
}
}
interface I {
void methodOne();
void methodTwo();
}
class Implementation implements I {
Object o;
public Implementation(Object o) {
this.o = o;
}
public void methodOne() {
System.out.println("methodOne running on "+o);
}
public void methodTwo() {
System.out.println("methodTwo running on "+o);
}
}
|