Class ReflectionTool

java.lang.Object
com.xxl.tool.core.ReflectionTool

public class ReflectionTool extends Object
Reflection Tool
Author:
xuxueli 2024-01-21 05:03:10
  • Constructor Details

    • ReflectionTool

      public ReflectionTool()
  • Method Details

    • getPackageName

      public static String getPackageName(Class<?> clazz)
      Returns the package name of clazz
      Parameters:
      clazz - the class to introspect
      Returns:
      package name of clazz
    • getPackageName

      public static String getPackageName(String classFullName)
      Returns the package name of classFullName
      Parameters:
      classFullName - the class to introspect
      Returns:
      package name of classFullName
    • findMethod

      public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes)
      find method of class by method method name and params
      Parameters:
      clazz - the class to introspect
      name - the name of the method
      paramTypes - the parameter types of the method
      Returns:
      the Method object, or null if none found
    • makeAccessible

      public static void makeAccessible(Method method)
      make method accessible
      Parameters:
      method - the method to make accessible
    • invokeMethod

      public static Object invokeMethod(Method method, Object target, Object... args)
      invoke method
      Parameters:
      method - method to invoke
      target - target object to invoke
      args - arguments to pass into method
      Returns:
      method invoke result
    • findField

      public static Field findField(Class<?> clazz, String name)
      find field of class by field name
      Parameters:
      clazz - class to introspect
      name - name of the field
      Returns:
      field object, or null if none found
    • findField

      public static Field findField(Class<?> clazz, String name, Class<?> type)
      find field of class by field name and field type
      Parameters:
      clazz - class to introspect
      name - name of the field
      type - type of the field
      Returns:
      field object, or null if none found
    • makeAccessible

      public static void makeAccessible(Field field)
      make field accessible
      Parameters:
      field - field to make accessible
    • setField

      public static void setField(Field field, Object target, Object value)
      set field value
      Parameters:
      field - field to set
      target - target object to set
      value - value to set
    • getField

      public static Object getField(Field field, Object target)
      get field value
      Parameters:
      field - field to get
      target - target object to get
      Returns:
      field value
    • isPublicStaticFinal

      public static boolean isPublicStaticFinal(Field field)
      check field is public static final
      Parameters:
      field - field to check
      Returns:
      true if field is public static final
    • doWithFields

      public static void doWithFields(Class<?> clazz, ReflectionTool.FieldCallback fc)
      iterate processing fields
      Parameters:
      clazz - class to introspect
      fc - callback to invoke for each field
    • newProxy

      public static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler)
      return a proxy instance that implements the specified interfaceType
      Type Parameters:
      T - the type of the proxy
      Parameters:
      interfaceType - interfaceType to implement
      handler - handler to handle method invocation
      Returns:
      a proxy instance