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.

TestRequirements.java 878B

123456789101112131415161718192021222324252627282930313233
  1. package TestRequirements;
  2. import java.lang.annotation.Retention;
  3. import java.lang.annotation.RetentionPolicy;
  4. @Retention(RetentionPolicy.RUNTIME)
  5. @interface AnnotatedMethod {}
  6. @Retention(RetentionPolicy.RUNTIME)
  7. @interface NewAnnotatedMethod {
  8. boolean newValue();
  9. }
  10. aspect X {
  11. declare @method: !@AnnotatedMethod * TestRequirements.*(..) : @NewAnnotatedMethod(newValue = true);
  12. }
  13. public class TestRequirements {
  14. @AnnotatedMethod
  15. public void dontMatchMe() {}
  16. public void matchMe() {}
  17. public static void foo() throws Exception {
  18. if (TestRequirements.class.getDeclaredMethod("dontMatchMe").getAnnotation(NewAnnotatedMethod.class)!=null) {
  19. throw new IllegalStateException();
  20. }
  21. if (TestRequirements.class.getDeclaredMethod("matchMe").getAnnotation(NewAnnotatedMethod.class)==null) {
  22. throw new IllegalStateException();
  23. }
  24. }
  25. }