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.

MyAspect.java 766B

123456789101112131415161718192021
  1. import java.util.Arrays;
  2. privileged public aspect MyAspect {
  3. Object around(MyClass o, MyAnnotation a) :
  4. execution(@MyAnnotation * *(..)) &&
  5. target(o) &&
  6. @annotation(a) {
  7. if (!isOneOf(o.getValue(), a.value()))
  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> boolean isOneOf(T obj, T[] arr) {
  15. for (T el : arr) if (obj == el) return true;
  16. return false;
  17. }
  18. }