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.

AdviceExecBinding.aj 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @interface Colored { String color(); }
  4. public class AdviceExecBinding {
  5. public static void main(String[]argv) {
  6. m1();
  7. m2();
  8. m3();
  9. X.verifyRun();
  10. }
  11. static void m1() {}
  12. static void m2() {}
  13. static void m3() {}
  14. }
  15. aspect B {
  16. @Colored(color="orange") before(): execution(* m1()) {}
  17. @Colored(color="yellow") before(): execution(* m2()) {}
  18. @Colored(color="brown") before(): execution(* m3()) {}
  19. }
  20. aspect X {
  21. // Expected color order
  22. static String exp[] = new String[]{"orange","yellow","brown"};
  23. static int i = 0; // Count of advice executions
  24. before(Colored c): adviceexecution() && within(B) && @annotation(c) {
  25. System.err.println(thisJoinPoint+" color="+c.color());
  26. if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());
  27. i++;
  28. }
  29. public static void verifyRun() {
  30. if (X.i != exp.length)
  31. throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);
  32. }
  33. }