blob: 533b3801274f68c67993a68f0c15d4dbe2c5a793 (
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
|
import org.aspectj.lang.annotation.*;
import java.lang.reflect.*;
public aspect AdviceWithArgs {
@SuppressAjWarnings
before(String s) : execution(* *(..)) && args(s) {
System.out.println(s);
}
public static void main(String[] args) throws Exception {
Method[] meths = AdviceWithArgs.class.getMethods();
boolean found = false;
for (Method meth : meths) {
if (meth.isAnnotationPresent(Before.class)) {
found = true;
Before bAnn = meth.getAnnotation(Before.class);
String argNames = bAnn.argNames();
if (!argNames.equals("s")) {
throw new RuntimeException("Expected 's' but got '" + argNames + "'");
}
break;
}
}
if (!found) throw new RuntimeException("Did not find expected advice annotation");
}
}
|