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 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import java.io.*;
  2. import org.aspectj.testing.Tester;
  3. public class Driver {
  4. public static void main(String[] args) { test(); }
  5. public static void test() {
  6. Point p = new Point();
  7. p.setX(3);
  8. }
  9. }
  10. class Point {
  11. int _x = 0;
  12. int _y = 0;
  13. Point() {}
  14. void set (int x, int y) {
  15. _x = x; _y = y;
  16. }
  17. void setX (int x) { _x = x; }
  18. void setY (int y) { _y = y; }
  19. int getX() { return _x; }
  20. int getY() { return _y; }
  21. }
  22. aspect Trace {
  23. static int oldvalue;
  24. before(Point p, int newvalue): target(p) && args(newvalue) &&
  25. (call(void setX(int)) ||
  26. call(void setY(int))) {
  27. oldvalue = p.getX();
  28. }
  29. after(Point p, int newvalue): target(p) && args(newvalue) &&
  30. (call(void setX(int)) ||
  31. call(void setY(int))) {
  32. Tester.checkEqual(oldvalue,0, "oldvalue");
  33. Tester.checkEqual(newvalue,3, "newvalue");
  34. }
  35. }