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.

CallAnnBinding2.aj 1009B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @interface Colored { String color(); }
  4. public class CallAnnBinding2 {
  5. public static void main(String[]argv) {
  6. SecondaryClass sc = new SecondaryClass();
  7. sc.m1(1);
  8. sc.m2("hello");
  9. sc.m3("hello",1);
  10. }
  11. }
  12. class SecondaryClass {
  13. @Colored(color="cyan")
  14. public void m1(int i) {
  15. }
  16. @Colored(color="magenta")
  17. public void m2(String s) {
  18. }
  19. @Colored(color="mauve")
  20. public void m3(String s,int i) {
  21. }
  22. }
  23. aspect X {
  24. int i = 0;
  25. before(Colored c): call(* SecondaryClass.*(..)) && !within(X) && @annotation(c) {
  26. i++;
  27. if (i==1) checkColor(1,c,"cyan");
  28. if (i==2) checkColor(2,c,"magenta");
  29. if (i==3) checkColor(3,c,"mauve");
  30. System.err.println(c.color());
  31. }
  32. public void checkColor(int run, Colored c,String exp) {
  33. if (!c.color().equals(exp))
  34. throw new RuntimeException("Advice execution #"+run+" expected "+exp+" but got "+c.color());
  35. }
  36. }