public abstract class ReflectionUtils extends ReflectionUtilsPredicates
see SuperTypes, Annotations, AnnotationTypes, Methods, Constructors and Fields.
Set<Class<?>> supertypes = get(SuperTypes.of(type))
Set<Annotation> annotations = get(Annotations.of(type))
generally, apply get(QueryFunction) on QueryFunction created by UtilQueryBuilder, and optionally use the functional methods in QueryFunction.
get(Methods.of(type)
.filter(withPublic().and(withPrefix("get")).and(withParameterCount(0)))
.as(Method.class)
.map(m -> ...))
or (previously), use getAllXXX(type/s, withYYY) methods:
getAllSuperTypes(), getAllFields(), getAllMethods(), getAllConstructors()
some predicates included here:
ReflectionUtilsPredicates.withPublic()
ReflectionUtilsPredicates.withParametersCount(int)}
ReflectionUtilsPredicates.withAnnotation(java.lang.annotation.Annotation)
ReflectionUtilsPredicates.withParameters(Class[])
ReflectionUtilsPredicates.withModifier(int)
ReflectionUtilsPredicates.withReturnType(Class)
import static org.reflections.ReflectionUtils.*;
Set<Method> getters =
get(Methods(classes)
.filter(withModifier(Modifier.PUBLIC).and(withPrefix("get")).and(withParametersCount(0)));
get(Annotations.of(method)
.filter(withAnnotation())
.map(annotation -> Methods.of(annotation)
.map(method -> )))))
.stream()...
| Modifier and Type | Field and Description |
|---|---|
static UtilQueryBuilder<AnnotatedElement,Annotation> |
Annotations
query annotations
|
static UtilQueryBuilder<AnnotatedElement,Class<? extends Annotation>> |
AnnotationTypes
query annotation types
|
static UtilQueryBuilder<Class<?>,Constructor> |
Constructors
query constructors
|
static UtilQueryBuilder<Class<?>,Field> |
Fields
query fields
|
static UtilQueryBuilder<Class<?>,Class<?>> |
Interfaces
query interfaces
|
static UtilQueryBuilder<Class<?>,Method> |
Methods
query methods
|
static Predicate<Method> |
notObjectMethod
predicate to filter out
Object methods |
static UtilQueryBuilder<String,URL> |
Resources
query url resources using
ClassLoader.getResources(java.lang.String) |
static UtilQueryBuilder<Class<?>,Class<?>> |
SuperClass
query super class
|
static UtilQueryBuilder<Class<?>,Class<?>> |
SuperTypes
query super classes and interfaces including element
|
| Constructor and Description |
|---|
ReflectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends AnnotatedElement> |
extendType() |
static <C,T> Set<T> |
get(QueryFunction<C,T> function)
get type elements
<T> by applying QueryFunction |
static <T> Set<T> |
get(QueryFunction<Store,T> queryFunction,
Predicate<? super T>... predicates)
|
static <T extends AnnotatedElement> |
getAllAnnotations(T type,
Predicate<Annotation>... predicates)
get all annotations of given
type, up the super class hierarchy, optionally filtered by predicates |
static Set<Constructor> |
getAllConstructors(Class<?> type,
Predicate<? super Constructor>... predicates)
get all constructors of given
type, up the super class hierarchy, optionally filtered by predicates |
static Set<Field> |
getAllFields(Class<?> type,
Predicate<? super Field>... predicates)
get all fields of given
type, up the super class hierarchy, optionally filtered by predicates |
static Set<Method> |
getAllMethods(Class<?> type,
Predicate<? super Method>... predicates)
get all methods of given
type, up the super class hierarchy, optionally filtered by predicates |
static Set<Class<?>> |
getAllSuperTypes(Class<?> type,
Predicate<? super Class<?>>... predicates)
get all super types of given
type, including, optionally filtered by predicates |
static <T extends AnnotatedElement> |
getAnnotations(T type,
Predicate<Annotation>... predicates)
get annotations of given
type, optionally honorInherited, optionally filtered by predicates |
static Set<Constructor> |
getConstructors(Class<?> t,
Predicate<? super Constructor>... predicates)
get constructors of given
type, optionally filtered by predicates |
static Set<Field> |
getFields(Class<?> type,
Predicate<? super Field>... predicates)
get fields of given
type, optionally filtered by predicates |
static Set<Method> |
getMethods(Class<?> t,
Predicate<? super Method>... predicates)
get methods of given
type, optionally filtered by predicates |
static Set<Class<?>> |
getSuperTypes(Class<?> type)
get the immediate supertype and interfaces of the given
type |
static Object |
invoke(Method method,
Object obj,
Object... args)
invoke the given
method with args, return either the result or an exception if occurred |
static Annotation |
toAnnotation(Map<String,Object> map)
create new annotation proxy with member values from the given
map |
static <T extends Annotation> |
toAnnotation(Map<String,Object> map,
Class<T> annotationType)
create new annotation proxy with member values from the given
map and member values from the given map |
static Map<String,Object> |
toMap(Annotation annotation)
map
annotation to hash map of member values recursively |
static Map<String,Object> |
toMap(Annotation annotation,
AnnotatedElement element)
map
annotation and annotatedElement to hash map of member values |
isAssignable, withAnnotation, withAnnotation, withAnnotations, withAnnotations, withAnyParameterAnnotation, withAnyParameterAnnotation, withClassModifier, withInterface, withModifier, withName, withNamePrefix, withParameters, withParametersAssignableFrom, withParametersAssignableTo, withParametersCount, withPattern, withPrefix, withPublic, withReturnType, withReturnTypeAssignableFrom, withStatic, withType, withTypeAssignableTopublic static final Predicate<Method> notObjectMethod
Object methodspublic static final UtilQueryBuilder<Class<?>,Class<?>> SuperClass
get(SuperClass.of(element)) -> Set<Class<?>>
see also SuperTypes, Interfaces
public static final UtilQueryBuilder<Class<?>,Class<?>> Interfaces
get(Interfaces.of(element)) -> Set<Class<?>>public static final UtilQueryBuilder<Class<?>,Class<?>> SuperTypes
get(SuperTypes.of(element)) -> Set<Class<?>> public static final UtilQueryBuilder<AnnotatedElement,Annotation> Annotations
get(Annotation.of(element)) -> Set<Annotation> public static final UtilQueryBuilder<AnnotatedElement,Class<? extends Annotation>> AnnotationTypes
get(AnnotationTypes.of(element)) -> Set<Class<? extends Annotation>> public static final UtilQueryBuilder<Class<?>,Method> Methods
get(Methods.of(type)) -> Set<Method>public static final UtilQueryBuilder<Class<?>,Constructor> Constructors
get(Constructors.of(type)) -> Set<Constructor> public static final UtilQueryBuilder<Class<?>,Field> Fields
get(Fields.of(type)) -> Set<Field> public static final UtilQueryBuilder<String,URL> Resources
ClassLoader.getResources(java.lang.String) get(Resources.with(name)) -> Set<URL> public static <C,T> Set<T> get(QueryFunction<C,T> function)
public static <T> Set<T> get(QueryFunction<Store,T> queryFunction, Predicate<? super T>... predicates)
public static <T extends AnnotatedElement> UtilQueryBuilder<AnnotatedElement,T> extendType()
public static <T extends AnnotatedElement> Set<Annotation> getAllAnnotations(T type, Predicate<Annotation>... predicates)
type, up the super class hierarchy, optionally filtered by predicates
marked for removal, use instead get(Annotations.of())
public static Set<Class<?>> getAllSuperTypes(Class<?> type, Predicate<? super Class<?>>... predicates)
type, including, optionally filtered by predicatespublic static Set<Class<?>> getSuperTypes(Class<?> type)
type
marked for removal, use instead get(SuperTypes.get())
public static Set<Method> getAllMethods(Class<?> type, Predicate<? super Method>... predicates)
type, up the super class hierarchy, optionally filtered by predicates
marked for removal, use instead get(Methods.of())
public static Set<Method> getMethods(Class<?> t, Predicate<? super Method>... predicates)
type, optionally filtered by predicates
marked for removal, use instead get(Methods.get())
public static Set<Constructor> getAllConstructors(Class<?> type, Predicate<? super Constructor>... predicates)
type, up the super class hierarchy, optionally filtered by predicates
marked for removal, use instead get(Constructors.of())
public static Set<Constructor> getConstructors(Class<?> t, Predicate<? super Constructor>... predicates)
type, optionally filtered by predicates
marked for removal, use instead get(Constructors.get())
public static Set<Field> getAllFields(Class<?> type, Predicate<? super Field>... predicates)
type, up the super class hierarchy, optionally filtered by predicates
marked for removal, use instead get(Fields.of())
public static Set<Field> getFields(Class<?> type, Predicate<? super Field>... predicates)
type, optionally filtered by predicates
marked for removal, use instead get(Fields.get())
public static <T extends AnnotatedElement> Set<Annotation> getAnnotations(T type, Predicate<Annotation>... predicates)
type, optionally honorInherited, optionally filtered by predicates
marked for removal, use instead get(Annotations.get())
public static Map<String,Object> toMap(Annotation annotation)
annotation to hash map of member values recursively Annotations.of(type).map(ReflectionUtils::toMap) public static Map<String,Object> toMap(Annotation annotation, AnnotatedElement element)
annotation and annotatedElement to hash map of member values
Annotations.of(type).map(a -> toMap(type, a)) public static Annotation toAnnotation(Map<String,Object> map)
map toAnnotation(Map.of("annotationType", annotationType, "value", ""))public static <T extends Annotation> T toAnnotation(Map<String,Object> map, Class<T> annotationType)
map and member values from the given map
toAnnotation(Map.of("value", ""), annotationType)Copyright © 2021. All rights reserved.