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.

AnnotationThrowsPattern.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import java.lang.annotation.Target;
  2. import java.lang.annotation.ElementType;
  3. @Target({ElementType.TYPE})
  4. @interface TypeAnnotation{}
  5. @Target({ElementType.METHOD})
  6. @interface MethodAnnotation{}
  7. public class AnnotationThrowsPattern {
  8. public void method1() throws MyException {}
  9. public void method2() throws MyNonAnnotatedException {}
  10. }
  11. @TypeAnnotation
  12. class MyException extends Exception {
  13. }
  14. class MyNonAnnotatedException extends Exception {
  15. }
  16. aspect A {
  17. // shouldn't get xlint warnings because @TypeAnnotation is allowed
  18. pointcut required() : execution(* *.*(..) throws (@TypeAnnotation *));
  19. declare warning : required() : "(* *.*(..) throws (@TypeAnnotation *))";
  20. // shouldn't get xlint warnings because @TypeAnnotation is allowed
  21. pointcut forbidden() : execution(* *.*(..) throws !(@TypeAnnotation *));
  22. declare warning : forbidden() : "(* *.*(..) throws !(@TypeAnnotation *))";
  23. // should get an xlint warning here because can only have
  24. // annotations with @Target{ElementType.TYPE} or the default
  25. // @Target (which is everything)
  26. pointcut required1() : execution(* *.*(..) throws (@MethodAnnotation *));
  27. declare warning : required1() : "* *.*(..) throws (@MethodAnnotation *)";
  28. // should get an xlint warning here because can only have
  29. // annotations with @Target{ElementType.TYPE} or the default
  30. // @Target (which is everything)
  31. pointcut forbidden1() : execution(* *.*(..) throws !(@MethodAnnotation *));
  32. declare warning : forbidden1() : "* *.*(..) throws !(@MethodAnnotation *)";
  33. }