Class MethodUtils
java.lang.Object
ushiosan.jvm_utilities.lang.reflection.MethodUtils
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 Summary
Modifier and TypeMethodDescriptionexcludeAll(String @NotNull ... methods) Generates a filter to capture elements that are different from the names passed as parameters.static MethodfindMethod(@NotNull Class<?> cls, @NotNull String name, @NotNull ReflectionOpts<Method> opts, Class<?>... argsTypes) It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters.static MethodIt searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters.static MethodfindMethodObj(@NotNull Object obj, @NotNull String name, @NotNull ReflectionOpts<Method> opts, Class<?>... argsTypes) It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters.static MethodIt searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the method parameters.getAllClassMethods(@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)getAllClassMethods(@NotNull Class<?> cls, @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)regexMultipleOf(boolean inverted, String @NotNull ... regex) Generates a filter to capture the items that meet that constraint.regexMultipleOf(boolean inverted, Pattern @NotNull ... patterns) Generates a filter to capture the items that meet that constraint.regexMultipleOf(String @NotNull ... regex) Generates a filter to capture the items that meet that constraint.regexMultipleOf(Pattern @NotNull ... patterns) Generates a filter to capture the items that meet that constraint.Generates a filter to capture the elements that meet said restrictionGenerates a filter to capture the elements that meet said restrictionGenerates a filter to capture the elements that meet said restrictionGenerates a filter to capture the elements that meet said restrictionstatic <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.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.Generates a filter to check if a field is valid within a classGenerates a filter to check if a method is valid inside a class (also checks if it is a getter)
-
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 inspectname- the method you want to search foropts- reflection optionsargsTypes- 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 inspectname- the method you want to search forargsTypes- 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 inspectname- the method you want to search foropts- reflection optionsargsTypes- 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 inspectname- the method you want to search forargsTypes- 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 inspectopts- reflection options- Returns:
- all valid class methods
- See Also:
-
getAllClassMethods
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 applyinverted- 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 applyinverted- 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 theregexOf(String)method is that it contains multiple constraints.- Type Parameters:
T- generic member type- Parameters:
inverted- option to perform the action invertedregex- 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 theregexOf(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 theregexOf(String)method is that it contains multiple constraints.- Type Parameters:
T- generic member type- Parameters:
inverted- option to perform the action invertedpatterns- 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 theregexOf(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
Generates a filter to check if a field is valid within a class- Returns:
- the filter instance with the desired behavior
-
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 invertedannotations- 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
-