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.

MarkMyMethodsAspect.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. public aspect MarkMyMethodsAspect {
  2. /* All methods not marked with @Read nor @Write are marked with @Write
  3. *
  4. * When @MarkMyMethods is present on a Type, all public methods of
  5. * that type must either be marked with @Read or @Write. If neither of
  6. * @Read or @Write is present on such a method, the method is automatically
  7. * annotated with the default marker, i.e. @Write
  8. *
  9. * *******************************************************
  10. * BUG
  11. * internal null pointer exception with the first part
  12. * of the declare statement.
  13. * *******************************************************
  14. *
  15. */
  16. declare @method : !@(Write || Read) public !static * (@MarkMyMethods *).*(..) : @Write;
  17. // This one works
  18. //declare @method : !@(Read) public !static * (@MarkMyMethods *).*(..) : @Write;
  19. // This one too
  20. //declare @method : !@(Write) public !static * (@MarkMyMethods *).*(..) : @Write;
  21. /* Cannot have @Read or @Write methods without @MarkMyMethods
  22. *
  23. * When @Read or @Write is present on a method, the enclosing type must
  24. * have the @AccessClassified annotation.
  25. */
  26. declare error : execution(@Read public * !@MarkMyMethods *.*(..)) :
  27. "Cannot have public @Read methods inside non @AccessClassified types.";
  28. declare error : execution(@Write public * !@MarkMyMethods *.*(..)) :
  29. "Cannot have public @Write methods inside non @AccessClassified types.";
  30. /* Cannot have a method marked with both @Read and @Write
  31. *
  32. * What would be necessary is to have an annotation that can take
  33. * a parameter to identify which type of access is needed that would prevent
  34. * the user from having the 2 at the same time e.g. @Access(READ). Unfortunately,
  35. * AspectJ 1.5 can currently only work with marker annotations and ignores
  36. * parameter annotations.
  37. */
  38. declare error : readMethod() && writeMethod() :
  39. "Cannot have both @Read and @Write on the same method.";
  40. /*
  41. * public @Read methods inside @MarkMyMethods types
  42. */
  43. public pointcut readMethod() :
  44. execution(@Read public !static * @MarkMyMethods *.*(..));
  45. /*
  46. * public @Write methods inside @MarkMyMethods types
  47. */
  48. public pointcut writeMethod() :
  49. execution(@Write public !static * @MarkMyMethods *.*(..));
  50. }