Interface MethodUtils


public interface MethodUtils
Miscellaneous method utility methods. Mainly for internal use within the framework.
Since:
2.7.2
  • Method Details

    • isSetter

      static boolean isSetter(Method method)
      Return true if the provided method is a set method. Otherwise, return false.
      Parameters:
      method - the method to check
      Returns:
      whether the given method is setter method
    • isGetter

      static boolean isGetter(Method method)
      Return true if the provided method is a get method. Otherwise, return false.
      Parameters:
      method - the method to check
      Returns:
      whether the given method is getter method
    • isMetaMethod

      static boolean isMetaMethod(Method method)
      Return true If this method is a meta method. Otherwise, return false.
      Parameters:
      method - the method to check
      Returns:
      whether the given method is meta method
    • isDeprecated

      static boolean isDeprecated(Method method)
      Check if the method is a deprecated method. The standard is whether the Deprecated annotation is declared on the class. Return true if this annotation is present. Otherwise, return false.
      Parameters:
      method - the method to check
      Returns:
      whether the given method is deprecated method
    • excludedDeclaredClass

      static Predicate<Method> excludedDeclaredClass(Class<?> declaredClass)
      Create an instance of Predicate for Method to exclude the specified declared class
      Parameters:
      declaredClass - the declared class to exclude
      Returns:
      non-null
      Since:
      2.7.6
    • getMethods

      static List<Method> getMethods(Class<?> declaringClass, boolean includeInheritedTypes, boolean publicOnly, Predicate<Method>... methodsToFilter)
      Get all methods of the declared class
      Parameters:
      declaringClass - the declared class
      includeInheritedTypes - include the inherited types, e,g. super classes or interfaces
      publicOnly - only public method
      methodsToFilter - (optional) the methods to be filtered
      Returns:
      non-null read-only List
      Since:
      2.7.6
    • getDeclaredMethods

      static List<Method> getDeclaredMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter)
      Get all declared methods of the declared class, excluding the inherited methods
      Parameters:
      declaringClass - the declared class
      methodsToFilter - (optional) the methods to be filtered
      Returns:
      non-null read-only List
      Since:
      2.7.6
      See Also:
    • getMethods

      static List<Method> getMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter)
      Get all public methods of the declared class, including the inherited methods.
      Parameters:
      declaringClass - the declared class
      methodsToFilter - (optional) the methods to be filtered
      Returns:
      non-null read-only List
      Since:
      2.7.6
      See Also:
    • getAllDeclaredMethods

      static List<Method> getAllDeclaredMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter)
      Get all declared methods of the declared class, including the inherited methods.
      Parameters:
      declaringClass - the declared class
      methodsToFilter - (optional) the methods to be filtered
      Returns:
      non-null read-only List
      Since:
      2.7.6
      See Also:
    • getAllMethods

      static List<Method> getAllMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter)
      Get all public methods of the declared class, including the inherited methods.
      Parameters:
      declaringClass - the declared class
      methodsToFilter - (optional) the methods to be filtered
      Returns:
      non-null read-only List
      Since:
      2.7.6
      See Also:
    • findMethod

      static Method findMethod(Class type, String methodName)
      Find the Method by the the specified type and method name without the parameter types
      Parameters:
      type - the target type
      methodName - the specified method name
      Returns:
      if not found, return null
      Since:
      2.7.6
    • findMethod

      static Method findMethod(Class type, String methodName, Class<?>... parameterTypes)
      Find the Method by the the specified type, method name and parameter types
      Parameters:
      type - the target type
      methodName - the method name
      parameterTypes - the parameter types
      Returns:
      if not found, return null
      Since:
      2.7.6
    • invokeMethod

      static <T> T invokeMethod(Object object, String methodName, Object... methodParameters)
      Invoke the target object and method
      Type Parameters:
      T - the return type
      Parameters:
      object - the target object
      methodName - the method name
      methodParameters - the method parameters
      Returns:
      the target method's execution result
      Since:
      2.7.6
    • overrides

      static boolean overrides(Method overrider, Method overridden)
      Tests whether one method, as a member of a given type, overrides another method.
      Parameters:
      overrider - the first method, possible overrider
      overridden - the second method, possibly being overridden
      Returns:
      true if and only if the first method overrides the second
      See Also:
    • findNearestOverriddenMethod

      static Method findNearestOverriddenMethod(Method overrider)
      Find the nearest overridden method from the inherited class
      Parameters:
      overrider - the overrider method
      Returns:
      if found, the overrider method, or null
    • findOverriddenMethod

      static Method findOverriddenMethod(Method overrider, Class<?> declaringClass)
      Find the overridden method from the declaring class
      Parameters:
      overrider - the overrider method
      declaringClass - the class that is declaring the overridden method
      Returns:
      if found, the overrider method, or null
    • extractFieldName

      static String extractFieldName(Method method)
      Extract fieldName from set/get/is method. if it's not a set/get/is method, return empty string. If method equals get/is/getClass/getObject, also return empty string.
      Parameters:
      method - method
      Returns:
      fieldName
    • invokeAndReturnDouble

      static double invokeAndReturnDouble(Method method, Object targetObj)
      Invoke and return double value.
      Parameters:
      method - method
      targetObj - the object the method is invoked from
      Returns:
      double value
    • invokeAndReturnLong

      static long invokeAndReturnLong(Method method, Object targetObj)
      Invoke and return long value.
      Parameters:
      method - method
      targetObj - the object the method is invoked from
      Returns:
      long value
    • toShortString

      static String toShortString(Method method)
    • toShortString

      static String toShortString(MethodDescriptor md)