15
15
*/
16
16
package org .apache .ibatis .reflection ;
17
17
18
- import org .apache .ibatis .reflection .invoker .*;
18
+ import org .apache .ibatis .reflection .invoker .AmbiguousMethodInvoker ;
19
+ import org .apache .ibatis .reflection .invoker .GetFieldInvoker ;
20
+ import org .apache .ibatis .reflection .invoker .Invoker ;
21
+ import org .apache .ibatis .reflection .invoker .MethodInvoker ;
22
+ import org .apache .ibatis .reflection .invoker .SetFieldInvoker ;
19
23
import org .apache .ibatis .reflection .property .PropertyNamer ;
20
24
import org .apache .ibatis .util .MapUtil ;
21
25
22
- import java .lang .reflect .*;
26
+ import java .lang .reflect .Array ;
27
+ import java .lang .reflect .Constructor ;
28
+ import java .lang .reflect .Field ;
29
+ import java .lang .reflect .GenericArrayType ;
30
+ import java .lang .reflect .Method ;
31
+ import java .lang .reflect .Modifier ;
32
+ import java .lang .reflect .ParameterizedType ;
33
+ import java .lang .reflect .ReflectPermission ;
34
+ import java .lang .reflect .Type ;
23
35
import java .text .MessageFormat ;
24
- import java .util .*;
36
+ import java .util .ArrayList ;
37
+ import java .util .Arrays ;
38
+ import java .util .Collection ;
39
+ import java .util .HashMap ;
40
+ import java .util .List ;
41
+ import java .util .Locale ;
42
+ import java .util .Map ;
25
43
import java .util .Map .Entry ;
26
44
27
45
/**
@@ -42,13 +60,13 @@ public class Reflector {
42
60
private Constructor <?> defaultConstructor ;
43
61
44
62
private Map <String , String > caseInsensitivePropertyMap = new HashMap <>();
45
- private Method [] allMethods ;
46
63
47
64
public Reflector (Class <?> clazz ) {
48
65
type = clazz ;
49
66
addDefaultConstructor (clazz );
50
- addGetMethods (clazz );
51
- addSetMethods (clazz );
67
+ Method [] allMethods = getClassMethods (clazz );
68
+ addGetMethods (allMethods );
69
+ addSetMethods (allMethods );
52
70
addFields (clazz );
53
71
readablePropertyNames = getMethods .keySet ().toArray (new String [0 ]);
54
72
writablePropertyNames = setMethods .keySet ().toArray (new String [0 ]);
@@ -66,9 +84,8 @@ private void addDefaultConstructor(Class<?> clazz) {
66
84
.findAny ().ifPresent (constructor -> this .defaultConstructor = constructor );
67
85
}
68
86
69
- private void addGetMethods (Class <?> clazz ) {
87
+ private void addGetMethods (Method [] methods ) {
70
88
Map <String , List <Method >> conflictingGetters = new HashMap <>();
71
- Method [] methods = allMethods ==null ?getClassMethods (clazz ):allMethods ;
72
89
Arrays .stream (methods ).filter (m -> m .getParameterTypes ().length == 0 && PropertyNamer .isGetter (m .getName ()))
73
90
.forEach (m -> addMethodConflict (conflictingGetters , PropertyNamer .methodToProperty (m .getName ()), m ));
74
91
resolveGetterConflicts (conflictingGetters );
@@ -117,9 +134,8 @@ private void addGetMethod(String name, Method method, boolean isAmbiguous) {
117
134
getTypes .put (name , typeToClass (returnType ));
118
135
}
119
136
120
- private void addSetMethods (Class <?> clazz ) {
137
+ private void addSetMethods (Method [] methods ) {
121
138
Map <String , List <Method >> conflictingSetters = new HashMap <>();
122
- Method [] methods = allMethods ==null ?getClassMethods (clazz ):allMethods ;
123
139
Arrays .stream (methods ).filter (m -> m .getParameterTypes ().length == 1 && PropertyNamer .isSetter (m .getName ()))
124
140
.forEach (m -> addMethodConflict (conflictingSetters , PropertyNamer .methodToProperty (m .getName ()), m ));
125
141
resolveSetterConflicts (conflictingSetters );
@@ -273,8 +289,7 @@ private Method[] getClassMethods(Class<?> clazz) {
273
289
}
274
290
275
291
Collection <Method > methods = uniqueMethods .values ();
276
- allMethods = methods .toArray (new Method [0 ]);
277
- return allMethods ;
292
+ return methods .toArray (new Method [0 ]);
278
293
}
279
294
280
295
private void addUniqueMethods (Map <String , Method > uniqueMethods , Method [] methods ) {
0 commit comments