1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 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.
19
19
import java .io .IOException ;
20
20
import java .io .InputStream ;
21
21
import java .lang .reflect .Constructor ;
22
- import java .lang .reflect .Member ;
22
+ import java .lang .reflect .Executable ;
23
23
import java .lang .reflect .Method ;
24
24
import java .util .Collections ;
25
25
import java .util .Map ;
51
51
* @author Costin Leau
52
52
* @author Juergen Hoeller
53
53
* @author Chris Beams
54
+ * @author Sam Brannen
54
55
* @since 2.0
55
56
*/
56
57
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
57
58
58
59
private static final Log logger = LogFactory .getLog (LocalVariableTableParameterNameDiscoverer .class );
59
60
60
61
// marker object for classes that do not have any debug info
61
- private static final Map <Member , String []> NO_DEBUG_INFO_MAP = Collections .emptyMap ();
62
+ private static final Map <Executable , String []> NO_DEBUG_INFO_MAP = Collections .emptyMap ();
62
63
63
64
// the cache uses a nested index (value is a map) to keep the top level cache relatively small in size
64
- private final Map <Class <?>, Map <Member , String []>> parameterNamesCache = new ConcurrentHashMap <>(32 );
65
+ private final Map <Class <?>, Map <Executable , String []>> parameterNamesCache = new ConcurrentHashMap <>(32 );
65
66
66
67
67
68
@ Override
68
69
@ Nullable
69
70
public String [] getParameterNames (Method method ) {
70
71
Method originalMethod = BridgeMethodResolver .findBridgedMethod (method );
71
- Class <?> declaringClass = originalMethod .getDeclaringClass ();
72
- Map <Member , String []> map = this .parameterNamesCache .computeIfAbsent (declaringClass , this ::inspectClass );
73
- if (map != NO_DEBUG_INFO_MAP ) {
74
- return map .get (originalMethod );
75
- }
76
- return null ;
72
+ return doGetParameterNames (originalMethod );
77
73
}
78
74
79
75
@ Override
80
76
@ Nullable
81
77
public String [] getParameterNames (Constructor <?> ctor ) {
82
- Class <?> declaringClass = ctor .getDeclaringClass ();
83
- Map <Member , String []> map = this .parameterNamesCache .computeIfAbsent (declaringClass , this ::inspectClass );
84
- if (map != NO_DEBUG_INFO_MAP ) {
85
- return map .get (ctor );
86
- }
87
- return null ;
78
+ return doGetParameterNames (ctor );
79
+ }
80
+
81
+ @ Nullable
82
+ private String [] doGetParameterNames (Executable executable ) {
83
+ Class <?> declaringClass = executable .getDeclaringClass ();
84
+ Map <Executable , String []> map = this .parameterNamesCache .computeIfAbsent (declaringClass , this ::inspectClass );
85
+ return (map != NO_DEBUG_INFO_MAP ? map .get (executable ) : null );
88
86
}
89
87
90
88
/**
91
- * Inspects the target class. Exceptions will be logged and a maker map returned
92
- * to indicate the lack of debug information.
89
+ * Inspects the target class.
90
+ * <p>Exceptions will be logged, and a marker map returned to indicate the
91
+ * lack of debug information.
93
92
*/
94
- private Map <Member , String []> inspectClass (Class <?> clazz ) {
93
+ private Map <Executable , String []> inspectClass (Class <?> clazz ) {
95
94
InputStream is = clazz .getResourceAsStream (ClassUtils .getClassFileName (clazz ));
96
95
if (is == null ) {
97
96
// We couldn't load the class file, which is not fatal as it
@@ -104,7 +103,7 @@ private Map<Member, String[]> inspectClass(Class<?> clazz) {
104
103
}
105
104
try {
106
105
ClassReader classReader = new ClassReader (is );
107
- Map <Member , String []> map = new ConcurrentHashMap <>(32 );
106
+ Map <Executable , String []> map = new ConcurrentHashMap <>(32 );
108
107
classReader .accept (new ParameterNameDiscoveringVisitor (clazz , map ), 0 );
109
108
return map ;
110
109
}
@@ -134,29 +133,29 @@ private Map<Member, String[]> inspectClass(Class<?> clazz) {
134
133
135
134
136
135
/**
137
- * Helper class that inspects all methods (constructor included) and then
138
- * attempts to find the parameter names for that member .
136
+ * Helper class that inspects all methods and constructors and then
137
+ * attempts to find the parameter names for the given {@link Executable} .
139
138
*/
140
139
private static class ParameterNameDiscoveringVisitor extends ClassVisitor {
141
140
142
141
private static final String STATIC_CLASS_INIT = "<clinit>" ;
143
142
144
143
private final Class <?> clazz ;
145
144
146
- private final Map <Member , String []> memberMap ;
145
+ private final Map <Executable , String []> executableMap ;
147
146
148
- public ParameterNameDiscoveringVisitor (Class <?> clazz , Map <Member , String []> memberMap ) {
147
+ public ParameterNameDiscoveringVisitor (Class <?> clazz , Map <Executable , String []> executableMap ) {
149
148
super (SpringAsmInfo .ASM_VERSION );
150
149
this .clazz = clazz ;
151
- this .memberMap = memberMap ;
150
+ this .executableMap = executableMap ;
152
151
}
153
152
154
153
@ Override
155
154
@ Nullable
156
155
public MethodVisitor visitMethod (int access , String name , String desc , String signature , String [] exceptions ) {
157
156
// exclude synthetic + bridged && static class initialization
158
157
if (!isSyntheticOrBridged (access ) && !STATIC_CLASS_INIT .equals (name )) {
159
- return new LocalVariableTableVisitor (this .clazz , this .memberMap , name , desc , isStatic (access ));
158
+ return new LocalVariableTableVisitor (this .clazz , this .executableMap , name , desc , isStatic (access ));
160
159
}
161
160
return null ;
162
161
}
@@ -177,7 +176,7 @@ private static class LocalVariableTableVisitor extends MethodVisitor {
177
176
178
177
private final Class <?> clazz ;
179
178
180
- private final Map <Member , String []> memberMap ;
179
+ private final Map <Executable , String []> executableMap ;
181
180
182
181
private final String name ;
183
182
@@ -195,10 +194,10 @@ private static class LocalVariableTableVisitor extends MethodVisitor {
195
194
*/
196
195
private final int [] lvtSlotIndex ;
197
196
198
- public LocalVariableTableVisitor (Class <?> clazz , Map <Member , String []> map , String name , String desc , boolean isStatic ) {
197
+ public LocalVariableTableVisitor (Class <?> clazz , Map <Executable , String []> map , String name , String desc , boolean isStatic ) {
199
198
super (SpringAsmInfo .ASM_VERSION );
200
199
this .clazz = clazz ;
201
- this .memberMap = map ;
200
+ this .executableMap = map ;
202
201
this .name = name ;
203
202
this .args = Type .getArgumentTypes (desc );
204
203
this .parameterNames = new String [this .args .length ];
@@ -223,11 +222,11 @@ public void visitEnd() {
223
222
// which doesn't use any local variables.
224
223
// This means that hasLvtInfo could be false for that kind of methods
225
224
// even if the class has local variable info.
226
- this .memberMap .put (resolveMember (), this .parameterNames );
225
+ this .executableMap .put (resolveExecutable (), this .parameterNames );
227
226
}
228
227
}
229
228
230
- private Member resolveMember () {
229
+ private Executable resolveExecutable () {
231
230
ClassLoader loader = this .clazz .getClassLoader ();
232
231
Class <?>[] argTypes = new Class <?>[this .args .length ];
233
232
for (int i = 0 ; i < this .args .length ; i ++) {
0 commit comments