summaryrefslogtreecommitdiffstats
path: root/tests/java5/ataspectj/annotationGen/SimplePointcut.aj
blob: e022f2b53e293efa1a40caa5bd5dcd10c8148e38 (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
import java.lang.annotation.*;
import org.aspectj.lang.annotation.*;
import java.lang.reflect.*;

public aspect SimplePointcut {
	
	pointcut myPointcut() : call(* String.*(..));
	
	public static void main(String[] args) {
		Method[] methods = SimplePointcut.class.getDeclaredMethods();
		boolean foundit = false;
		for (Method method : methods) {
			if (method.getName().startsWith("ajc$pointcut$")) {
				if (foundit) throw new RuntimeException("Only expecting one pointcut method");
				foundit = true;
				if (method.getName().indexOf("$myPointcut$") == -1) {
					throw new RuntimeException("Pointcut name not captured");
				}
				if (method.getAnnotations().length != 1) {
					throw new RuntimeException("Expecting one annotation, found " + method.getAnnotations().length);
				}
				Pointcut pcAnn = method.getAnnotation(Pointcut.class);
				if (!pcAnn.value().equals("call(* java.lang.String.*(..))"))
					throw new RuntimeException("Pointcut expression not set correctly in annotation: " + pcAnn.value());
			}
		}
	}
	
}