1 /***************************************************************************************
2
3 * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
4
5 * http://aspectwerkz.codehaus.org *
6
7 * ---------------------------------------------------------------------------------- *
8
9 * The software in this package is published under the terms of the LGPL license *
10
11 * a copy of which has been included with this distribution in the license.txt file. *
12
13 **************************************************************************************/
14
15 package test.aspect;
16
17
18
19 import test.Introductions;
20
21
22
23 import java.io.Serializable;
24
25
26
27 /***
28
29 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
30
31 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
32
33 * @Aspect perJVM
34
35 */
36
37 public class IntroductionTestAspect {
38
39
40
41
42
43 /***
44
45 * @Implements within(test.ToBeIntroduced)
46
47 */
48
49 Serializable serializable;
50
51
52
53 /***
54
55 * @Implements hasmethod(* *..*.thisMethodNameShouldHopefullyBeUnique())
56
57 */
58
59 Serializable otherSerializable;
60
61
62
63 /***
64
65 * @Implements hasfield(* *..*.thisFieldNameShouldHopefullyBeUnique)
66
67 */
68
69 Cloneable cloneable;
70
71
72
73 /***
74
75 * Here we use an expression
76
77 *
78
79 * @Introduce within(test.ToBeIntroduced) or
80
81 * hasfield(* *..*.thisFieldNameShouldHopefullyBeUnique)
82
83 */
84
85 public static class MyImpl implements Introductions {
86
87
88
89 public void NOT_IN_MIXIN_INTF() {}
90
91
92
93
94
95 public void noArgs() throws RuntimeException {
96
97 }
98
99
100
101 public long longArg(long arg) {
102
103 return arg;
104
105 }
106
107
108
109 public int intArg(int arg) {
110
111 return arg;
112
113 }
114
115
116
117 public short shortArg(short arg) {
118
119 return arg;
120
121 }
122
123
124
125 public double doubleArg(double arg) {
126
127 return arg;
128
129 }
130
131
132
133 public float floatArg(float arg) {
134
135 return arg;
136
137 }
138
139
140
141 public byte byteArg(byte arg) {
142
143 return arg;
144
145 }
146
147
148
149 public boolean booleanArg(boolean arg) {
150
151 return arg;
152
153 }
154
155
156
157 public char charArg(char arg) {
158
159 return arg;
160
161 }
162
163
164
165 public Object objectArg(Object arg) {
166
167 return arg;
168
169 }
170
171
172
173 public String[] arrayArg(String[] arg) {
174
175 return arg;
176
177 }
178
179
180
181 public int variousArguments1(String str, int i, float f, Object o, long l) throws RuntimeException {
182
183 return str.hashCode() + i + (int) f + o.hashCode() + (int) l;
184
185 }
186
187
188
189 public int variousArguments2(float f, int i, String str1, Object o, long l, String str2) throws RuntimeException {
190
191 return (int) f + i + str1.hashCode() + o.hashCode() + (int) l + str2.hashCode();
192
193 }
194
195
196
197 public void getVoid() throws RuntimeException {
198
199 }
200
201
202
203 public long getLong() throws RuntimeException {
204
205 return 1L;
206
207 }
208
209
210
211 public int getInt() throws RuntimeException {
212
213 return 1;
214
215 }
216
217
218
219 public short getShort() throws RuntimeException {
220
221 return 1;
222
223 }
224
225
226
227 public double getDouble() throws RuntimeException {
228
229 return 1.1D;
230
231 }
232
233
234
235 public float getFloat() throws RuntimeException {
236
237 return 1.1F;
238
239 }
240
241
242
243 public byte getByte() throws RuntimeException {
244
245 return Byte.parseByte("1");
246
247 }
248
249
250
251 public char getChar() throws RuntimeException {
252
253 return 'A';
254
255 }
256
257
258
259 public boolean getBoolean() throws RuntimeException {
260
261 return true;
262
263 }
264
265
266
267 public void exceptionThrower() throws Throwable {
268
269 throw new UnsupportedOperationException("this is a test");
270
271 }
272
273
274
275 public void exceptionThrowerChecked() throws CheckedException {
276
277 throw new CheckedException();
278
279 }
280
281 }
282
283
284
285 /***
286
287 * Other implementation For now explicit implements is needed (extends is not enough - bug in
288
289 * swapping)
290
291 */
292
293 public static class MyOtherImpl extends MyImpl implements Introductions, Serializable {
294
295 public void noArgs() throws RuntimeException {
296
297 }
298
299
300
301 public long longArg(long arg) {
302
303 return arg;
304
305 }
306
307
308
309 /***
310
311 * used by test case
312
313 */
314
315 public int intArg(int arg) {
316
317 return -1 * arg;
318
319 }
320
321
322
323 public short shortArg(short arg) {
324
325 return arg;
326
327 }
328
329
330
331 public double doubleArg(double arg) {
332
333 return arg;
334
335 }
336
337
338
339 public float floatArg(float arg) {
340
341 return arg;
342
343 }
344
345
346
347 public byte byteArg(byte arg) {
348
349 return arg;
350
351 }
352
353
354
355 public boolean booleanArg(boolean arg) {
356
357 return arg;
358
359 }
360
361
362
363 public char charArg(char arg) {
364
365 return arg;
366
367 }
368
369
370
371 public Object objectArg(Object arg) {
372
373 return arg;
374
375 }
376
377
378
379 public String[] arrayArg(String[] arg) {
380
381 return arg;
382
383 }
384
385
386
387 public int variousArguments1(String str, int i, float f, Object o, long l) throws RuntimeException {
388
389 return str.hashCode() + i + (int) f + o.hashCode() + (int) l;
390
391 }
392
393
394
395 public int variousArguments2(float f, int i, String str1, Object o, long l, String str2) throws RuntimeException {
396
397 return (int) f + i + str1.hashCode() + o.hashCode() + (int) l + str2.hashCode();
398
399 }
400
401
402
403 public void getVoid() throws RuntimeException {
404
405 }
406
407
408
409 public long getLong() throws RuntimeException {
410
411 return 1L;
412
413 }
414
415
416
417 public int getInt() throws RuntimeException {
418
419 return -1;
420
421 }
422
423
424
425 public short getShort() throws RuntimeException {
426
427 return 1;
428
429 }
430
431
432
433 public double getDouble() throws RuntimeException {
434
435 return 1.1D;
436
437 }
438
439
440
441 public float getFloat() throws RuntimeException {
442
443 return 1.1F;
444
445 }
446
447
448
449 public byte getByte() throws RuntimeException {
450
451 return Byte.parseByte("1");
452
453 }
454
455
456
457 public char getChar() throws RuntimeException {
458
459 return 'A';
460
461 }
462
463
464
465 public boolean getBoolean() throws RuntimeException {
466
467 return true;
468
469 }
470
471 }
472
473 }