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.

CflowOrder.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import java.io.PrintStream;
  2. import java.lang.annotation.*;
  3. @Retention(RetentionPolicy.RUNTIME) @interface Marker {}
  4. class A {
  5. @Marker void foo() { }
  6. public static void main(String[] args) {
  7. new A().foo();
  8. }
  9. }
  10. public class CflowOrder {
  11. public static void main(String[] args) {
  12. A.main(null);
  13. }
  14. static aspect MyAspect {
  15. pointcut annotated(Marker a) : execution(@Marker * *(..)) && @annotation(a);
  16. pointcut belowAnnotated() : cflowbelow(annotated(Marker));
  17. // pointcut belowAnnotated() : cflowbelow(execution(@Marker * *(..)) && @annotation(Marker));
  18. pointcut topAnnotated(Marker a) : annotated(a) && !belowAnnotated();
  19. pointcut notTopAnnotated(/*Marker a,*/ Marker aTop) :
  20. /* annotated(a) &&*/ cflowbelow(annotated(aTop));
  21. // if this first, then no nonTopAnnotated advice
  22. before(Marker a) : topAnnotated(a) { }
  23. // if topAnnotated is first, this does not run
  24. before(Marker aTop) : notTopAnnotated( aTop) { }
  25. }
  26. }