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.

AtArgs5.aj 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME) @interface Colored { String color(); }
  3. @Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value(); }
  4. @Colored(color="yellow") @Fruit("banana") class YB {}
  5. @Colored(color="green") @Fruit("apple") class GA {}
  6. @Colored(color="red") @Fruit("tomato") class RT {}
  7. public class AtArgs5 {
  8. public static void main(String[]argv) {
  9. m(new YB(),new GA(),new RT());
  10. }
  11. public static void m(Object a,Object b,Object c) { }
  12. }
  13. aspect X {
  14. static int count = 0;
  15. before(Colored c1,Fruit f,Colored c2): execution(* m(..)) && !within(X) && @args(c1,f,c2) {
  16. System.err.println("Two colors:"+c1.color()+","+c2.color());
  17. System.err.println("Fruit is:"+f.value());
  18. count++;
  19. if (!c1.color().equals("yellow"))
  20. throw new RuntimeException("Color1 should be yellow");
  21. if (!f.value().equals("apple"))
  22. throw new RuntimeException("Fruit should be apple");
  23. if (!c2.color().equals("red"))
  24. throw new RuntimeException("Color2 should be red");
  25. }
  26. public static void verify() {
  27. if (count!=3) throw new Error("Should be 3 runs: "+count);
  28. }
  29. }