Class ReflectionUtils
java.lang.Object
org.reflections.util.ReflectionUtilsPredicates
org.reflections.ReflectionUtils
utils for querying java reflection meta types
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()...
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UtilQueryBuilder<AnnotatedElement, Annotation> query annotationsstatic final UtilQueryBuilder<AnnotatedElement, Class<? extends Annotation>> query annotation typesstatic final UtilQueryBuilder<Class<?>, Constructor> query constructorsstatic final UtilQueryBuilder<Class<?>, Field> query fieldsstatic final UtilQueryBuilder<Class<?>, Class<?>> query interfacesstatic final UtilQueryBuilder<Class<?>, Method> query methodspredicate to filter outObjectmethodsstatic final UtilQueryBuilder<String, URL> query url resources usingClassLoader.getResources(java.lang.String)static final UtilQueryBuilder<Class<?>, Class<?>> query super classstatic final UtilQueryBuilder<Class<?>, Class<?>> query super classes and interfaces including element -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends AnnotatedElement>
UtilQueryBuilder<AnnotatedElement, T> static <C,T> Set <T> get(QueryFunction<C, T> function) get type elements<T>by applyingQueryFunctionstatic <T> Set<T> get(QueryFunction<Store, T> queryFunction, Predicate<? super T>... predicates) static <T extends AnnotatedElement>
Set<Annotation> getAllAnnotations(T type, Predicate<Annotation>... predicates) get all annotations of giventype, up the super class hierarchy, optionally filtered bypredicatesstatic Set<Constructor> getAllConstructors(Class<?> type, Predicate<? super Constructor>... predicates) get all constructors of giventype, up the super class hierarchy, optionally filtered bypredicatesgetAllFields(Class<?> type, Predicate<? super Field>... predicates) get all fields of giventype, up the super class hierarchy, optionally filtered bypredicatesgetAllMethods(Class<?> type, Predicate<? super Method>... predicates) get all methods of giventype, up the super class hierarchy, optionally filtered bypredicatesgetAllSuperTypes(Class<?> type, Predicate<? super Class<?>>... predicates) get all super types of giventype, including, optionally filtered bypredicatesstatic <T extends AnnotatedElement>
Set<Annotation> getAnnotations(T type, Predicate<Annotation>... predicates) get annotations of giventype, optionally honorInherited, optionally filtered bypredicatesstatic Set<Constructor> getConstructors(Class<?> t, Predicate<? super Constructor>... predicates) get constructors of giventype, optionally filtered bypredicatesget fields of giventype, optionally filtered bypredicatesgetMethods(Class<?> t, Predicate<? super Method>... predicates) get methods of giventype, optionally filtered bypredicatesgetSuperTypes(Class<?> type) get the immediate supertype and interfaces of the giventypestatic Objectinvoke the givenmethodwithargs, return either the result or an exception if occurredstatic AnnotationtoAnnotation(Map<String, Object> map) create new annotation proxy with member values from the givenmapstatic <T extends Annotation>
TtoAnnotation(Map<String, Object> map, Class<T> annotationType) create new annotation proxy with member values from the givenmapand member values from the givenmaptoMap(Annotation annotation) mapannotationto hash map of member values recursivelytoMap(Annotation annotation, AnnotatedElement element) mapannotationandannotatedElementto hash map of member valuesMethods inherited from class ReflectionUtilsPredicates
isAssignable, withAnnotation, withAnnotation, withAnnotations, withAnnotations, withAnyParameterAnnotation, withAnyParameterAnnotation, withClassModifier, withInterface, withModifier, withName, withNamePrefix, withParameters, withParametersAssignableFrom, withParametersAssignableTo, withParametersCount, withPattern, withPrefix, withPublic, withReturnType, withReturnTypeAssignableFrom, withStatic, withType, withTypeAssignableTo
-
Field Details
-
objectMethodNames
-
notObjectMethod
-
SuperClass
query super classget(SuperClass.of(element)) -> Set<Class<?>>see also
SuperTypes,Interfaces -
Interfaces
query interfacesget(Interfaces.of(element)) -> Set<Class<?>> -
SuperTypes
query super classes and interfaces including elementget(SuperTypes.of(element)) -> Set<Class<?>> -
Annotations
query annotationsget(Annotation.of(element)) -> Set<Annotation> -
AnnotationTypes
query annotation typesget(AnnotationTypes.of(element)) -> Set<Class<? extends Annotation>> -
Methods
query methodsget(Methods.of(type)) -> Set<Method> -
Constructors
query constructorsget(Constructors.of(type)) -> Set<Constructor> -
Fields
query fieldsget(Fields.of(type)) -> Set<Field> -
Resources
query url resources usingClassLoader.getResources(java.lang.String)get(Resources.with(name)) -> Set<URL>
-
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils()
-
-
Method Details
-
get
-
get
public static <T> Set<T> get(QueryFunction<Store, T> queryFunction, Predicate<? super T>... predicates) -
extendType
-
getAllAnnotations
public static <T extends AnnotatedElement> Set<Annotation> getAllAnnotations(T type, Predicate<Annotation>... predicates) get all annotations of giventype, up the super class hierarchy, optionally filtered bypredicatesmarked for removal, use instead
get(Annotations.of()) -
getAllSuperTypes
-
getSuperTypes
-
getAllMethods
-
getMethods
-
getAllConstructors
public static Set<Constructor> getAllConstructors(Class<?> type, Predicate<? super Constructor>... predicates) get all constructors of giventype, up the super class hierarchy, optionally filtered bypredicatesmarked for removal, use instead
get(Constructors.of()) -
getConstructors
public static Set<Constructor> getConstructors(Class<?> t, Predicate<? super Constructor>... predicates) get constructors of giventype, optionally filtered bypredicatesmarked for removal, use instead
get(Constructors.get()) -
getAllFields
-
getFields
-
getAnnotations
public static <T extends AnnotatedElement> Set<Annotation> getAnnotations(T type, Predicate<Annotation>... predicates) get annotations of giventype, optionally honorInherited, optionally filtered bypredicatesmarked for removal, use instead
get(Annotations.get()) -
toMap
mapannotationto hash map of member values recursivelyAnnotations.of(type).map(ReflectionUtils::toMap) -
toMap
mapannotationandannotatedElementto hash map of member valuesAnnotations.of(type).map(a -> toMap(type, a)) -
toAnnotation
create new annotation proxy with member values from the givenmaptoAnnotation(Map.of("annotationType", annotationType, "value", "")) -
toAnnotation
public static <T extends Annotation> T toAnnotation(Map<String, Object> map, Class<T> annotationType) create new annotation proxy with member values from the givenmapand member values from the givenmaptoAnnotation(Map.of("value", ""), annotationType) -
invoke
-