aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs151/pr122742/AfterReturningTest.java
blob: 9ec10a43e699232ba299f730849221fc1cd8c517 (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
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class AfterReturningTest {

	public static void main(String[] args) {
		new B1().start();
	}
	
	// include "JoinPoint" in the argument list
	@AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
	public void afterJP(JoinPoint jp, B1 r) {
		r.stop();
	}
	
	// include "JoinPoint.StaticPart" in the argument list
	@AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
	public void afterJPSP(JoinPoint.StaticPart jp, B1 r) {
		r.stop();
	}
	
	// include "JoinPoint.EnclosingStaticPart" in the argument list
	@AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
	public void afterJPESP(JoinPoint.EnclosingStaticPart jp, B1 r) {
		r.stop();
	}
	
	// include "JoinPoint and JoinPoint.EnclosingStaticPart" in the argument list
	@AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
	public void afterJPESP2(JoinPoint jp1, JoinPoint.EnclosingStaticPart jp, B1 r) {
		r.stop();
	}
	
	// make sure it still works if "JoinPoint" is second in the argument list
	@AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
	public void afterJP2(B1 r, JoinPoint jp) {
		r.stop();
	}
}

class B1 {
	
	public B1 start() {
		return new B1();
	}
	
	public void stop() {
	}
	
}