blob: 7615d728e1c2e101381d75a604a5c58afb9b9ddf (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
import java.lang.annotation.*;
abstract aspect GA<P,Q,A extends Annotation> {
/*
* test before advice with
- CflowPointcut
- annotation
- args annotation
- args
- this
- target
- @this
- @target
- @within
- @withincode
- parameter binding
*/
before(P p, Q q) : cflow(execution(* P.*(..)) && this(p)) && set(Q *) && args(q) {
System.out.println("cflow-ok " + p + " " + q + " " + thisJoinPoint);
}
before(A a) : execution(* *(..)) && @annotation(a) && !execution(* toString()){
System.out.println("@annotation-ok " + a + " " + thisJoinPoint);
}
before(A a) : execution(* *(..)) && @args(a) && !execution(* toString()){
System.out.println("@args-ok " + a + " " + thisJoinPoint);
}
before(P p) : execution(* *(..)) && args(..,p) && !execution(* toString()){
System.out.println("args-ok " + p + " " + thisJoinPoint);
}
before(Q q) : this(q) && execution(* *(..)) && !execution(* toString()){
System.out.println("this-ok " + q + " " + thisJoinPoint);
}
before(P p) : target(p) && execution(* *(..)) && !execution(* toString()){
System.out.println("target-ok " + p + " " + thisJoinPoint);
}
before(A a) : @this(a) && execution(* *(..)) && !execution(* toString()){
System.out.println("@this-ok " + a + " " + thisJoinPoint);
}
before(A a) : @target(a) && execution(* *(..)) && !execution(* toString()){
System.out.println("@target-ok " + a + " " + thisJoinPoint);
}
before(A a) : @within(a) && execution(* *(..)) && !execution(* toString()){
System.out.println("@within-ok " + a + " " + thisJoinPoint);
}
before(A a) : @withincode(a) && get(* *) {
System.out.println("@withincode-ok " + a + " " + thisJoinPoint);
}
}
aspect Sub extends GA<X,Y,MyAnnotation> {
before(MyAnnotation a) : execution(* bar(..)) && @annotation(a) && !execution(* toString()){
System.out.println("@annotation-ok-sub " + a + " " + thisJoinPoint);
}
}
public class GenericAspectRuntimePointcuts {
public static void main(String[] s) {
X x = new X();
Y y = new Y();
x.foo();
x.bar();
y.foo(x);
y.bar();
}
}
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
String value() default "my-value";
}
@MyAnnotation
class X {
Y y;
void foo() {
this.y = new Y();
}
@MyAnnotation("bar")
void bar() {}
public String toString() { return "an X"; }
}
@MyAnnotation("on Y")
class Y {
X x;
void foo(X x) {}
@MyAnnotation
X bar() { return this.x; }
public String toString() { return "a Y"; }
}
|