Package panda.utilities
Class ReflectionUtils
java.lang.Object
panda.utilities.ReflectionUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Executable>
Collection<E>getByModifier(E[] executables, int modifier) Get executables with the specified modifierstatic <R,T> Collection<R> getFieldValues(Class<T> clazz, Class<R> type, T instance) Collect values of static fields with the specified typestatic panda.std.Option<Method>Get method wrapped into optional instead of exception if method does not exist.getMethods(Class<?> clazz, String methodName) Collect all methods with the same namegetMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation) Collect methods annotated with the specified annotationstatic <T> Collection<T>getStaticFieldValues(Class<?> clazz, Class<T> type) Collect values of static fields with the specified type
-
Method Details
-
getByModifier
Get executables with the specified modifier- Type Parameters:
E- type of executable- Parameters:
executables- array of executables to search inmodifier- the modifier to search for- Returns:
- collection of matched executables
-
getMethod
public static panda.std.Option<Method> getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) Get method wrapped into optional instead of exception if method does not exist. Comparing toClass.getMethod(String, Class[])it also checks non-public methods.- Parameters:
clazz- the class to search inmethodName- name of methodparameterTypes- parameter types of method- Returns:
- the result method wrapped into optional
-
getMethods
Collect all methods with the same name- Parameters:
clazz- class to searchmethodName- name to search for- Returns:
- the list of the matching methods
-
getMethodsAnnotatedWith
public static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation) Collect methods annotated with the specified annotation- Parameters:
clazz- class to searchannotation- annotation to search for- Returns:
- the set of annotated methods
-
getStaticFieldValues
Collect values of static fields with the specified type- Type Parameters:
T- value type- Parameters:
clazz- class to search intype- type of field- Returns:
- collection of collected values
-
getFieldValues
public static <R,T> Collection<R> getFieldValues(Class<T> clazz, Class<R> type, @Nullable T instance) Collect values of static fields with the specified type- Type Parameters:
R- type of valuesT- type of instance- Parameters:
clazz- class to search intype- type of fieldsinstance- instance- Returns:
- collection of collected values
-