blob: 1198f6fa918f99b0299e14ec956b79d7ec8b5722 (
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
|
import org.aspectj.lang.reflect.*;
public aspect PointcutsWithParams {
pointcut pc1(String s) : args(s);
pointcut pc2(Integer i, Double d, String s) : args(i,d,s);
public static void main(String[] args) throws NoSuchPointcutException {
AjType myType = AjTypeSystem.getAjType(PointcutsWithParams.class);
Pointcut p1 = myType.getDeclaredPointcut("pc1");
AjType<?>[] params = p1.getParameterTypes();
if (params.length != 1) throw new RuntimeException("expecting one param");
if (!params[0].getJavaClass().equals(String.class)) throw new RuntimeException("expecting a String");
String[] names = p1.getParameterNames();
if (names.length != 1) throw new RuntimeException("expecting one name");
if (!names[0].equals("s")) throw new RuntimeException("expecting 's', found " + names[0]);
Pointcut p2 = myType.getDeclaredPointcut("pc2");
params = p2.getParameterTypes();
if (params.length != 3) throw new RuntimeException("expecting three params");
if (!params[0].getJavaClass().equals(Integer.class)) throw new RuntimeException("expecting an Integer");
if (!params[1].getJavaClass().equals(Double.class)) throw new RuntimeException("expecting a Double");
if (!params[2].getJavaClass().equals(String.class)) throw new RuntimeException("expecting a String");
names = p2.getParameterNames();
if (names.length != 3) throw new RuntimeException("expecting one name");
if (!names[0].equals("i")) throw new RuntimeException("expecting 'i', found '" + names[0] + "'");
if (!names[1].equals("d")) throw new RuntimeException("expecting 'd', found '" + names[1] + "'");
if (!names[2].equals("s")) throw new RuntimeException("expecting 's', found '" + names[2] + "'");
}
}
|