1515 */
1616package org .apache .ibatis .reflection ;
1717
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 ;
1923import org .apache .ibatis .reflection .property .PropertyNamer ;
2024import org .apache .ibatis .util .MapUtil ;
2125
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 ;
2335import 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 ;
2543import java .util .Map .Entry ;
2644
2745/**
@@ -42,13 +60,13 @@ public class Reflector {
4260 private Constructor <?> defaultConstructor ;
4361
4462 private Map <String , String > caseInsensitivePropertyMap = new HashMap <>();
45- private Method [] allMethods ;
4663
4764 public Reflector (Class <?> clazz ) {
4865 type = clazz ;
4966 addDefaultConstructor (clazz );
50- addGetMethods (clazz );
51- addSetMethods (clazz );
67+ Method [] allMethods = getClassMethods (clazz );
68+ addGetMethods (allMethods );
69+ addSetMethods (allMethods );
5270 addFields (clazz );
5371 readablePropertyNames = getMethods .keySet ().toArray (new String [0 ]);
5472 writablePropertyNames = setMethods .keySet ().toArray (new String [0 ]);
@@ -66,9 +84,8 @@ private void addDefaultConstructor(Class<?> clazz) {
6684 .findAny ().ifPresent (constructor -> this .defaultConstructor = constructor );
6785 }
6886
69- private void addGetMethods (Class <?> clazz ) {
87+ private void addGetMethods (Method [] methods ) {
7088 Map <String , List <Method >> conflictingGetters = new HashMap <>();
71- Method [] methods = allMethods ==null ?getClassMethods (clazz ):allMethods ;
7289 Arrays .stream (methods ).filter (m -> m .getParameterTypes ().length == 0 && PropertyNamer .isGetter (m .getName ()))
7390 .forEach (m -> addMethodConflict (conflictingGetters , PropertyNamer .methodToProperty (m .getName ()), m ));
7491 resolveGetterConflicts (conflictingGetters );
@@ -117,9 +134,8 @@ private void addGetMethod(String name, Method method, boolean isAmbiguous) {
117134 getTypes .put (name , typeToClass (returnType ));
118135 }
119136
120- private void addSetMethods (Class <?> clazz ) {
137+ private void addSetMethods (Method [] methods ) {
121138 Map <String , List <Method >> conflictingSetters = new HashMap <>();
122- Method [] methods = allMethods ==null ?getClassMethods (clazz ):allMethods ;
123139 Arrays .stream (methods ).filter (m -> m .getParameterTypes ().length == 1 && PropertyNamer .isSetter (m .getName ()))
124140 .forEach (m -> addMethodConflict (conflictingSetters , PropertyNamer .methodToProperty (m .getName ()), m ));
125141 resolveSetterConflicts (conflictingSetters );
@@ -273,8 +289,7 @@ private Method[] getClassMethods(Class<?> clazz) {
273289 }
274290
275291 Collection <Method > methods = uniqueMethods .values ();
276- allMethods = methods .toArray (new Method [0 ]);
277- return allMethods ;
292+ return methods .toArray (new Method [0 ]);
278293 }
279294
280295 private void addUniqueMethods (Map <String , Method > uniqueMethods , Method [] methods ) {
0 commit comments