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.

InitBinding.aj 1015B

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