1 /***************************************************************************************
2 * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package test.aspect;
9
10 import test.Introductions;
11
12 import java.io.Serializable;
13
14 /***
15 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
16 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
17 * @Aspect perJVM
18 */
19 public class IntroductionTestAspect {
20
21
22 /***
23 * @Implements within(test.ToBeIntroduced)
24 */
25 Serializable serializable;
26
27 /***
28 * @Implements hasmethod(* *..*.thisMethodNameShouldHopefullyBeUnique())
29 */
30 Serializable otherSerializable;
31
32 /***
33 * @Implements hasfield(* *..*.thisFieldNameShouldHopefullyBeUnique)
34 */
35 Cloneable cloneable;
36
37 /***
38 * Here we use an expression
39 *
40 * @Introduce within(test.ToBeIntroduced) or
41 * hasfield(* *..*.thisFieldNameShouldHopefullyBeUnique)
42 */
43 public static class MyImpl implements Introductions {
44
45 public void NOT_IN_MIXIN_INTF() {}
46
47
48 public void noArgs() throws RuntimeException {
49 }
50
51 public long longArg(long arg) {
52 return arg;
53 }
54
55 public int intArg(int arg) {
56 return arg;
57 }
58
59 public short shortArg(short arg) {
60 return arg;
61 }
62
63 public double doubleArg(double arg) {
64 return arg;
65 }
66
67 public float floatArg(float arg) {
68 return arg;
69 }
70
71 public byte byteArg(byte arg) {
72 return arg;
73 }
74
75 public boolean booleanArg(boolean arg) {
76 return arg;
77 }
78
79 public char charArg(char arg) {
80 return arg;
81 }
82
83 public Object objectArg(Object arg) {
84 return arg;
85 }
86
87 public String[] arrayArg(String[] arg) {
88 return arg;
89 }
90
91 public int variousArguments1(String str, int i, float f, Object o, long l) throws RuntimeException {
92 return str.hashCode() + i + (int) f + o.hashCode() + (int) l;
93 }
94
95 public int variousArguments2(float f, int i, String str1, Object o, long l, String str2) throws RuntimeException {
96 return (int) f + i + str1.hashCode() + o.hashCode() + (int) l + str2.hashCode();
97 }
98
99 public void getVoid() throws RuntimeException {
100 }
101
102 public long getLong() throws RuntimeException {
103 return 1L;
104 }
105
106 public int getInt() throws RuntimeException {
107 return 1;
108 }
109
110 public short getShort() throws RuntimeException {
111 return 1;
112 }
113
114 public double getDouble() throws RuntimeException {
115 return 1.1D;
116 }
117
118 public float getFloat() throws RuntimeException {
119 return 1.1F;
120 }
121
122 public byte getByte() throws RuntimeException {
123 return Byte.parseByte("1");
124 }
125
126 public char getChar() throws RuntimeException {
127 return 'A';
128 }
129
130 public boolean getBoolean() throws RuntimeException {
131 return true;
132 }
133
134 public void exceptionThrower() throws Throwable {
135 throw new UnsupportedOperationException("this is a test");
136 }
137
138 public void exceptionThrowerChecked() throws CheckedException {
139 throw new CheckedException();
140 }
141 }
142
143 /***
144 * Other implementation For now explicit implements is needed (extends is not enough - bug in
145 * swapping)
146 */
147 public static class MyOtherImpl extends MyImpl implements Introductions, Serializable {
148 public void noArgs() throws RuntimeException {
149 }
150
151 public long longArg(long arg) {
152 return arg;
153 }
154
155 /***
156 * used by test case
157 */
158 public int intArg(int arg) {
159 return -1 * arg;
160 }
161
162 public short shortArg(short arg) {
163 return arg;
164 }
165
166 public double doubleArg(double arg) {
167 return arg;
168 }
169
170 public float floatArg(float arg) {
171 return arg;
172 }
173
174 public byte byteArg(byte arg) {
175 return arg;
176 }
177
178 public boolean booleanArg(boolean arg) {
179 return arg;
180 }
181
182 public char charArg(char arg) {
183 return arg;
184 }
185
186 public Object objectArg(Object arg) {
187 return arg;
188 }
189
190 public String[] arrayArg(String[] arg) {
191 return arg;
192 }
193
194 public int variousArguments1(String str, int i, float f, Object o, long l) throws RuntimeException {
195 return str.hashCode() + i + (int) f + o.hashCode() + (int) l;
196 }
197
198 public int variousArguments2(float f, int i, String str1, Object o, long l, String str2) throws RuntimeException {
199 return (int) f + i + str1.hashCode() + o.hashCode() + (int) l + str2.hashCode();
200 }
201
202 public void getVoid() throws RuntimeException {
203 }
204
205 public long getLong() throws RuntimeException {
206 return 1L;
207 }
208
209 public int getInt() throws RuntimeException {
210 return -1;
211 }
212
213 public short getShort() throws RuntimeException {
214 return 1;
215 }
216
217 public double getDouble() throws RuntimeException {
218 return 1.1D;
219 }
220
221 public float getFloat() throws RuntimeException {
222 return 1.1F;
223 }
224
225 public byte getByte() throws RuntimeException {
226 return Byte.parseByte("1");
227 }
228
229 public char getChar() throws RuntimeException {
230 return 'A';
231 }
232
233 public boolean getBoolean() throws RuntimeException {
234 return true;
235 }
236 }
237 }