blob: 8d4a769663dd8b322d91d10b658bfa4f427c5764 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import java.util.Arrays;
privileged public aspect MyAspect2 {
Object around(MyClass o, MyAnnotation a) :
execution(@MyAnnotation * *(..)) &&
target(o) &&
@annotation(a) {
if (isOneOf(o.getValue(), a.value())==null)
throw new IllegalStateException(
o.getValue() +
" is not one of " +
Arrays.toString(a.value()));
return proceed(o, a);
}
private static final <T> T isOneOf(T obj, T[] arr) {
for (T el : arr) if (obj == el) return obj;
return null;
}
}
|