15
15
*/
16
16
package org .apache .ibatis .reflection ;
17
17
18
- import java .lang .reflect .Array ;
19
- import java .lang .reflect .Constructor ;
20
- import java .lang .reflect .Field ;
21
- import java .lang .reflect .GenericArrayType ;
22
- import java .lang .reflect .Method ;
23
- import java .lang .reflect .Modifier ;
24
- import java .lang .reflect .ParameterizedType ;
25
- import java .lang .reflect .ReflectPermission ;
26
- import java .lang .reflect .Type ;
27
- import java .text .MessageFormat ;
28
- import java .util .ArrayList ;
29
- import java .util .Arrays ;
30
- import java .util .Collection ;
31
- import java .util .HashMap ;
32
- import java .util .List ;
33
- import java .util .Locale ;
34
- import java .util .Map ;
35
- import java .util .Map .Entry ;
36
-
37
- import org .apache .ibatis .reflection .invoker .AmbiguousMethodInvoker ;
38
- import org .apache .ibatis .reflection .invoker .GetFieldInvoker ;
39
- import org .apache .ibatis .reflection .invoker .Invoker ;
40
- import org .apache .ibatis .reflection .invoker .MethodInvoker ;
41
- import org .apache .ibatis .reflection .invoker .SetFieldInvoker ;
18
+ import org .apache .ibatis .reflection .invoker .*;
42
19
import org .apache .ibatis .reflection .property .PropertyNamer ;
43
20
import org .apache .ibatis .util .MapUtil ;
44
21
22
+ import java .lang .reflect .*;
23
+ import java .text .MessageFormat ;
24
+ import java .util .*;
25
+ import java .util .Map .Entry ;
26
+
45
27
/**
46
28
* This class represents a cached set of class definition information that
47
29
* allows for easy mapping between property names and getter/setter methods.
@@ -60,6 +42,7 @@ public class Reflector {
60
42
private Constructor <?> defaultConstructor ;
61
43
62
44
private Map <String , String > caseInsensitivePropertyMap = new HashMap <>();
45
+ private Method [] allMethods ;
63
46
64
47
public Reflector (Class <?> clazz ) {
65
48
type = clazz ;
@@ -85,7 +68,7 @@ private void addDefaultConstructor(Class<?> clazz) {
85
68
86
69
private void addGetMethods (Class <?> clazz ) {
87
70
Map <String , List <Method >> conflictingGetters = new HashMap <>();
88
- Method [] methods = getClassMethods (clazz );
71
+ Method [] methods = allMethods == null ? getClassMethods (clazz ): allMethods ;
89
72
Arrays .stream (methods ).filter (m -> m .getParameterTypes ().length == 0 && PropertyNamer .isGetter (m .getName ()))
90
73
.forEach (m -> addMethodConflict (conflictingGetters , PropertyNamer .methodToProperty (m .getName ()), m ));
91
74
resolveGetterConflicts (conflictingGetters );
@@ -136,7 +119,7 @@ private void addGetMethod(String name, Method method, boolean isAmbiguous) {
136
119
137
120
private void addSetMethods (Class <?> clazz ) {
138
121
Map <String , List <Method >> conflictingSetters = new HashMap <>();
139
- Method [] methods = getClassMethods (clazz );
122
+ Method [] methods = allMethods == null ? getClassMethods (clazz ): allMethods ;
140
123
Arrays .stream (methods ).filter (m -> m .getParameterTypes ().length == 1 && PropertyNamer .isSetter (m .getName ()))
141
124
.forEach (m -> addMethodConflict (conflictingSetters , PropertyNamer .methodToProperty (m .getName ()), m ));
142
125
resolveSetterConflicts (conflictingSetters );
@@ -290,8 +273,8 @@ private Method[] getClassMethods(Class<?> clazz) {
290
273
}
291
274
292
275
Collection <Method > methods = uniqueMethods .values ();
293
-
294
- return methods . toArray ( new Method [ 0 ]) ;
276
+ allMethods = methods . toArray ( new Method [ 0 ]);
277
+ return allMethods ;
295
278
}
296
279
297
280
private void addUniqueMethods (Map <String , Method > uniqueMethods , Method [] methods ) {
0 commit comments