summaryrefslogtreecommitdiffstats
path: root/tests/base/test100/Driver.java
blob: cc231537722e640c81f8e4c46b5f31372c007994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import org.aspectj.testing.Tester;

public class Driver {
  public static void main(String[] args) { test(); }
  
  public static void test() { 
   
    Pos p1 = new Pos();
    Pos p2 = new Pos(); 
    Pos p3 = new Pos();

    Foo f1 = Foo.aspectOf(p1);
    Foo f2 = Foo.aspectOf(p2);
    Foo f3 = Foo.aspectOf(p3);

    p1.move(1, 2);
    Tester.checkEqual(p1.getX(), 1, "p1.x");
    Tester.checkEqual(p1.getY(), 2, "p1.y");

    p2.move(1, 2);
    Tester.checkEqual(p2.getX(), 1, "p2.x");
    Tester.checkEqual(p2.getY(), 2, "p2.y");
   
    p3.move(1, 2);
    Tester.checkEqual(p3.getX(), 1, "p3.x");
    Tester.checkEqual(p3.getY(), 2, "p3.y");

    Tester.checkEqual(f1.count, 3, "f1.count");
    Tester.checkEqual(f2.count, 3, "f2.count");
    Tester.checkEqual(f3.count, 3, "f3.count");
    Tester.checkEqual(Bar.countx, 9, "Bar.countx");
  }
}

class Pos {

  int x = 0;
  int y = 0;

  int getX() { 
    return(x);
  }

  int getY() {
    return(y);
  }
  
  void move(int newX, int newY) {
    x=newX;
    y=newY;
  }
}

aspect Foo pertarget(target(Pos)) {
  int count = 0;

  before (): ( call(* getX(..)) || 
               call(* getY(..)) ||
               call(* move(..))  ) {
      count++;
  }
}     

aspect Bar {
  static int countx = 0;
  
  /*static*/ before (): target(Pos) && 
                    ( call(* getX(..)) || 
                      call(* getY(..)) ||
                      call(* move(..))  ) {
      countx++;
  }
}