You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MyAspect2.java 764B

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