public final class ReflectionUtils extends Object
Constructor and Description |
---|
ReflectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <T extends Annotation> |
appendAnnotations(Class<T> a,
Class<?> c,
List<T> l)
Finds and appends the specified annotation on the specified class and superclasses/interfaces to the specified
list.
|
static <T extends Annotation> |
findAnnotations(Class<T> a,
Class<?> c)
Returns all instances of the specified annotation on the specified class.
|
static <T extends Annotation> |
findAnnotationsMap(Class<T> a,
Class<?> c)
Same as
findAnnotations(Class, Class) except returns the annotations as a map with the keys being the
class on which the annotation was found. |
static <T extends Annotation> |
findAnnotationsMapParentFirst(Class<T> a,
Class<?> c)
Same as
findAnnotationsMap(Class, Class) except returns results in parent-to-child order. |
static <T extends Annotation> |
findAnnotationsParentFirst(Class<T> a,
Class<?> c)
Same as
findAnnotations(Class, Class) but returns the list in parent-to-child order. |
static <T extends Annotation> |
getAnnotation(Class<T> a,
Class<?> c)
Similar to
Class.getAnnotation(Class) except also searches annotations on interfaces. |
static <T extends Annotation> |
getDeclaredAnnotation(Class<T> a,
Class<?> c)
Returns the specified annotation only if it's been declared on the specified class.
|
static InputStream |
getResource(Class<?> c,
String name)
Similar to
Class.getResourceAsStream(String) except looks up the parent hierarchy for the existence of
the specified resource. |
public ReflectionUtils()
public static <T extends Annotation> T getAnnotation(Class<T> a, Class<?> c)
Class.getAnnotation(Class)
except also searches annotations on interfaces.T
- The annotation class type.a
- The annotation class.c
- The annotated class.public static <T extends Annotation> T getDeclaredAnnotation(Class<T> a, Class<?> c)
More efficient than calling Class.getAnnotation(Class)
since it doesn't recursively look for the class
up the parent chain.
T
- The annotation class type.a
- The annotation class.c
- The annotated class.public static <T extends Annotation> List<T> findAnnotations(Class<T> a, Class<?> c)
Searches all superclasses and superinterfaces. Results are ordered child-to-parent.
T
- The annotation class type.a
- The annotation class type.c
- The class being searched.public static <T extends Annotation> List<T> findAnnotationsParentFirst(Class<T> a, Class<?> c)
findAnnotations(Class, Class)
but returns the list in parent-to-child order.a
- The annotation class type.c
- The class being searched.public static <T extends Annotation> LinkedHashMap<Class<?>,T> findAnnotationsMap(Class<T> a, Class<?> c)
findAnnotations(Class, Class)
except returns the annotations as a map with the keys being the
class on which the annotation was found.
Results are ordered child-to-parent.
T
- The annotation class type.a
- The annotation class type.c
- The class being searched.public static <T extends Annotation> LinkedHashMap<Class<?>,T> findAnnotationsMapParentFirst(Class<T> a, Class<?> c)
findAnnotationsMap(Class, Class)
except returns results in parent-to-child order.T
- The annotation class type.a
- The annotation class type.c
- The class being searched.public static <T extends Annotation> void appendAnnotations(Class<T> a, Class<?> c, List<T> l)
a
- The annotation.c
- The class.l
- The list of annotations.public static InputStream getResource(Class<?> c, String name)
Class.getResourceAsStream(String)
except looks up the parent hierarchy for the existence of
the specified resource.c
- The class to return the resource on.name
- The resource name.Copyright © 2018 Apache. All rights reserved.