Package org.apache.ibatis.reflection
Class Reflector
- java.lang.Object
-
- org.apache.ibatis.reflection.Reflector
-
public class Reflector extends java.lang.ObjectThis class represents a cached set of class definition information that allows for easy mapping between property names and getter/setter methods.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>caseInsensitivePropertyMapprivate java.lang.reflect.Constructor<?>defaultConstructorprivate java.util.Map<java.lang.String,Invoker>getMethodsprivate java.util.Map<java.lang.String,java.lang.Class<?>>getTypesprivate static java.lang.invoke.MethodHandleisRecordMethodHandleprivate java.lang.String[]readablePropertyNamesprivate java.util.Map<java.lang.String,Invoker>setMethodsprivate java.util.Map<java.lang.String,java.lang.Class<?>>setTypesprivate java.lang.Class<?>typeprivate java.lang.String[]writablePropertyNames
-
Constructor Summary
Constructors Constructor Description Reflector(java.lang.Class<?> clazz)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddDefaultConstructor(java.lang.Class<?> clazz)private voidaddFields(java.lang.Class<?> clazz)private voidaddGetField(java.lang.reflect.Field field)private voidaddGetMethod(java.lang.String name, java.lang.reflect.Method method, boolean isAmbiguous)private voidaddGetMethods(java.lang.reflect.Method[] methods)private voidaddMethodConflict(java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> conflictingMethods, java.lang.String name, java.lang.reflect.Method method)private voidaddRecordGetMethods(java.lang.reflect.Method[] methods)private voidaddSetField(java.lang.reflect.Field field)private voidaddSetMethod(java.lang.String name, java.lang.reflect.Method method)private voidaddSetMethods(java.lang.reflect.Method[] methods)private voidaddUniqueMethods(java.util.Map<java.lang.String,java.lang.reflect.Method> uniqueMethods, java.lang.reflect.Method[] methods)static booleancanControlMemberAccessible()Checks whether can control member accessible.java.lang.StringfindPropertyName(java.lang.String name)private java.lang.reflect.Method[]getClassMethods(java.lang.Class<?> clazz)This method returns an array containing all methods declared in this class and any superclass.java.lang.reflect.Constructor<?>getDefaultConstructor()java.lang.String[]getGetablePropertyNames()Gets an array of the readable properties for an object.InvokergetGetInvoker(java.lang.String propertyName)java.lang.Class<?>getGetterType(java.lang.String propertyName)Gets the type for a property getter.private static java.lang.invoke.MethodHandlegetIsRecordMethodHandle()java.lang.String[]getSetablePropertyNames()Gets an array of the writable properties for an object.InvokergetSetInvoker(java.lang.String propertyName)java.lang.Class<?>getSetterType(java.lang.String propertyName)Gets the type for a property setter.private java.lang.StringgetSignature(java.lang.reflect.Method method)java.lang.Class<?>getType()Gets the name of the class the instance provides information for.booleanhasDefaultConstructor()booleanhasGetter(java.lang.String propertyName)Check to see if a class has a readable property by name.booleanhasSetter(java.lang.String propertyName)Check to see if a class has a writable property by name.private static booleanisRecord(java.lang.Class<?> clazz)Class.isRecord() alternative for Java 15 and older.private booleanisValidPropertyName(java.lang.String name)private java.lang.reflect.MethodpickBetterSetter(java.lang.reflect.Method setter1, java.lang.reflect.Method setter2, java.lang.String property)private voidresolveGetterConflicts(java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> conflictingGetters)private voidresolveSetterConflicts(java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> conflictingSetters)private java.lang.Class<?>typeToClass(java.lang.reflect.Type src)
-
-
-
Field Detail
-
isRecordMethodHandle
private static final java.lang.invoke.MethodHandle isRecordMethodHandle
-
type
private final java.lang.Class<?> type
-
readablePropertyNames
private final java.lang.String[] readablePropertyNames
-
writablePropertyNames
private final java.lang.String[] writablePropertyNames
-
setMethods
private final java.util.Map<java.lang.String,Invoker> setMethods
-
getMethods
private final java.util.Map<java.lang.String,Invoker> getMethods
-
setTypes
private final java.util.Map<java.lang.String,java.lang.Class<?>> setTypes
-
getTypes
private final java.util.Map<java.lang.String,java.lang.Class<?>> getTypes
-
defaultConstructor
private java.lang.reflect.Constructor<?> defaultConstructor
-
caseInsensitivePropertyMap
private final java.util.Map<java.lang.String,java.lang.String> caseInsensitivePropertyMap
-
-
Method Detail
-
addRecordGetMethods
private void addRecordGetMethods(java.lang.reflect.Method[] methods)
-
addDefaultConstructor
private void addDefaultConstructor(java.lang.Class<?> clazz)
-
addGetMethods
private void addGetMethods(java.lang.reflect.Method[] methods)
-
resolveGetterConflicts
private void resolveGetterConflicts(java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> conflictingGetters)
-
addGetMethod
private void addGetMethod(java.lang.String name, java.lang.reflect.Method method, boolean isAmbiguous)
-
addSetMethods
private void addSetMethods(java.lang.reflect.Method[] methods)
-
addMethodConflict
private void addMethodConflict(java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> conflictingMethods, java.lang.String name, java.lang.reflect.Method method)
-
resolveSetterConflicts
private void resolveSetterConflicts(java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> conflictingSetters)
-
pickBetterSetter
private java.lang.reflect.Method pickBetterSetter(java.lang.reflect.Method setter1, java.lang.reflect.Method setter2, java.lang.String property)
-
addSetMethod
private void addSetMethod(java.lang.String name, java.lang.reflect.Method method)
-
typeToClass
private java.lang.Class<?> typeToClass(java.lang.reflect.Type src)
-
addFields
private void addFields(java.lang.Class<?> clazz)
-
addSetField
private void addSetField(java.lang.reflect.Field field)
-
addGetField
private void addGetField(java.lang.reflect.Field field)
-
isValidPropertyName
private boolean isValidPropertyName(java.lang.String name)
-
getClassMethods
private java.lang.reflect.Method[] getClassMethods(java.lang.Class<?> clazz)
This method returns an array containing all methods declared in this class and any superclass. We use this method, instead of the simplerClass.getMethods(), because we want to look for private methods as well.- Parameters:
clazz- The class- Returns:
- An array containing all methods in this class
-
addUniqueMethods
private void addUniqueMethods(java.util.Map<java.lang.String,java.lang.reflect.Method> uniqueMethods, java.lang.reflect.Method[] methods)
-
getSignature
private java.lang.String getSignature(java.lang.reflect.Method method)
-
canControlMemberAccessible
public static boolean canControlMemberAccessible()
Checks whether can control member accessible.- Returns:
- If can control member accessible, it return true
- Since:
- 3.5.0
-
getType
public java.lang.Class<?> getType()
Gets the name of the class the instance provides information for.- Returns:
- The class name
-
getDefaultConstructor
public java.lang.reflect.Constructor<?> getDefaultConstructor()
-
hasDefaultConstructor
public boolean hasDefaultConstructor()
-
getSetInvoker
public Invoker getSetInvoker(java.lang.String propertyName)
-
getGetInvoker
public Invoker getGetInvoker(java.lang.String propertyName)
-
getSetterType
public java.lang.Class<?> getSetterType(java.lang.String propertyName)
Gets the type for a property setter.- Parameters:
propertyName- - the name of the property- Returns:
- The Class of the property setter
-
getGetterType
public java.lang.Class<?> getGetterType(java.lang.String propertyName)
Gets the type for a property getter.- Parameters:
propertyName- - the name of the property- Returns:
- The Class of the property getter
-
getGetablePropertyNames
public java.lang.String[] getGetablePropertyNames()
Gets an array of the readable properties for an object.- Returns:
- The array
-
getSetablePropertyNames
public java.lang.String[] getSetablePropertyNames()
Gets an array of the writable properties for an object.- Returns:
- The array
-
hasSetter
public boolean hasSetter(java.lang.String propertyName)
Check to see if a class has a writable property by name.- Parameters:
propertyName- - the name of the property to check- Returns:
- True if the object has a writable property by the name
-
hasGetter
public boolean hasGetter(java.lang.String propertyName)
Check to see if a class has a readable property by name.- Parameters:
propertyName- - the name of the property to check- Returns:
- True if the object has a readable property by the name
-
findPropertyName
public java.lang.String findPropertyName(java.lang.String name)
-
isRecord
private static boolean isRecord(java.lang.Class<?> clazz)
Class.isRecord() alternative for Java 15 and older.
-
getIsRecordMethodHandle
private static java.lang.invoke.MethodHandle getIsRecordMethodHandle()
-
-