aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/AfterReturningParamMatching.java
blob: 4677eac09b73730df4053426ff146ad08fcc3c06 (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
import org.aspectj.testing.Tester;

// this test verifies the matching behaivor for after returning with a typed parameter.

public class AfterReturningParamMatching {
	public static void main(String[] args) {
		goBoolean(false);
		Tester.checkAndClearEvents(new String[] { "boolean", "Object" });

		goByte(1);
		Tester.checkAndClearEvents(new String[] { "byte", "int", "long", "Object"});
		
		goInt(2);
		Tester.checkAndClearEvents(new String[] { "int", "long", "Object" });

		goLong(3);
		Tester.checkAndClearEvents(new String[] { "long", "Object" });
		
		goObject(new Object());
		Tester.checkAndClearEvents(new String[] { "Object" });
		
	    goObject(new Integer(4));
		Tester.checkAndClearEvents(new String[] { "Object", "Number", "Integer" });
		
		goObject(null); 
		Tester.checkAndClearEvents(new String[] { "Object" });
	    
		goNumber(new Long(5));
		Tester.checkAndClearEvents(new String[] { "Object", "Number" });
		
		goNumber(new Integer(6));
		Tester.checkAndClearEvents(new String[] { "Object", "Number", "Integer" });

		goNumber(null);
		Tester.checkAndClearEvents(new String[] { "Object", "Number" });

		goInteger(new Integer(7));
		Tester.checkAndClearEvents(new String[] { "Object", "Number", "Integer" });

        goInteger(null);
        Tester.checkAndClearEvents(new String[] { "Object", "Number", "Integer" });

	}
	static boolean goBoolean(boolean b) { return b; }
	static byte goByte(int i) { return (byte) i; }
	static int goInt(int i) { return i; }
	static long goLong(int i) { return (long) i; }
	
	static Object goObject(Object o) { return o; }
	static Number goNumber(Number o) { return o; }
	static Integer goInteger(Integer o) { return o; }
}

aspect A {
	
	pointcut methodsInQuestion():
		call(* goBoolean(*)) || 
		call(* goByte(*)) || 
		call(* goInt(*)) || 
		call(* goLong(*)) || 
		call(* goObject(*)) || 
		call(* goNumber(*)) || 
		call(* goInteger(*)); 
	
	after() returning(boolean b): methodsInQuestion() { Tester.event("boolean"); }
	after() returning(byte b): methodsInQuestion() { Tester.event("byte"); }
	after() returning(int b): methodsInQuestion() { Tester.event("int"); }
	after() returning(long b): methodsInQuestion() { Tester.event("long"); }
	after() returning(Object b): methodsInQuestion() { Tester.event("Object"); }
	after() returning(Number b): methodsInQuestion() { Tester.event("Number"); }
	after() returning(Integer b): methodsInQuestion() { Tester.event("Integer"); }

}