summaryrefslogtreecommitdiffstats
path: root/tests/design/calls/Simple.java
blob: f1277bde03465a820966c36d3819adc264f59fbd (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import org.aspectj.testing.Tester;

import java.lang.reflect.*;

public class Simple {
    public static void main(String[] args) {
	new Simple().fromInstanceMethod("a1", 1);
        //Tester.printEvents();
        Tester.checkAndClearEvents(new String[] {
            "this(simple)",
                "call(C.*)",
                "args(..,a1)",
                "C.toStaticMethod(a1)",

                "this(simple)",
                "call(SubC.*)",
                "args(..,a1)",
                "SubC.toStaticMethod(a1)",

                "this(simple)&&target(c)",
                "target(c)",
                "this(simple)",
                "call(C.*)",
                "args(..,a1)",
                "C.toInstanceMethod(a1)",

                "this(simple)&&target(subc)",
                "target(subc)",
                "this(simple)",
                "call(C.*)",
                "call(C.*)&&target(SubC)",
                "args(..,a1)",
                "SubC.toInstanceMethod(a1)",

                "this(simple)&&target(subc)",
                "target(subc)",
                "this(simple)",
                "call(C.*)",
                "call(SubC.*)",
                "call(SubC.*)&&target(C)",
                "call(C.*)&&target(SubC)",
                "args(..,a1)",
                "SubC.toInstanceMethod(a1)",

				//??? these events are not expected because advice on call join points
				// isn't run when the calls are made reflectively -- Change from 1.0 to 1.1
                //"call(C.*)",
                //"call(C.*)&&target(SubC)",
                //"args(..,a1)",
                "SubC.toInstanceMethod(a1)",
                });
	Simple.fromStaticMethod("a2");
        //Tester.printEvents();
        Tester.checkAndClearEvents(new String[] {        
            "call(C.*)",
                "args(..,a2)",
                "C.toStaticMethod(a2)",

                "call(SubC.*)",
                "args(..,a2)",
                "SubC.toStaticMethod(a2)",

                "target(c)",
                "call(C.*)",
                "args(..,a2)",
                "C.toInstanceMethod(a2)",

                "target(subc)",
                "call(C.*)",
                "call(C.*)&&target(SubC)",
                "args(..,a2)",
                "SubC.toInstanceMethod(a2)",

                "target(subc)",
                "call(C.*)",
                "call(C.*)&&target(SubC)",
                "SubC.toInstanceMethod(2)",
                });
    }

    public static void fromStaticMethod(String s) {
	C.toStaticMethod(s);
	SubC.toStaticMethod(s);
	C c = new C();
	c.toInstanceMethod(0, s);
	c = new SubC();
	c.toInstanceMethod(0, s);
        c.toInstanceMethod(0, new Integer(2));
    }

    public void fromInstanceMethod(String s, int v) {
	C.toStaticMethod(s);
	SubC.toStaticMethod(s);
	C c = new C();
	c.toInstanceMethod(v, s);
	c = new SubC();
	c.toInstanceMethod(v, s);
        SubC subc = new SubC();
	subc.toInstanceMethod(v, s);
        doReflectiveCall(subc, v, s);
    }

    void doReflectiveCall(C c, int v, String s) {
        try {
            Method m =
                C.class.getMethod("toInstanceMethod", 
                                  new Class[] {Integer.TYPE, Object.class});
            m.invoke(c, new Object[] {new Integer(v), s});
        } catch (Exception e) {
            Tester.event("unexpected exception: " + e);
        }
    }

    public String toString() { return "simple"; }
}


class C {
    public static void toStaticMethod(Object s) {
        Tester.event("C.toStaticMethod("+s+")");
    }

    public void toInstanceMethod(int value, Object str) {
        Tester.event("C.toInstanceMethod("+str+")");
    }
    public String toString() { return "c"; }
}

class SubC extends C {
    public static void toStaticMethod(Object s) {
        Tester.event("SubC.toStaticMethod("+s+")");
    }

    public void toInstanceMethod(int x, Object str) {
        Tester.event("SubC.toInstanceMethod("+str+")");
    }
    public String toString() { return "subc"; }
}    

aspect A {
    before(C c, Simple s): this(s) && target(c) {
        Tester.event("this("+s+")&&target("+c+")");
    }

    before(C c): target(c) && within(Simple) {
        Tester.event("target("+c+")");
    }

    before(Simple s): this(s) && call(* C+.*(..))  {
        Tester.event("this("+s+")");
    }

    before(): call(* C.*(..)) {
        Tester.event("call(C.*)");
    }

    before(): call(* SubC.*(..)) {
        Tester.event("call(SubC.*)");
    }

    before(): call(* SubC.*(..)) && target(C) {
        Tester.event("call(SubC.*)&&target(C)");
    }

    before(): call(* C.*(..)) && target(SubC) {
        Tester.event("call(C.*)&&target(SubC)");
    }

    before(String s): args(.., s) && call(* C+.*(..)) {
        //System.out.println(thisJoinPoint);
        Tester.event("args(..,"+s+")");
    }
}