aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/generics/genericaspects/GenericAspectRuntimePointcuts.aj
blob: 8436e719f2a4cf8248fdd578a9b0d71e9b9f8795 (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
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 q) {
		System.out.println("cflow-ok " + p + " " + q);
	}
	
	before(A a) : execution(* *(..)) && @annotation(a) {
		System.out.println("@annotation-ok " + a);
	}
	
	before(A a) : @args(a) {
		System.out.println("@args-ok " + a);
	}
	
	before(P p) : args(..,p) {
		System.out.println("args-ok " + p);
	}
	
	before(Q q) : this(q) && execution(* *(..)) {
		System.out.println("this-ok " + q);
	}
	
	before(P p) : target(p) && call(* *(..)) {
		System.out.println("target-ok " + p);
	}
	
	before(A a) : @this(a) && execution(* *(..)) {
		System.out.println("@this-ok " + a);
	}
	
	before(A a) : @target(a) && call(* *(..)) {
		System.out.println("@target-ok " + a);
	}
	
	before(A a) : @within(a) && execution(* *(..)) {
		System.out.println("@within-ok " + a);
	}
	
	before(A a) : @withincode(a) && get(* *) {
		System.out.println("@withincode-ok " + a);
	}
}

aspect GenericAspectRuntimePointcuts extends GA<X,Y,MyAnnotation> {
	
	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() {}
	
}

@MyAnnotation("on Y")
class Y {
	X x;
	
	void foo(X x) {}
	
	@MyAnnotation
	X bar() { return this.x; }
}