summaryrefslogtreecommitdiffstats
path: root/tests/new/Cricket.java
blob: 33c1849e127ebd2eab7cef222cdee4b88de7d2cf (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
import org.aspectj.testing.Tester;

public class Cricket {
    public static void main(String[] args) {
        Lib l = new Lib();
        Tester.event("call stringMethod");
        l.stringMethod(2);
        Tester.event("call voidMethod");
        l.voidMethod(2);
        Tester.checkEventsFromFile("Cricket.out");
    }
}


class Lib {
    public void voidMethod(int count) {
        if (count == 0) return;
        else voidMethod(count - 1);
    }

    public String stringMethod(int count) {
        if (count == 0) return "0";
        else return count + "-" + stringMethod(count-1);
    }
}


aspect Trace {
    pointcut entry(): target(Lib) && call(* *(..));
    pointcut topEntry(): entry() && !cflowbelow(entry());

    before(): topEntry() {
        Tester.event("->top entry: " + thisJoinPoint);
    }

    after(): entry() {
        Tester.event("->exit: " + thisJoinPoint);
    }

    after() returning (Object o): entry() {
        Tester.event("->exit: " + thisJoinPoint + " with " + o);
    }
    after(): topEntry() {
        Tester.event("->top exit: " + thisJoinPoint);
    }

    after() returning (Object o): topEntry() {
        Tester.event("->top exit: " + thisJoinPoint + " with " + o);
    }
}