Class ReflectionUtils
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 outObject
methodsstatic 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 applyingQueryFunction
static <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 bypredicates
static Set
<Constructor> getAllConstructors
(Class<?> type, Predicate<? super Constructor>... predicates) get all constructors of giventype
, up the super class hierarchy, optionally filtered bypredicates
getAllFields
(Class<?> type, Predicate<? super Field>... predicates) get all fields of giventype
, up the super class hierarchy, optionally filtered bypredicates
getAllMethods
(Class<?> type, Predicate<? super Method>... predicates) get all methods of giventype
, up the super class hierarchy, optionally filtered bypredicates
getAllSuperTypes
(Class<?> type, Predicate<? super Class<?>>... predicates) get all super types of giventype
, including, optionally filtered bypredicates
static <T extends AnnotatedElement>
Set<Annotation> getAnnotations
(T type, Predicate<Annotation>... predicates) get annotations of giventype
, optionally honorInherited, optionally filtered bypredicates
static Set
<Constructor> getConstructors
(Class<?> t, Predicate<? super Constructor>... predicates) get constructors of giventype
, optionally filtered bypredicates
get fields of giventype
, optionally filtered bypredicates
getMethods
(Class<?> t, Predicate<? super Method>... predicates) get methods of giventype
, optionally filtered bypredicates
getSuperTypes
(Class<?> type) get the immediate supertype and interfaces of the giventype
static Object
invoke the givenmethod
withargs
, return either the result or an exception if occurredstatic Annotation
toAnnotation
(Map<String, Object> map) create new annotation proxy with member values from the givenmap
static <T extends Annotation>
TtoAnnotation
(Map<String, Object> map, Class<T> annotationType) create new annotation proxy with member values from the givenmap
and member values from the givenmap
toMap
(Annotation annotation) mapannotation
to hash map of member values recursivelytoMap
(Annotation annotation, AnnotatedElement element) mapannotation
andannotatedElement
to hash map of member valuesMethods inherited from class org.reflections.util.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
predicate to filter outObject
methods -
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 bypredicates
marked for removal, use instead
get(Annotations.of())
-
getAllSuperTypes
public static Set<Class<?>> getAllSuperTypes(Class<?> type, Predicate<? super Class<?>>... predicates) get all super types of giventype
, including, optionally filtered bypredicates
-
getSuperTypes
get the immediate supertype and interfaces of the giventype
marked for removal, use instead
get(SuperTypes.get())
-
getAllMethods
get all methods of giventype
, up the super class hierarchy, optionally filtered bypredicates
marked for removal, use instead
get(Methods.of())
-
getMethods
get methods of giventype
, optionally filtered bypredicates
marked for removal, use instead
get(Methods.get())
-
getAllConstructors
public static Set<Constructor> getAllConstructors(Class<?> type, Predicate<? super Constructor>... predicates) get all constructors of giventype
, up the super class hierarchy, optionally filtered bypredicates
marked 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 bypredicates
marked for removal, use instead
get(Constructors.get())
-
getAllFields
get all fields of giventype
, up the super class hierarchy, optionally filtered bypredicates
marked for removal, use instead
get(Fields.of())
-
getFields
get fields of giventype
, optionally filtered bypredicates
marked for removal, use instead
get(Fields.get())
-
getAnnotations
public static <T extends AnnotatedElement> Set<Annotation> getAnnotations(T type, Predicate<Annotation>... predicates) get annotations of giventype
, optionally honorInherited, optionally filtered bypredicates
marked for removal, use instead
get(Annotations.get())
-
toMap
mapannotation
to hash map of member values recursivelyAnnotations.of(type).map(ReflectionUtils::toMap)
-
toMap
mapannotation
andannotatedElement
to hash map of member valuesAnnotations.of(type).map(a -> toMap(type, a))
-
toAnnotation
create new annotation proxy with member values from the givenmap
toAnnotation(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 givenmap
and member values from the givenmap
toAnnotation(Map.of("value", ""), annotationType)
-
invoke
invoke the givenmethod
withargs
, return either the result or an exception if occurred
-