summaryrefslogtreecommitdiffstats
path: root/tests/new/Inners.java
blob: 2366b2c8e0ec6ec70950608920edf79175a2b54b (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
import org.aspectj.testing.*;
import java.awt.event.*;
import javax.swing.*;

public class Inners {

    public static void main(String[] args) {
        new Inners().realMain(args);
    }
    
    public void realMain(String[] args) {
        unincludedInterfaces();
        includedInterfaces();
        unincludedAbstractClases();
        includedAbstractClases();
        Tester.checkAllEvents();
    }

    static {
        // Ensure all methods run
        Tester.expectEventsInString("localRunnable0,localRunnable1,anonRunnable,staticInnerRunnable0" +
           ",innerRunnable0,staticInnerRunnable1,innerRunnable1");
        Tester.expectEventsInString("localStuff0,localStuff1,anonStuff,staticInnerStuff0" +
           ",innerStuff0,staticInnerStuff1,innerStuff1");
        Tester.expectEventsInString("localAbstractAction0,localAbstractAction1,,localAbstractAction2" +
           ",anonAbstractAction0,anonAbstractAction1," +
           ",staticInnerAbstractAction0,staticInnerAbstractAction1,staticInnerAbstractAction2" +
           ",innerAbstractAction0,innerAbstractAction1,innerAbstractAction2");
        Tester.expectEventsInString("localAbstractStuff0,localAbstractStuff1,,localAbstractStuff2" +
           ",anonAbstractStuff0,anonAbstractStuff1," +
           ",staticInnerAbstractStuff0,staticInnerAbstractStuff1,staticInnerAbstractStuff2" +
           ",innerAbstractStuff0,innerAbstractStuff1,innerAbstractStuff2");        
    }

    static String s = "";
    static void c(Object o) {
        s = o + "";
    }

    static int localRunnableI = 0;
    private void unincludedInterfaces() {
        class LocalRunnable implements Runnable {
            public void run() { a("localRunnable" + (localRunnableI++)); }
        }
        Runnable r0 = new StaticInnerRunnable();
        Runnable r1 = new InnerRunnable();
        Runnable r2 = new LocalRunnable();
        Runnable r3 = new Runnable() {
                public void run() { a("anonRunnable"); }
            };
        StaticInnerRunnable r4 = new StaticInnerRunnable();
        InnerRunnable r5 = new InnerRunnable();
        LocalRunnable r6 = new LocalRunnable();
        c("ui-r0"); r0.run();
        c("ui-r1"); r1.run();
        c("ui-r2"); r2.run();
        c("ui-r3"); r3.run();
        c("ui-r4"); r4.run();
        c("ui-r5"); r5.run();
        c("ui-r6"); r6.run();
    }
    
    static int localStuffI = 0;
    private void includedInterfaces() {
        class LocalStuff implements Stuff {
            public void run() { a("localStuff" + (localStuffI++)); }
        }
        Stuff r0 = new StaticInnerStuff();
        Stuff r1 = new InnerStuff();
        Stuff r2 = new LocalStuff();
        Stuff r3 = new Stuff() {
                public void run() { a("anonStuff"); }
            };
        StaticInnerStuff r4 = new StaticInnerStuff();
        InnerStuff r5 = new InnerStuff();
        LocalStuff r6 = new LocalStuff();
        c("ii-r0"); r0.run();
        c("ii-r1"); r1.run();
        c("ii-r2"); r2.run();
        c("ii-r3"); r3.run();
        c("ii-r4"); r4.run();
        c("ii-r5"); r5.run();
        c("ii-r6"); r6.run();        
    }

    static int localAbstractActionI = 0;
    private void unincludedAbstractClases() {
        class LocalAbstractAction extends AbstractAction {
            public void actionPerformed(ActionEvent e) { a("localAbstractAction" + (localAbstractActionI++)); }
        }
        AbstractAction r0 = new StaticInnerAbstractAction();
        AbstractAction r1 = new InnerAbstractAction();
        AbstractAction r2 = new LocalAbstractAction();
        AbstractAction r3 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) { a("anonAbstractAction0"); }
            };
        StaticInnerAbstractAction r4 = new StaticInnerAbstractAction();
        InnerAbstractAction r5 = new InnerAbstractAction();
        LocalAbstractAction r6 = new LocalAbstractAction();
        ActionListener r7 = new StaticInnerAbstractAction();
        ActionListener r8 = new InnerAbstractAction();
        ActionListener r9 = new LocalAbstractAction();
        ActionListener r10 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) { a("anonAbstractAction1"); }
            };
        c("ua-r0");  r0.actionPerformed(null);
        c("ua-r1");  r1.actionPerformed(null);
        c("ua-r2");  r2.actionPerformed(null);
        c("ua-r3");  r3.actionPerformed(null);
        c("ua-r4");  r4.actionPerformed(null);
        c("ua-r5");  r5.actionPerformed(null);
        c("ua-r6");  r6.actionPerformed(null);
        c("ua-r7");  r7.actionPerformed(null);
        c("ua-r8");  r8.actionPerformed(null);
        c("ua-r9");  r9.actionPerformed(null);
        c("ua-r10"); r10.actionPerformed(null);        
    }
    
    static int localAbstractStuffI = 0;    
    private void includedAbstractClases() {
        class LocalAbstractStuff extends AbstractStuff {
            public void run() { a("localAbstractStuff" + (localAbstractStuffI++)); }
        }
        AbstractStuff r0 = new StaticInnerAbstractStuff();
        AbstractStuff r1 = new InnerAbstractStuff();
        AbstractStuff r2 = new LocalAbstractStuff();
        AbstractStuff r3 = new AbstractStuff() {
                public void run() { a("anonAbstractStuff0"); }
            };
        StaticInnerAbstractStuff r4 = new StaticInnerAbstractStuff();
        InnerAbstractStuff r5 = new InnerAbstractStuff();
        LocalAbstractStuff r6 = new LocalAbstractStuff();
        Stuff r7 = new StaticInnerAbstractStuff();
        Stuff r8 = new InnerAbstractStuff();
        Stuff r9 = new LocalAbstractStuff();
        Stuff r10 = new AbstractStuff() {
                public void run() { a("anonAbstractStuff1"); }
            };        
        c("ia-r0");  r0.run();
        c("ia-r1");  r1.run();
        c("ia-r2");  r2.run();
        c("ia-r3");  r3.run();
        c("ia-r4");  r4.run();
        c("ia-r5");  r5.run();
        c("ia-r6");  r6.run();
        c("ia-r7");  r7.run();
        c("ia-r8");  r8.run();
        c("ia-r9");  r9.run();
        c("ia-r10"); r10.run();
    }

    
    /* Implement an unincluded interface */
    static class StaticInnerRunnable implements Runnable {
        static int i = 0;
        public void run() { Tester.event("staticInnerRunnable" + (i++)); }
    }
    static int innerRunnableI = 0;
    class InnerRunnable implements Runnable {
        public void run() { Tester.event("innerRunnable" + (innerRunnableI++)); }
    }

    /* Implement a included interface */
    static class StaticInnerStuff implements Stuff {
        static int i = 0;
        public void run() { Tester.event("staticInnerStuff" + (i++)); }
    }
    static int innerStuffI = 0;
    class InnerStuff implements Stuff {
        public void run() { Tester.event("innerStuff" + (innerStuffI++)); }
    }

    /* Extend an unincluded abstract class */
    static class StaticInnerAbstractAction extends AbstractAction {
        static int i = 0;
        public void actionPerformed(ActionEvent e) { Tester.event("staticInnerAbstractAction" + (i++)); }
    }
    static int innerAbstractActionI = 0;
    class InnerAbstractAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) { Tester.event("innerAbstractAction" + (innerAbstractActionI++)); }
    }    

    /* Extend a included abstract class */
    static class StaticInnerAbstractStuff extends AbstractStuff {
        static int i = 0;
        public void run() { Tester.event("staticInnerAbstractStuff" + (i++)); }
    }
    static int innerAbstractStuffI = 0;
    class InnerAbstractStuff extends AbstractStuff {
        public void run() { Tester.event("innerAbstractStuff" + (innerAbstractStuffI++)); }
    }    
}

aspect Aspect {
    static void advise(String str, int start, int num) {
        for (int i = start; i < num; i++) {
            addAll(str, i);
        }
    }
    static void advise(String str, int num) {
        advise(str, 0, num);
    }
    static void advise(String str, int[] ints) {
        for (int i = 0; i < ints.length; i++) {
            addAll(str, ints[i]);
        }
    }
    static void addAll(String str, int i) {
        Tester.expectEvent("before-" + str + "-r" + i);
        Tester.expectEvent("after-" + str + "-r" + i);
        Tester.expectEvent("around-" + str + "-r" + i);
    }
    static void add(String str) {
        Tester.event(str + "-" + Inners.s);
    }

    /* unincludedInterfaces */
    pointcut receptionsRunnable(): receptions(void run()) && instanceof(Runnable);
    static { advise("receptions-ui", 7); }
    static before(): receptionsRunnable() { add("before-receptions"); }
    static after(): receptionsRunnable() { add("after-receptions"); }
    static around() returns void: receptionsRunnable() { add("around-receptions"); proceed(); }

    pointcut executionsRunnable(): executions(void run()) && instanceof(Runnable);
    static { advise("executions-ui", 7); }
    static before(): executionsRunnable() { add("before-executions"); }
    static after(): executionsRunnable() { add("after-executions"); }
    static around() returns void: executionsRunnable() { add("around-executions"); proceed(); }

    pointcut receptionsStaticInnerRunnable(): receptions(void run()) && instanceof(Inners.StaticInnerRunnable);
    static { advise("receptions-ui", new int[]{0,4}); }
    static before(): receptionsStaticInnerRunnable() { add("before-receptions"); }
    static after(): receptionsStaticInnerRunnable() { add("after-receptions"); }
    static around() returns void: receptionsStaticInnerRunnable() { add("around-receptions"); proceed(); }

    pointcut executionsStaticInnerRunnable(): executions(void run()) && instanceof(Inners.StaticInnerRunnable);
    static { advise("executions-ui", new int[]{0,4}); }
    static before(): executionsStaticInnerRunnable() { add("before-executions"); }
    static after(): executionsStaticInnerRunnable() { add("after-executions"); }
    static around() returns void: executionsStaticInnerRunnable() { add("around-executions"); proceed(); }

    pointcut receptionsInnerRunnable(): receptions(void run()) && instanceof(Inners.InnerRunnable);
    static { advise("receptions-ui", new int[]{1,5}); }
    static before(): receptionsInnerRunnable() { add("before-receptions"); }
    static after(): receptionsInnerRunnable() { add("after-receptions"); }
    static around() returns void: receptionsInnerRunnable() { add("around-receptions"); proceed(); }

    pointcut executionsInnerRunnable(): executions(void run()) && instanceof(Inners.InnerRunnable);
    static { advise("executions-ui", new int[]{1,5}); }
    static before(): executionsInnerRunnable() { add("before-executions"); }
    static after(): executionsInnerRunnable() { add("after-executions"); }
    static around() returns void: executionsInnerRunnable() { add("around-executions"); proceed(); }



    /* includedInterfaces */
    pointcut receptionsStuff(): receptions(void run()) && instanceof(Stuff);
    static { advise("receptions-ii", 7); }
    static before(): receptionsStuff() { add("before-receptions"); }
    static after(): receptionsStuff() { add("after-receptions"); }
    static around() returns void: receptionsStuff() { add("around-receptions"); proceed(); }

    pointcut executionsStuff(): executions(void run()) && instanceof(Stuff);
    static { advise("executions-ii", 7); }
    static before(): executionsStuff() { add("before-executions"); }
    static after(): executionsStuff() { add("after-executions"); }
    static around() returns void: executionsStuff() { add("around-executions"); proceed(); }

    pointcut receptionsStaticInnerStuff(): receptions(void run()) && instanceof(Inners.StaticInnerStuff);
    static { advise("receptions-ii", new int[]{0,4}); }
    static before(): receptionsStaticInnerStuff() { add("before-receptions"); }
    static after(): receptionsStaticInnerStuff() { add("after-receptions"); }
    static around() returns void: receptionsStaticInnerStuff() { add("around-receptions"); proceed(); }

    pointcut executionsStaticInnerStuff(): executions(void run()) && instanceof(Inners.StaticInnerStuff);
    static { advise("executions-ii", new int[]{0,4}); }
    static before(): executionsStaticInnerStuff() { add("before-executions"); }
    static after(): executionsStaticInnerStuff() { add("after-executions"); }
    static around() returns void: executionsStaticInnerStuff() { add("around-executions"); proceed(); }

    pointcut receptionsInnerStuff(): receptions(void run()) && instanceof(Inners.InnerStuff);
    static { advise("receptions-ii", new int[]{1,5}); }
    static before(): receptionsInnerStuff() { add("before-receptions"); }
    static after(): receptionsInnerStuff() { add("after-receptions"); }
    static around() returns void: receptionsInnerStuff() { add("around-receptions"); proceed(); }

    pointcut executionsInnerStuff(): executions(void run()) && instanceof(Inners.InnerStuff);
    static { advise("executions-ii", new int[]{1,5}); }
    static before(): executionsInnerStuff() { add("before-executions"); }
    static after(): executionsInnerStuff() { add("after-executions"); }
    static around() returns void: executionsInnerStuff() { add("around-executions"); proceed(); }



    /* unincludedAbstractClases */
    pointcut receptionsAbstractAction():
        receptions(void actionPerformed(ActionEvent)) && instanceof(AbstractAction);
    static { advise("receptions-ua", 7); }
    static before(): receptionsAbstractAction() { add("before-receptions"); }
    static after(): receptionsAbstractAction() { add("after-receptions"); }
    static around() returns void: receptionsAbstractAction() { add("around-receptions"); proceed(); }

    pointcut executionsAbstractAction():
        executions(void actionPerformed(ActionEvent)) && instanceof(AbstractAction);
    static { advise("executions-ua", 7); }
    static before(): executionsAbstractAction() { add("before-executions"); }
    static after(): executionsAbstractAction() { add("after-executions"); }
    static around() returns void: executionsAbstractAction() { add("around-executions"); proceed(); }

    pointcut receptionsActionListener():
        receptions(void actionPerformed(ActionEvent)) && instanceof(ActionListener);
    static { advise("receptions-ua", 11); }
    static before(): receptionsActionListener() { add("before-receptions"); }
    static after(): receptionsActionListener() { add("after-receptions"); }
    static around() returns void: receptionsActionListener() { add("around-receptions"); proceed(); }

    pointcut executionsActionListener():
        executions(void actionPerformed(ActionEvent)) && instanceof(ActionListener);
    static { advise("executions-ua", 11); }
    static before(): executionsActionListener() { add("before-executions"); }
    static after(): executionsActionListener() { add("after-executions"); }
     static around() returns void: executionsActionListener() { add("around-executions"); proceed(); }    

    pointcut receptionsStaticInnerAbstractAction():
        receptions(void actionPerformed(ActionEvent)) && instanceof(Inners.StaticInnerAbstractAction);
    static { advise("receptions-ua", new int[]{0,4,7}); }
    static before(): receptionsStaticInnerAbstractAction() { add("before-receptions"); }
    static after(): receptionsStaticInnerAbstractAction() { add("after-receptions"); }
    static around() returns void: receptionsStaticInnerAbstractAction() { add("around-receptions"); proceed(); }

    pointcut executionsStaticInnerAbstractAction():
        executions(void actionPerformed(ActionEvent)) && instanceof(Inners.StaticInnerAbstractAction);
    static { advise("executions-ua", new int[]{0,4,7}); }
    static before(): executionsStaticInnerAbstractAction() { add("before-executions"); }
    static after(): executionsStaticInnerAbstractAction() { add("after-executions"); }
    static around() returns void: executionsStaticInnerAbstractAction() { add("around-executions"); proceed(); }

    pointcut receptionsInnerAbstractAction():
        receptions(void actionPerformed(ActionEvent)) && instanceof(Inners.InnerAbstractAction);
    static { advise("receptions-ua", new int[]{1,5,8}); }
    static before(): receptionsInnerAbstractAction() { add("before-receptions"); }
    static after(): receptionsInnerAbstractAction() { add("after-receptions"); }
    static around() returns void: receptionsInnerAbstractAction() { add("around-receptions"); proceed(); }

    pointcut executionsInnerAbstractAction():
        executions(void actionPerformed(ActionEvent)) && instanceof(Inners.InnerAbstractAction);
    static { advise("executions-ua", new int[]{1,5,8}); }
    static before(): executionsInnerAbstractAction() { add("before-executions"); }
    static after(): executionsInnerAbstractAction() { add("after-executions"); }
    static around() returns void: executionsInnerAbstractAction() { add("around-executions"); proceed(); }
    
    
    /* includedAbstractClases */
    pointcut receptionsAbstractStuff(): receptions(void run()) && instanceof(AbstractStuff);
    static { advise("receptions-ia", 7); }
    static before(): receptionsAbstractStuff() { add("before-receptions"); }
    static after(): receptionsAbstractStuff() { add("after-receptions"); }
    static around() returns void: receptionsAbstractStuff() { add("around-receptions"); proceed(); }

    pointcut executionsAbstractStuff(): executions(void run()) && instanceof(AbstractStuff);
    static { advise("executions-ia", 7); }
    static before(): executionsAbstractStuff() { add("before-executions"); }
    static after(): executionsAbstractStuff() { add("after-executions"); }
    static around() returns void: executionsAbstractStuff() { add("around-executions"); proceed(); }

    pointcut receptionsStuff2(): receptions(void run()) && instanceof(Stuff);
    static { advise("receptions-ia", 11); }
    static before(): receptionsStuff2() { add("before-receptions"); }
    static after(): receptionsStuff2() { add("after-receptions"); }
    static around() returns void: receptionsStuff2() { add("around-receptions"); proceed(); }

    pointcut executionsStuff2(): executions(void run()) && instanceof(Stuff);
    static { advise("executions-ia", 11); }
    static before(): executionsStuff2() { add("before-executions"); }
    static after(): executionsStuff2() { add("after-executions"); }
    static around() returns void: executionsStuff2() { add("around-executions"); proceed(); }    

    pointcut receptionsStaticInnerAbstractStuff():
        receptions(void run()) && instanceof(Inners.StaticInnerAbstractStuff);
    static { advise("receptions-ia", new int[]{0,4,7}); }
    static before(): receptionsStaticInnerAbstractStuff() { add("before-receptions"); }
    static after(): receptionsStaticInnerAbstractStuff() { add("after-receptions"); }
    static around() returns void: receptionsStaticInnerAbstractStuff() { add("around-receptions"); proceed(); }

    pointcut executionsStaticInnerAbstractStuff():
        executions(void run()) && instanceof(Inners.StaticInnerAbstractStuff);
    static { advise("executions-ia", new int[]{0,4,7}); }
    static before(): executionsStaticInnerAbstractStuff() { add("before-executions"); }
    static after(): executionsStaticInnerAbstractStuff() { add("after-executions"); }
    static around() returns void: executionsStaticInnerAbstractStuff() { add("around-executions"); proceed(); }

    pointcut receptionsInnerAbstractStuff():
        receptions(void run()) && instanceof(Inners.InnerAbstractStuff);
    static { advise("receptions-ia", new int[]{1,5,8}); }
    static before(): receptionsInnerAbstractStuff() { add("before-receptions"); }
    static after(): receptionsInnerAbstractStuff() { add("after-receptions"); }
    static around() returns void: receptionsInnerAbstractStuff() { add("around-receptions"); proceed(); }

    pointcut executionsInnerAbstractStuff():
        executions(void run()) && instanceof(Inners.InnerAbstractStuff);
    static { advise("executions-ia", new int[]{1,5,8}); }
    static before(): executionsInnerAbstractStuff() { add("before-executions"); }
    static after(): executionsInnerAbstractStuff() { add("after-executions"); }
    static around() returns void: executionsInnerAbstractStuff() { add("around-executions"); proceed(); }
}

interface Stuff {
    public void run();
}

abstract class AbstractStuff implements Stuff {
    public abstract void run();
}