public class ReflectionUtils extends Object
Constructor and Description |
---|
ReflectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <T extends Annotation> |
findAnnotation(Annotation[] parameterAnnotations,
Class<T> targetAnnotation)
Utility method to find if an annotation type is present in an array of annotations.
|
static Method |
findMethod(Class<?> clazz,
String name,
Class<?>... parameterTypes)
Safely search for a method with a given signature (name + parameter types) on a given class.
|
static <T extends Annotation> |
findMethodParameterAnnotation(Method ownerMethod,
int paramIndex,
Class<T> targetAnnotation)
Return the specified annotation for the method parameter at a given position (see
paramIndex ). |
static <T> T |
getAnnotationField(Annotation annotation,
String fieldName,
T defaultValue)
Get the value of an annotation field.
|
static Annotation |
getAnnotationParam(int i,
Method method)
Return the annotation (annotated with an
AnnotatedParam )
used with a given method parameter. |
static List<Class<?>> |
getElementsClasses(Collection<?> collection)
Extract the list of types of every element of a given collection.
|
static <T> T |
invokeMethod(Object target,
String name,
Class<?>... parameterTypes)
Safely invoke a method with the given signature (name + parameter types) on the given target object.
|
static boolean |
isParameterAnnotatedWith(int i,
Method method,
Class<? extends Annotation> targetAnnotation)
Check if a parameter is annotated with a given annotation.
|
public static boolean isParameterAnnotatedWith(int i, Method method, Class<? extends Annotation> targetAnnotation)
i
- method parameter index.method
- the method the parameter belongs to.targetAnnotation
- the annotation type we want to check for.public static Annotation getAnnotationParam(int i, Method method)
AnnotatedParam
)
used with a given method parameter.i
- method parameter index.method
- the method the parameter belongs to.AnnotatedParam
public static <T extends Annotation> T findAnnotation(Annotation[] parameterAnnotations, Class<T> targetAnnotation)
parameterAnnotations
- the array of annotations we will look in.targetAnnotation
- the type of annotation we are looking for.public static <T extends Annotation> T findMethodParameterAnnotation(Method ownerMethod, int paramIndex, Class<T> targetAnnotation)
paramIndex
).ownerMethod
- the parameter's methodparamIndex
- the parameter indextargetAnnotation
- the annotation type to search forpublic static Method findMethod(Class<?> clazz, String name, Class<?>... parameterTypes)
clazz
- the target classname
- method nameparameterTypes
- method's parameters types.public static <T> T invokeMethod(Object target, String name, Class<?>... parameterTypes)
target
- the target objectname
- method nameparameterTypes
- method's parameters types.public static <T> T getAnnotationField(Annotation annotation, String fieldName, T defaultValue)
annotation
- the target annotationfieldName
- the field namedefaultValue
- the default value to returnpublic static List<Class<?>> getElementsClasses(Collection<?> collection)
collection
- the collection in input.Copyright © 2015. All rights reserved.