summaryrefslogtreecommitdiffstats
path: root/tests/java5/generics/pointcuts/ThisAndTargetPointcutMatchingRuntime.aj
blob: 2dde15d1d23a5477a524475d76b5624d63f4f256 (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
public aspect ThisAndTargetPointcutMatchingRuntime {

	// rule 2) a raw type pattern matches all jps within a generic type
	pointcut setAndThis() : set(* *) && this(Generic);
	pointcut setAndTarget() : set(* *) && target(Generic);
	pointcut executionAndThis() : execution(* *(..)) && this(Generic);
	pointcut executionAndTarget() : execution(* *(..)) && target(Generic);
	pointcut callAndTarget() : call(* *(..)) && target(Generic);
	
	// rule 3) a raw type pattern matches all jps within a parameterized type
	pointcut pCallAndThis() : call(* *(..)) && this(ISore);
	pointcut pCallAndTarget() : call(* *(..)) && target(ISore);
	
	before() : setAndThis() { System.out.println("set and this matched ok"); }
	before() : setAndTarget() { System.out.println("set and target matched ok"); }
	before() : executionAndThis() { System.out.println("execution and this matched ok"); }
	before() : executionAndTarget() { System.out.println("execution and target matched ok"); }
	before() : callAndTarget() { System.out.println("call and target matched ok"); }
	before() : pCallAndThis() { System.out.println("parameterized call and this matched ok"); }
	before() : pCallAndTarget() { System.out.println("parameterized call and target matched ok"); }
	
	public static void main(String[] args) {
		Generic<String> gs = new Generic<String>();
		gs.getFoo();
		UglyBuilding theIBMBuilding = new UglyBuilding(); 
		theIBMBuilding.iSee("you");
	}
}


class Generic<T> {
	
	T foo = null;
	
	public T getFoo() {
		return foo;
	}
	
}

interface ISore<E> {
	
	void iSee(E anE);
	
}

class UglyBuilding implements ISore<String> {
	
	public void iSee(String s) {
		noop();
	}
	
	private void noop() {}
	
}