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.

HandlerBinding.aj 1010B

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