Package io.github.zero88.repl
Class ReflectionMethod
- java.lang.Object
-
- io.github.zero88.repl.ReflectionMethod
-
- All Implemented Interfaces:
ReflectionMember
public final class ReflectionMethod extends java.lang.Object implements ReflectionMember
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Objectexecute(@NotNull java.lang.Object instance, @NotNull java.lang.reflect.Method method)Execute method with no arguments.static java.lang.Objectexecute(@NotNull java.lang.Object instance, @NotNull java.lang.reflect.Method method, @NotNull Arguments args)Execute method with arguments.static <O> Oexecute(@NotNull java.lang.Object instance, @NotNull java.lang.reflect.Method method, @NotNull java.lang.Class<O> outputType, @NotNull Arguments arguments)static <I,O>
Oexecute(@NotNull java.lang.Object instance, @NotNull java.lang.reflect.Method method, @NotNull java.lang.Class<O> outputType, @NotNull java.lang.Class<I> argClass, I argValue)Execute method from object instance by only one param.static <O> Oexecute(@NotNull java.lang.Object instance, @NotNull java.lang.reflect.Method method, java.lang.Object... args)static <T> TexecuteStatic(@NotNull java.lang.Class<?> declareCls, @NotNull java.lang.Class<T> outputCls, @NotNull java.lang.String methodName, java.lang.Object... args)Execute static methodstatic java.util.List<java.lang.reflect.Method>find(@NotNull java.lang.Class<?> clazz, java.util.function.Predicate<java.lang.reflect.Method> predicate)Find declared methods in givenclassthat matches with filterstatic java.util.stream.Stream<java.lang.reflect.Method>find(java.util.function.Predicate<java.lang.reflect.Method> predicate, @NotNull java.lang.Class<?> clazz)static booleanvalidateMethod(@NotNull java.lang.reflect.Method method, @NotNull java.lang.Class<?> outputType, @NotNull Arguments arguments)Check givenMethodis matched with givenoutputclass andinputsclassstatic booleanvalidateMethod(@NotNull java.lang.reflect.Method method, @NotNull java.lang.Class<?> outputType, @NotNull java.util.Collection<java.lang.Class<?>> argClasses)Check givenMethodis matched with givenoutputclass andinputsclassstatic booleanvalidateMethod(java.lang.reflect.Method method, java.lang.Class<?> outputType, java.lang.Class<?>... argClasses)Check givenMethodis matched with givenoutputclass andinputsclass
-
-
-
Method Detail
-
executeStatic
public static <T> T executeStatic(@NotNull @NotNull java.lang.Class<?> declareCls, @NotNull @NotNull java.lang.Class<T> outputCls, @NotNull @NotNull java.lang.String methodName, java.lang.Object... args)Execute static method- Type Parameters:
T- Type of output- Parameters:
declareCls- a declare classoutputCls- an output classmethodName- a method nameargs- a object arguments- Returns:
- method result
-
execute
public static java.lang.Object execute(@NotNull @NotNull java.lang.Object instance, @NotNull @NotNull java.lang.reflect.Method method)Execute method with no arguments.- Parameters:
instance- an object instancemethod- a method to execute- Returns:
- the method result
-
execute
public static java.lang.Object execute(@NotNull @NotNull java.lang.Object instance, @NotNull @NotNull java.lang.reflect.Method method, @NotNull @NotNull Arguments args)Execute method with arguments.- Parameters:
instance- an object instancemethod- a method to execute- Returns:
- the method result
-
execute
public static <O> O execute(@NotNull @NotNull java.lang.Object instance, @NotNull @NotNull java.lang.reflect.Method method, java.lang.Object... args)
-
execute
public static <I,O> O execute(@NotNull @NotNull java.lang.Object instance, @NotNull @NotNull java.lang.reflect.Method method, @NotNull @NotNull java.lang.Class<O> outputType, @NotNull @NotNull java.lang.Class<I> argClass, I argValue)Execute method from object instance by only one param.- Type Parameters:
I- Type of Input parameterO- Type of Return result- Parameters:
instance- Object instancemethod- Method to executeoutputType- Output type ofmethodargClass- Param type ofmethodargValue- Argument to pass intomethod- Returns:
- the method result
- Throws:
ReflectionException- if any error when invoke method
-
execute
public static <O> O execute(@NotNull @NotNull java.lang.Object instance, @NotNull @NotNull java.lang.reflect.Method method, @NotNull @NotNull java.lang.Class<O> outputType, @NotNull @NotNull Arguments arguments)
-
find
public static java.util.List<java.lang.reflect.Method> find(@NotNull @NotNull java.lang.Class<?> clazz, java.util.function.Predicate<java.lang.reflect.Method> predicate)Find declared methods in givenclassthat matches with filter- Parameters:
clazz- Givenclassto find methodspredicate- Given predicate- Returns:
- List of matching
methods
-
find
public static java.util.stream.Stream<java.lang.reflect.Method> find(java.util.function.Predicate<java.lang.reflect.Method> predicate, @NotNull @NotNull java.lang.Class<?> clazz)
-
validateMethod
public static boolean validateMethod(java.lang.reflect.Method method, java.lang.Class<?> outputType, java.lang.Class<?>... argClasses)Check givenMethodis matched with givenoutputclass andinputsclass- Parameters:
method- Given methodoutputType- Given output typeargClasses- Given argument classes- Returns:
trueif matched, otherwisefalse
-
validateMethod
public static boolean validateMethod(@NotNull @NotNull java.lang.reflect.Method method, @NotNull @NotNull java.lang.Class<?> outputType, @NotNull @NotNull java.util.Collection<java.lang.Class<?>> argClasses)Check givenMethodis matched with givenoutputclass andinputsclass- Parameters:
method- Given methodoutputType- Given output typeargClasses- Given argument classes- Returns:
trueif matched, otherwisefalse
-
validateMethod
public static boolean validateMethod(@NotNull @NotNull java.lang.reflect.Method method, @NotNull @NotNull java.lang.Class<?> outputType, @NotNull @NotNull Arguments arguments)Check givenMethodis matched with givenoutputclass andinputsclass- Parameters:
method- Given methodoutputType- Given output typearguments- Given arguments- Returns:
trueif matched, otherwisefalse
-
-