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 org.codehaus.aspectwerkz.aspect;
9
10 import org.codehaus.aspectwerkz.transform.inlining.AsmHelper;
11 import org.codehaus.aspectwerkz.expression.ExpressionInfo;
12 import org.codehaus.aspectwerkz.expression.ExpressionContext;
13 import org.codehaus.aspectwerkz.definition.AdviceDefinition;
14 import org.codehaus.aspectwerkz.DeploymentModel;
15 import org.objectweb.asm.Type;
16
17 import java.io.Serializable;
18
19 /***
20 * Contains advice info, like indexes describing the aspect and a method (advice or introduced),
21 * aspect manager etc.
22 *
23 * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
24 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
25 */
26 public class AdviceInfo implements Serializable {
27
28 public final static AdviceInfo[] EMPTY_ADVICE_INFO_ARRAY = new AdviceInfo[0];
29
30
31
32 public final static int JOINPOINT_ARG = -0x1;
33 public final static int STATIC_JOINPOINT_ARG = -0x2;
34 public final static int TARGET_ARG = -0x3;
35 public final static int THIS_ARG = -0x4;
36 public final static int VALID_NON_AW_AROUND_CLOSURE_TYPE = -0x5;
37 public final static int SPECIAL_ARGUMENT = -0x6;
38 public static final int CUSTOM_JOIN_POINT_ARG = -0x7;
39
40 /***
41 * The method name.
42 */
43 private String m_methodName;
44
45 /***
46 * The method sig.
47 */
48 private String m_methodSignature;
49
50 /***
51 * The method's parameter types.
52 */
53 private Type[] m_methodParameterTypes;
54
55 /***
56 * The advice name
57 * <adviceMethodName>[(... call signature)]
58 */
59 private final String m_name;
60
61 /***
62 * The aspect class name where this advice is defined.
63 */
64 private String m_aspectClassName;
65
66 /***
67 * The aspect qualified name - <uuid>/<aspectNickName or FQNclassName>
68 */
69 private String m_aspectQualifiedName;
70
71 /***
72 * The aspect deployment model
73 */
74 private DeploymentModel m_aspectDeploymentModel;
75
76 /***
77 * The advice method arg index mapped to the advisED target arg index.
78 * If the value is greater or equal to 0, it is an args binding. Else, it is a magic index
79 * (see constants JOINPOINT_ARG, STATIC_JOINPOINT_ARG, THIS_ARG, TARGET_ARG)
80 */
81 private int[] m_methodToArgIndexes;
82
83 /***
84 * The "special" argument type desc for the advice.
85 */
86 private String m_specialArgumentTypeDesc;
87
88 /***
89 * The "special" argument type name for the advice.
90 */
91 private String m_specialArgumentTypeName;
92
93 /***
94 * The advice type.
95 */
96 private AdviceType m_type;
97
98 /***
99 * Runtime check flag.
100 */
101 private boolean m_targetWithRuntimeCheck;
102
103 /***
104 * The expression info.
105 */
106 private ExpressionInfo m_expressionInfo;
107
108 /***
109 * The expression context.
110 */
111 private ExpressionContext m_expressionContext;
112
113 /***
114 * The advice definition for this advice.
115 */
116 private AdviceDefinition m_adviceDef;
117
118 /***
119 * TODO refactor - many member fields holds data that is in either the adviceDef (which is in the class) or the aspectDef (which is accessible from the adviceDef)
120 * <p/>
121 * Creates a new advice info.
122 *
123 * @param aspectQualifiedName
124 * @param aspectClassName
125 * @param aspectDeploymentModel
126 * @param methodName
127 * @param methodSignature
128 * @param methodParameterTypes
129 * @param type the advice type
130 * @param specialArgumentType the special arg type
131 * @param adviceName full qualified advice method name (aspectFQN/advice(call sig))
132 * @param targetWithRuntimeCheck true if a runtime check is needed based on target instance
133 * @param expressionInfo
134 * @param expressionContext
135 * @param adviceDef
136 */
137 public AdviceInfo(final String aspectQualifiedName,
138 final String aspectClassName,
139 final DeploymentModel aspectDeploymentModel,
140 final String methodName,
141 final String methodSignature,
142 final Type[] methodParameterTypes,
143 final AdviceType type,
144 final String specialArgumentType,
145 final String adviceName,
146 final boolean targetWithRuntimeCheck,
147 final ExpressionInfo expressionInfo,
148 final ExpressionContext expressionContext,
149 final AdviceDefinition adviceDef) {
150 m_aspectQualifiedName = aspectQualifiedName;
151 m_aspectClassName = aspectClassName;
152 m_aspectDeploymentModel = aspectDeploymentModel;
153 m_methodName = methodName;
154 m_methodSignature = methodSignature;
155 m_methodParameterTypes = methodParameterTypes;
156 m_type = type;
157 if (specialArgumentType != null && specialArgumentType.length()>0) {
158 m_specialArgumentTypeDesc = AsmHelper.convertReflectDescToTypeDesc(specialArgumentType);
159 m_specialArgumentTypeName = specialArgumentType.replace('.', '/');
160 }
161 m_name = adviceName;
162 m_targetWithRuntimeCheck = targetWithRuntimeCheck;
163 m_expressionInfo = expressionInfo;
164 m_expressionContext = expressionContext;
165 m_adviceDef = adviceDef;
166 }
167
168 /***
169 * Return the method name.
170 *
171 * @return the method name
172 */
173 public String getMethodName() {
174 return m_methodName;
175 }
176
177 /***
178 * Return the method signature.
179 *
180 * @return the method signature
181 */
182 public String getMethodSignature() {
183 return m_methodSignature;
184 }
185
186 /***
187 * Return the method name.
188 *
189 * @return the method name
190 */
191 public Type[] getMethodParameterTypes() {
192 return m_methodParameterTypes;
193 }
194
195 /***
196 * Returns the aspect qualified name.
197 *
198 * @return the aspect qualified name
199 */
200 public String getAspectQualifiedName() {
201 return m_aspectQualifiedName;
202 }
203
204 /***
205 * Returns the aspect FQN className.
206 *
207 * @return the aspect class name
208 */
209 public String getAspectClassName() {
210 return m_aspectClassName;
211 }
212
213 /***
214 * Returns the aspect deployment model
215 *
216 * @return
217 */
218 public DeploymentModel getAspectDeploymentModel() {
219 return m_aspectDeploymentModel;
220 }
221
222 /***
223 * Returns the name of the advice.
224 *
225 * @return
226 */
227 public String getName() {
228 return m_name;
229 }
230
231 /***
232 * Sets the advice method to target method arg mapping A value of -1 means "not mapped"
233 *
234 * @param map
235 */
236 public void setMethodToArgIndexes(final int[] map) {
237 m_methodToArgIndexes = map;
238 }
239
240 /***
241 * Returns the advice method to target method arg index mapping.
242 *
243 * @return the indexes
244 */
245 public int[] getMethodToArgIndexes() {
246 return m_methodToArgIndexes;
247 }
248
249 /***
250 * Returns the special argument type desc.
251 *
252 * @return
253 */
254 public String getSpecialArgumentTypeDesc() {
255 return m_specialArgumentTypeDesc;
256 }
257
258 /***
259 * Returns the special argument type name.
260 *
261 * @return
262 */
263 public String getSpecialArgumentTypeName() {
264 return m_specialArgumentTypeName;
265 }
266
267 /***
268 * Returns the advice type.
269 *
270 * @return
271 */
272 public AdviceType getType() {
273 return m_type;
274 }
275
276 /***
277 * Checks if the target has a runtime check.
278 *
279 * @return
280 */
281 public boolean hasTargetWithRuntimeCheck() {
282 return m_targetWithRuntimeCheck;
283 }
284
285 /***
286 * Returns the expression info.
287 *
288 * @return
289 */
290 public ExpressionInfo getExpressionInfo() {
291 return m_expressionInfo;
292 }
293
294 /***
295 * Returns the expression context.
296 *
297 * @return
298 */
299 public ExpressionContext getExpressionContext() {
300 return m_expressionContext;
301 }
302
303 /***
304 * Returns the advice definition.
305 *
306 * @return
307 */
308 public AdviceDefinition getAdviceDefinition() {
309 return m_adviceDef;
310 }
311
312 public String toString() {
313 StringBuffer sb = new StringBuffer("AdviceInfo[");
314 sb.append(m_type).append(',');
315 sb.append(m_aspectQualifiedName).append(',');
316 sb.append(m_name).append(',');
317 sb.append(m_methodName).append(',');
318 sb.append(m_methodSignature).append(',');
319 sb.append(m_methodParameterTypes).append(',');
320 sb.append(m_specialArgumentTypeDesc).append(',');
321 sb.append(m_expressionInfo).append(',');
322 sb.append(m_expressionContext).append(',');
323 sb.append(m_targetWithRuntimeCheck).append(']');
324 sb.append(hashCode());
325 return sb.toString();
326 }
327
328 }