java.lang.Object
ushiosan.jvm_utilities.lang.reflection.MethodUtils

public final class MethodUtils extends Object
Class containing utilities for handling methods obtained by reflection. In addition to filters for handling within the same functionality of the class to have a more powerful reflection.
  • Method Details

    • findMethod

      public static Method findMethod(@NotNull @NotNull Class<?> cls, @NotNull @NotNull String name, @NotNull @NotNull ReflectionOpts<Method> opts, Class<?>... argsTypes) throws NoSuchMethodException
      It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters. Java handles methods independently for each class, and you cannot access a field that is inside another class, but inherits from it. That is why a trick is performed to perform such a task.
      Parameters:
      cls - the class you want to inspect
      name - the method you want to search for
      opts - reflection options
      argsTypes - the data types contained in the method parameters
      Returns:
      the method that contains all the constraints mentioned
      Throws:
      NoSuchMethodException - error if such method does not exist in the entire inheritance tree of the class
      See Also:
    • findMethod

      public static Method findMethod(@NotNull @NotNull Class<?> cls, @NotNull @NotNull String name, Class<?>... argsTypes) throws NoSuchMethodException
      It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters. Java handles methods independently for each class, and you cannot access a field that is inside another class, but inherits from it. That is why a trick is performed to perform such a task.
      Parameters:
      cls - the class you want to inspect
      name - the method you want to search for
      argsTypes - the data types contained in the method parameters
      Returns:
      the method that contains all the constraints mentioned
      Throws:
      NoSuchMethodException - error if such method does not exist in the entire inheritance tree of the class
      See Also:
    • findMethodObj

      public static Method findMethodObj(@NotNull @NotNull Object obj, @NotNull @NotNull String name, @NotNull @NotNull ReflectionOpts<Method> opts, Class<?>... argsTypes) throws NoSuchMethodException
      It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters. Java handles methods independently for each class, and you cannot access a field that is inside another class, but inherits from it. That is why a trick is performed to perform such a task.
      Parameters:
      obj - the object you want to inspect
      name - the method you want to search for
      opts - reflection options
      argsTypes - the data types contained in the method parameters
      Returns:
      the method that contains all the constraints mentioned
      Throws:
      NoSuchMethodException - error if such method does not exist in the entire inheritance tree of the class
      See Also:
    • findMethodObj

      public static Method findMethodObj(@NotNull @NotNull Object obj, @NotNull @NotNull String name, Class<?>... argsTypes) throws NoSuchMethodException
      It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters. Java handles methods independently for each class, and you cannot access a field that is inside another class, but inherits from it. That is why a trick is performed to perform such a task.
      Parameters:
      obj - the object you want to inspect
      name - the method you want to search for
      argsTypes - the data types contained in the method parameters
      Returns:
      the method that contains all the constraints mentioned
      Throws:
      NoSuchMethodException - error if such method does not exist in the entire inheritance tree of the class
      See Also:
    • getAllClassMethods

      public static Method @NotNull [] getAllClassMethods(@NotNull @NotNull Class<?> cls, @NotNull @NotNull ReflectionOpts<Method> opts)
      Returns all defined and undefined methods of a class (for this, this method accesses the inheritance tree to get all these fields)
      Parameters:
      cls - the class you want to inspect
      opts - reflection options
      Returns:
      all valid class methods
      See Also:
    • getAllClassMethods

      public static Method @NotNull [] getAllClassMethods(@NotNull @NotNull Class<?> cls)
      Returns all defined and undefined methods of a class (for this, this method accesses the inheritance tree to get all these fields)
      Parameters:
      cls - the class you want to inspect
      Returns:
      all valid class methods
      See Also:
    • regexOf

      @NotNull public static <T extends Member> @NotNull Predicate<T> regexOf(@NotNull @RegExp @NotNull String regex, boolean inverted)
      Generates a filter to capture the elements that meet said restriction
      Type Parameters:
      T - generic member type
      Parameters:
      regex - regular expression to apply
      inverted - option to perform the action inverted
      Returns:
      the filter instance with the desired behavior
    • regexOf

      @NotNull public static <T extends Member> @NotNull Predicate<T> regexOf(@NotNull @RegExp @NotNull String regex)
      Generates a filter to capture the elements that meet said restriction
      Type Parameters:
      T - generic member type
      Parameters:
      regex - regular expression to apply
      Returns:
      the filter instance with the desired behavior
    • regexOf

      @Contract(pure=true) @NotNull public static <T extends Member> @NotNull Predicate<T> regexOf(@NotNull @NotNull Pattern pattern, boolean inverted)
      Generates a filter to capture the elements that meet said restriction
      Type Parameters:
      T - generic member type
      Parameters:
      pattern - regular expression object to apply
      inverted - option to perform the action inverted
      Returns:
      the filter instance with the desired behavior
    • regexOf

      @NotNull public static <T extends Member> @NotNull Predicate<T> regexOf(@NotNull @NotNull Pattern pattern)
      Generates a filter to capture the elements that meet said restriction
      Type Parameters:
      T - generic member type
      Parameters:
      pattern - regular expression object to apply
      Returns:
      the filter instance with the desired behavior
    • regexMultipleOf

      @NotNull public static <T extends Member> @NotNull Predicate<T> regexMultipleOf(boolean inverted, @RegExp String @NotNull ... regex)
      Generates a filter to capture the items that meet that constraint. The only difference with the regexOf(String) method is that it contains multiple constraints.
      Type Parameters:
      T - generic member type
      Parameters:
      inverted - option to perform the action inverted
      regex - regular expression to apply
      Returns:
      the filter instance with the desired behavior
    • regexMultipleOf

      @NotNull public static <T extends Member> @NotNull Predicate<T> regexMultipleOf(@RegExp String @NotNull ... regex)
      Generates a filter to capture the items that meet that constraint. The only difference with the regexOf(String) method is that it contains multiple constraints.
      Type Parameters:
      T - generic member type
      Parameters:
      regex - regular expression to apply
      Returns:
      the filter instance with the desired behavior
    • regexMultipleOf

      @NotNull public static <T extends Member> @NotNull Predicate<T> regexMultipleOf(boolean inverted, Pattern @NotNull ... patterns)
      Generates a filter to capture the items that meet that constraint. The only difference with the regexOf(String) method is that it contains multiple constraints.
      Type Parameters:
      T - generic member type
      Parameters:
      inverted - option to perform the action inverted
      patterns - regular expression object to apply
      Returns:
      the filter instance with the desired behavior
    • regexMultipleOf

      @NotNull public static <T extends Member> @NotNull Predicate<T> regexMultipleOf(Pattern @NotNull ... patterns)
      Generates a filter to capture the items that meet that constraint. The only difference with the regexOf(String) method is that it contains multiple constraints.
      Type Parameters:
      T - generic member type
      Parameters:
      patterns - regular expression object to apply
      Returns:
      the filter instance with the desired behavior
    • excludeAll

      @NotNull public static <T extends Member> @NotNull Predicate<T> excludeAll(String @NotNull ... methods)
      Generates a filter to capture elements that are different from the names passed as parameters.
      Type Parameters:
      T - generic member type
      Parameters:
      methods - all the names you want to exclude
      Returns:
      the filter instance with the desired behavior
    • validField

      @NotNull public static @NotNull Predicate<Field> validField()
      Generates a filter to check if a field is valid within a class
      Returns:
      the filter instance with the desired behavior
    • validGetterMethod

      @NotNull public static @NotNull Predicate<Method> validGetterMethod()
      Generates a filter to check if a method is valid inside a class (also checks if it is a getter)
      Returns:
      the filter instance with the desired behavior
    • requireAnnotations

      @SafeVarargs @NotNull public static <T extends AccessibleObject> @NotNull Predicate<T> requireAnnotations(boolean inverted, Class<? extends Annotation> @NotNull ... annotations)
      Generates a filter to check if the object contains one or more annotations.
      Type Parameters:
      T - generic accessible type
      Parameters:
      inverted - option to perform the action inverted
      annotations - the annotations that are required
      Returns:
      the filter instance with the desired behavior
    • requireAnnotations

      @SafeVarargs @NotNull public static <T extends AccessibleObject> @NotNull Predicate<T> requireAnnotations(Class<? extends Annotation> @NotNull ... annotations)
      Generates a filter to check if the object contains one or more annotations.
      Type Parameters:
      T - generic accessible type
      Parameters:
      annotations - the annotations that are required
      Returns:
      the filter instance with the desired behavior