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.

FieldAnnBinding3.aj 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @interface Colored { String color();}
  4. public class FieldAnnBinding3 {
  5. @Colored(color="red") String s[];
  6. @Colored(color="blue") boolean b[];
  7. public static void main(String[]argv) {
  8. FieldAnnBinding3 fab = new FieldAnnBinding3();
  9. fab.s = new String[]{"abc","def"};
  10. fab.b = new boolean[]{true,false,true};
  11. System.err.println("s="+fab.s);
  12. System.err.println("b="+fab.b);
  13. X.verifyRun();
  14. }
  15. }
  16. aspect X {
  17. // Expected color order
  18. static String exp[] = new String[]{"red","blue"};
  19. static int i = 0; // Count of advice executions
  20. before(Colored c): get(* *) && withincode(* main(..)) && @annotation(c) {
  21. System.err.println(thisJoinPoint+" color="+c.color());
  22. if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());
  23. i++;
  24. }
  25. public static void verifyRun() {
  26. if (X.i != exp.length)
  27. throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);
  28. }
  29. }