Class Reflector

java.lang.Object
org.apache.ibatis.reflection.Reflector

public class Reflector extends Object
This class represents a cached set of class definition information that allows for easy mapping between property names and getter/setter methods.
  • Field Details

    • type

      private final Class<?> type
    • readablePropertyNames

      private final String[] readablePropertyNames
    • writablePropertyNames

      private final String[] writablePropertyNames
    • setMethods

      private final Map<String,Invoker> setMethods
    • getMethods

      private final Map<String,Invoker> getMethods
    • setTypes

      private final Map<String,Class<?>> setTypes
    • getTypes

      private final Map<String,Class<?>> getTypes
    • defaultConstructor

      private Constructor<?> defaultConstructor
    • caseInsensitivePropertyMap

      private Map<String,String> caseInsensitivePropertyMap
  • Constructor Details

    • Reflector

      public Reflector(Class<?> clazz)
  • Method Details

    • addDefaultConstructor

      private void addDefaultConstructor(Class<?> clazz)
    • addGetMethods

      private void addGetMethods(Class<?> clazz)
    • resolveGetterConflicts

      private void resolveGetterConflicts(Map<String,List<Method>> conflictingGetters)
    • addGetMethod

      private void addGetMethod(String name, Method method, boolean isAmbiguous)
    • addSetMethods

      private void addSetMethods(Class<?> clazz)
    • addMethodConflict

      private void addMethodConflict(Map<String,List<Method>> conflictingMethods, String name, Method method)
    • resolveSetterConflicts

      private void resolveSetterConflicts(Map<String,List<Method>> conflictingSetters)
    • pickBetterSetter

      private Method pickBetterSetter(Method setter1, Method setter2, String property)
    • addSetMethod

      private void addSetMethod(String name, Method method)
    • typeToClass

      private Class<?> typeToClass(Type src)
    • addFields

      private void addFields(Class<?> clazz)
    • addSetField

      private void addSetField(Field field)
    • addGetField

      private void addGetField(Field field)
    • isValidPropertyName

      private boolean isValidPropertyName(String name)
    • getClassMethods

      private Method[] getClassMethods(Class<?> clazz)
      This method returns an array containing all methods declared in this class and any superclass. We use this method, instead of the simpler Class.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(Map<String,Method> uniqueMethods, Method[] methods)
    • getSignature

      private String getSignature(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 Class<?> getType()
      Gets the name of the class the instance provides information for.
      Returns:
      The class name
    • getDefaultConstructor

      public Constructor<?> getDefaultConstructor()
    • hasDefaultConstructor

      public boolean hasDefaultConstructor()
    • getSetInvoker

      public Invoker getSetInvoker(String propertyName)
    • getGetInvoker

      public Invoker getGetInvoker(String propertyName)
    • getSetterType

      public Class<?> getSetterType(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 Class<?> getGetterType(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 String[] getGetablePropertyNames()
      Gets an array of the readable properties for an object.
      Returns:
      The array
    • getSetablePropertyNames

      public String[] getSetablePropertyNames()
      Gets an array of the writable properties for an object.
      Returns:
      The array
    • hasSetter

      public boolean hasSetter(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(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 String findPropertyName(String name)