aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/AbstractCflows.java
blob: 25d21a9be370c147bd8595fc22ea66d7ab2bcffe (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import org.aspectj.testing.Tester;

public class AbstractCflows {
    public static void main(String[] args) {
        C c = new C();
        c.enter(1, 2);
        c.enter1(3);
        Tester.checkEvents(expected);
    }
    private static final String[] expected = {
        "enter(1, 2)",
        "CflowX: call(void C.body()); i = 1",
        "CflowY: call(void C.body()); i = 2",
        "PerCflowX: call(void C.body())",
        "PerCflowY: call(void C.body())",
        "BODY",
        "CflowX: call(void C.body()); i = 1",
        "CflowY: call(void C.body()); i = 2",
        "PerCflowX: call(void C.body())",
        "PerCflowY: call(void C.body())",
        "BODY",
        "enter1(3)",
        "Cflow3: call(void C.body()); i = 3",
        "PerCflow3: call(void C.body())",
        "BODY",
    };
}

class C {
    public void enter(int x, int y) {
        Tester.event("enter(" + x + ", " + y + ")");
        body();
        body();
    }

    public void enter1(int i) {
        Tester.event("enter1(" + i + ")");
        body();
    }

    public void body() {
        Tester.event("BODY");
    }
}

abstract aspect CflowBase {
    abstract pointcut entry(int i);
    pointcut flow(int x): cflow(entry(x));

    pointcut body(): call(* body());

    before(int i): body() && flow(i) {
        Tester.event(this.getClass().getName() + ": " + thisJoinPoint + "; i = " + i);
    }
}

aspect CflowY extends CflowBase {
    pointcut entry(int y): args(*, y) && call(void enter(int, int));
}

aspect CflowX extends CflowBase {
    pointcut entry(int x): args(x, *) && call(void enter(int, int));
}

aspect Cflow3 extends CflowBase {
    pointcut entry(int i): args(i) && call(void enter1(int));
}

abstract aspect PerCflowBase percflow(entry(int)) {
    abstract pointcut entry(int i);

    pointcut body(): call(* body());

    before(): body() {
        Tester.event(this.getClass().getName() + ": " + thisJoinPoint);
    }
}

aspect PerCflowY extends PerCflowBase {
    pointcut entry(int y): args(*, y) && call(void enter(int, int));
}

aspect PerCflowX extends PerCflowBase {
    pointcut entry(int x): args(x, *) && call(void enter(int, int));
}

aspect PerCflow3 extends PerCflowBase {
    pointcut entry(int i): args(i) && call(void enter1(int));
}