1
1
/*
2
- * Copyright 2002-2009 the original author or authors.
2
+ * Copyright 2002-2010 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
27
27
28
28
import org .apache .commons .logging .Log ;
29
29
import org .apache .commons .logging .LogFactory ;
30
+
30
31
import org .springframework .asm .ClassReader ;
31
32
import org .springframework .asm .Label ;
32
33
import org .springframework .asm .MethodVisitor ;
46
47
* as far as possible.
47
48
*
48
49
* @author Adrian Colyer
49
- * @author Juergen Hoeller
50
50
* @author Costin Leau
51
+ * @author Juergen Hoeller
51
52
* @since 2.0
52
53
*/
53
54
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
54
55
55
56
private static Log logger = LogFactory .getLog (LocalVariableTableParameterNameDiscoverer .class );
56
57
57
- // the cache uses a nested index (value is a map) to keep the top level cache relatively small in size
58
- private final Map <Class <?>, Map <Member , String []>> parameterNamesCache = new ConcurrentHashMap <Class <?>, Map <Member , String []>>();
59
-
60
58
// marker object for classes that do not have any debug info
61
59
private static final Map <Member , String []> NO_DEBUG_INFO_MAP = Collections .emptyMap ();
62
60
61
+ // the cache uses a nested index (value is a map) to keep the top level cache relatively small in size
62
+ private final Map <Class <?>, Map <Member , String []>> parameterNamesCache =
63
+ new ConcurrentHashMap <Class <?>, Map <Member , String []>>();
64
+
65
+
63
66
public String [] getParameterNames (Method method ) {
64
67
Class <?> declaringClass = method .getDeclaringClass ();
65
- Map <Member , String []> map = parameterNamesCache .get (declaringClass );
68
+ Map <Member , String []> map = this . parameterNamesCache .get (declaringClass );
66
69
if (map == null ) {
67
70
// initialize cache
68
71
map = inspectClass (declaringClass );
69
- parameterNamesCache .put (declaringClass , map );
72
+ this . parameterNamesCache .put (declaringClass , map );
70
73
}
71
74
if (map != NO_DEBUG_INFO_MAP ) {
72
75
return map .get (method );
@@ -77,11 +80,11 @@ public String[] getParameterNames(Method method) {
77
80
@ SuppressWarnings ("unchecked" )
78
81
public String [] getParameterNames (Constructor ctor ) {
79
82
Class <?> declaringClass = ctor .getDeclaringClass ();
80
- Map <Member , String []> map = parameterNamesCache .get (declaringClass );
83
+ Map <Member , String []> map = this . parameterNamesCache .get (declaringClass );
81
84
if (map == null ) {
82
85
// initialize cache
83
86
map = inspectClass (declaringClass );
84
- parameterNamesCache .put (declaringClass , map );
87
+ this . parameterNamesCache .put (declaringClass , map );
85
88
}
86
89
if (map != NO_DEBUG_INFO_MAP ) {
87
90
return map .get (ctor );
@@ -91,10 +94,8 @@ public String[] getParameterNames(Constructor ctor) {
91
94
}
92
95
93
96
/**
94
- * Inspects the target class. Exceptions will be logged and a maker map returned to indicate the lack of debug information.
95
- *
96
- * @param clazz
97
- * @return
97
+ * Inspects the target class. Exceptions will be logged and a maker map returned
98
+ * to indicate the lack of debug information.
98
99
*/
99
100
private Map <Member , String []> inspectClass (Class <?> clazz ) {
100
101
InputStream is = clazz .getResourceAsStream (ClassUtils .getClassFileName (clazz ));
@@ -105,40 +106,42 @@ private Map<Member, String[]> inspectClass(Class<?> clazz) {
105
106
logger .debug ("Cannot find '.class' file for class [" + clazz
106
107
+ "] - unable to determine constructors/methods parameter names" );
107
108
}
108
-
109
109
return NO_DEBUG_INFO_MAP ;
110
110
}
111
-
112
111
try {
113
112
ClassReader classReader = new ClassReader (is );
114
113
Map <Member , String []> map = new ConcurrentHashMap <Member , String []>();
115
114
classReader .accept (new ParameterNameDiscoveringVisitor (clazz , map ), false );
116
115
return map ;
117
- } catch (IOException ex ) {
116
+ }
117
+ catch (IOException ex ) {
118
118
if (logger .isDebugEnabled ()) {
119
119
logger .debug ("Exception thrown while reading '.class' file for class [" + clazz
120
120
+ "] - unable to determine constructors/methods parameter names" , ex );
121
121
}
122
- } finally {
122
+ }
123
+ finally {
123
124
try {
124
125
is .close ();
125
- } catch (IOException ex ) {
126
+ }
127
+ catch (IOException ex ) {
126
128
// ignore
127
129
}
128
130
}
129
-
130
131
return NO_DEBUG_INFO_MAP ;
131
132
}
132
133
134
+
133
135
/**
134
136
* Helper class that inspects all methods (constructor included) and then
135
137
* attempts to find the parameter names for that member.
136
138
*/
137
139
private static class ParameterNameDiscoveringVisitor extends EmptyVisitor {
138
140
141
+ private static final String STATIC_CLASS_INIT = "<clinit>" ;
142
+
139
143
private final Class <?> clazz ;
140
144
private final Map <Member , String []> memberMap ;
141
- private static final String STATIC_CLASS_INIT = "<clinit>" ;
142
145
143
146
public ParameterNameDiscoveringVisitor (Class <?> clazz , Map <Member , String []> memberMap ) {
144
147
this .clazz = clazz ;
@@ -163,6 +166,7 @@ private static boolean isStatic(int access) {
163
166
}
164
167
}
165
168
169
+
166
170
private static class LocalVariableTableVisitor extends EmptyVisitor {
167
171
168
172
private static final String CONSTRUCTOR = "<init>" ;
@@ -255,4 +259,5 @@ private static boolean isWideType(Type aType) {
255
259
return (aType == Type .LONG_TYPE || aType == Type .DOUBLE_TYPE );
256
260
}
257
261
}
258
- }
262
+
263
+ }
0 commit comments