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.

CallAnnBinding6.aj 928B

12345678910111213141516171819202122232425262728293031323334353637
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @interface Colored { String color(); }
  4. public class CallAnnBinding6 {
  5. public static void main(String[]argv) {
  6. A b = new B();
  7. b.m();
  8. if (X.i!=1) throw new RuntimeException("Why did the advice not run?");
  9. }
  10. }
  11. class A {
  12. @Colored(color="RedA") public void m() {}
  13. }
  14. class B extends A {
  15. @Colored(color="RedB") public void m() {}
  16. }
  17. aspect X {
  18. public static int i = 0;
  19. before(Colored c): call(* m*(..)) && !within(X) && @annotation(c) {
  20. i++;
  21. if (i==1) checkColor(1,c,"RedA");
  22. if (i==11) throw new RuntimeException("Advice running more times than expected");
  23. System.err.println(c.color());
  24. }
  25. public void checkColor(int run, Colored c,String exp) {
  26. if (!c.color().equals(exp))
  27. throw new RuntimeException("Advice execution #"+run+" expected "+exp+" but got "+c.color());
  28. }
  29. }