blob: 994dc4cfbdb40de5e704cc42742bd7bb04107c15 (
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
|
import java.util.List;
@interface AspectAnnotation {}
@interface InterfaceAnnotation {}
@interface ITDFieldAnnotation {}
@interface ITDMethodAnnotation {}
@interface MethodAnnotation {}
@interface AdviceAnnotation {}
@AspectAnnotation
public abstract aspect AnnotatingAspects {
@InterfaceAnnotation
public interface Observer {}
@InterfaceAnnotation
interface Subject {}
@ITDFieldAnnotation
private List<Observer> Subject.observers;
@ITDMethodAnnotation
public void Subject.addObserver(Observer o) {
((List<Observer>)observers).add(o); // this cast will not be needed when generics are fixed
}
@ITDMethodAnnotation
public void Subject.removeObserver(Observer o) {
observers.remove(o);
}
@MethodAnnotation
private void notifyObservers(Subject subject) {
for(Observer o : (List<Observer>)subject.observers) // this cast will not be needed when generics are fixed
notifyObserver(o,subject);
}
@MethodAnnotation
protected abstract void notifyObserver(Observer o, Subject s);
protected abstract pointcut observedEvent(Subject subject);
@AdviceAnnotation
after(Subject subject) returning : observedEvent(subject) {
notifyObservers(subject);
}
}
|