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.

Driver.java 787B

1234567891011121314151617181920212223242526272829
  1. import org.aspectj.testing.Tester;
  2. public class Driver {
  3. public static void main(String[] args) { test(); }
  4. public static void test() {
  5. Driver.m(4);
  6. Tester.checkEqual(Trace.enterCount, 2, "befores");
  7. // The after for this method hasn't been run yet
  8. Tester.checkEqual(Trace.exitCount, 1, "afters");
  9. }
  10. static int m(int x) {
  11. return 0;
  12. }
  13. }
  14. aspect Trace {
  15. public static int enterCount, exitCount;
  16. // notice the absence of any modifiers in the advise
  17. before(): within(Driver) && (execution(void test()) ||
  18. execution(* m(..))) {
  19. enterCount++;
  20. }
  21. after(): within(Driver) && (execution(void test()) ||
  22. execution(* m(..))) {
  23. exitCount++;
  24. }
  25. }