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.

AtThis1.aj 741B

123456789101112131415161718192021222324252627282930313233343536
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @interface Colored { String color(); }
  4. @Colored(color="yellow")
  5. public class AtThis1 {
  6. public static void main(String[]argv) {
  7. new AtThis1().m();
  8. X.verify();
  9. }
  10. @Colored(color="red")
  11. public void m() {
  12. System.err.println("method");
  13. }
  14. }
  15. aspect X {
  16. static int count = 0;
  17. before(Colored c): call(* *(..)) && !within(X) && @this(c) {
  18. System.err.println(thisJoinPoint+" > "+c.color());
  19. count++;
  20. if (!c.color().equals("yellow"))
  21. throw new RuntimeException("Color should be yellow");
  22. }
  23. public static void verify() {
  24. if (count!=1) throw new Error("Should be 1 run: "+count);
  25. }
  26. }