17
17
package org .springframework .aop .aspectj ;
18
18
19
19
import java .lang .reflect .Method ;
20
+ import java .lang .reflect .Modifier ;
20
21
21
22
import org .aspectj .lang .JoinPoint ;
22
23
import org .aspectj .lang .ProceedingJoinPoint ;
44
45
* @author Rod Johnson
45
46
* @author Juergen Hoeller
46
47
* @author Adrian Colyer
48
+ * @author Ramnivas Laddad
47
49
* @since 2.0
48
50
*/
49
51
public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint , JoinPoint .StaticPart {
@@ -132,19 +134,17 @@ public String getKind() {
132
134
public JoinPoint .StaticPart getStaticPart () {
133
135
return this ;
134
136
}
135
-
136
137
137
138
public String toShortString () {
138
- return "execution(" + this . methodInvocation . getMethod ().getName () + ")" ;
139
+ return "execution(" + getSignature ().toShortString () + ")" ;
139
140
}
140
141
141
142
public String toLongString () {
142
- return getClass (). getName () + ": execution: [ " + this . methodInvocation + "] " ;
143
+ return " execution( " + getSignature (). toLongString () + ") " ;
143
144
}
144
145
145
- @ Override
146
146
public String toString () {
147
- return getClass (). getName () + ": " + toShortString () ;
147
+ return "execution(" + getSignature (). toString () + ")" ;
148
148
}
149
149
150
150
@@ -153,14 +153,6 @@ public String toString() {
153
153
*/
154
154
private class MethodSignatureImpl implements Signature , MethodSignature {
155
155
156
- public String toShortString () {
157
- return methodInvocation .getMethod ().getName ();
158
- }
159
-
160
- public String toLongString () {
161
- return methodInvocation .getMethod ().toString ();
162
- }
163
-
164
156
public String getName () {
165
157
return methodInvocation .getMethod ().getName ();
166
158
}
@@ -199,8 +191,75 @@ public String[] getParameterNames() {
199
191
public Class [] getExceptionTypes () {
200
192
return methodInvocation .getMethod ().getExceptionTypes ();
201
193
}
194
+
195
+ public String toShortString () {
196
+ return toString (false , false , false , false );
197
+ }
198
+
199
+ public String toLongString () {
200
+ return toString (true , true , true , true );
201
+ }
202
+
203
+ public String toString () {
204
+ return toString (false , true , false , true );
205
+ }
206
+
207
+ private String toString (boolean includeModifier ,
208
+ boolean includeReturnTypeAndArgs ,
209
+ boolean useLongReturnAndArgumentTypeName ,
210
+ boolean useLongTypeName ) {
211
+ StringBuilder sb = new StringBuilder ();
212
+ if (includeModifier ) {
213
+ sb .append (Modifier .toString (getModifiers ()));
214
+ sb .append (" " );
215
+ }
216
+ if (includeReturnTypeAndArgs ) {
217
+ appendType (sb , getReturnType (),
218
+ useLongReturnAndArgumentTypeName );
219
+ sb .append (" " );
220
+ }
221
+ appendType (sb , getDeclaringType (), useLongTypeName );
222
+ sb .append ("." );
223
+ sb .append (getMethod ().getName ());
224
+ sb .append ("(" );
225
+
226
+ Class [] parametersTypes = getParameterTypes ();
227
+ appendTypes (sb , parametersTypes , includeReturnTypeAndArgs ,
228
+ useLongReturnAndArgumentTypeName );
229
+ sb .append (")" );
230
+ return sb .toString ();
231
+ }
232
+ }
233
+
234
+ private void appendTypes (StringBuilder sb , Class <?>[] types ,
235
+ boolean includeArgs , boolean useLongReturnAndArgumentTypeName ) {
236
+ if (includeArgs ) {
237
+ for (int size = types .length , i = 0 ; i < size ; i ++) {
238
+ appendType (sb , types [i ], useLongReturnAndArgumentTypeName );
239
+ if (i < size - 1 ) {
240
+ sb .append ("," );
241
+ }
242
+ }
243
+ } else {
244
+ if (types .length != 0 ) {
245
+ sb .append (".." );
246
+ }
247
+ }
202
248
}
203
249
250
+ private void appendType (StringBuilder sb , Class <?> type ,
251
+ boolean useLongTypeName ) {
252
+ if (type .isArray ()) {
253
+ appendType (sb , type .getComponentType (), useLongTypeName );
254
+ sb .append ("[]" );
255
+ } else {
256
+ if (type .getPackage () != null
257
+ && type .getPackage ().equals ("java.lang" )) {
258
+ useLongTypeName = false ;
259
+ }
260
+ sb .append (useLongTypeName ? type .getName () : type .getSimpleName ());
261
+ }
262
+ }
204
263
205
264
/**
206
265
* Lazily initialized SourceLocation.
0 commit comments