Package org.reflections
Class ReflectionUtils
- java.lang.Object
-
- org.reflections.util.ReflectionUtilsPredicates
-
- org.reflections.ReflectionUtils
-
public abstract class ReflectionUtils extends ReflectionUtilsPredicates
utils for querying java reflection meta typesSuperTypes
,Annotations
,AnnotationTypes
,Methods
,Constructors
,Fields
.Set<Class<?>> supertypes = get(SuperTypes.of(type)) Set<Annotation> annotations = get(Annotations.of(type))
generally, apply
get(QueryFunction)
onQueryFunction
created byUtilQueryBuilder
, and optionally use the functional methods in QueryFunctionget(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
Fields Modifier and Type Field Description static UtilQueryBuilder<AnnotatedElement,Annotation>
Annotations
query annotationsstatic UtilQueryBuilder<AnnotatedElement,Class<? extends Annotation>>
AnnotationTypes
query annotation typesstatic UtilQueryBuilder<Class<?>,Constructor>
Constructors
query constructorsstatic UtilQueryBuilder<Class<?>,Field>
Fields
query fieldsstatic UtilQueryBuilder<Class<?>,Class<?>>
Interfaces
query interfacesstatic UtilQueryBuilder<Class<?>,Method>
Methods
query methodsstatic Predicate<Method>
notObjectMethod
predicate to filter outObject
methodsstatic UtilQueryBuilder<Class<?>,Class<?>>
SuperClass
query super classstatic UtilQueryBuilder<Class<?>,Class<?>>
SuperTypes
query super classes and interfaces including element
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends AnnotatedElement>
UtilQueryBuilder<AnnotatedElement,T>extendType()
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
static Set<Field>
getAllFields(Class<?> type, Predicate<? super Field>... predicates)
get all fields of giventype
, up the super class hierarchy, optionally filtered bypredicates
static Set<Method>
getAllMethods(Class<?> type, Predicate<? super Method>... predicates)
get all methods of giventype
, up the super class hierarchy, optionally filtered bypredicates
static Set<Class<?>>
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
static Set<Field>
getFields(Class<?> type, Predicate<? super Field>... predicates)
get fields of giventype
, optionally filtered bypredicates
static Set<Method>
getMethods(Class<?> t, Predicate<? super Method>... predicates)
get methods of giventype
, optionally filtered bypredicates
static Set<Class<?>>
getSuperTypes(Class<?> type)
get the immediate supertype and interfaces of the giventype
static Object
invoke(Method method, Object obj, Object... args)
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
static Map<String,Object>
toMap(Annotation annotation)
mapannotation
to hash map of member values recursivelystatic Map<String,Object>
toMap(Annotation annotation, AnnotatedElement element)
mapannotation
andannotatedElement
to hash map of member values-
Methods inherited from class org.reflections.util.ReflectionUtilsPredicates
isAssignable, withAnnotation, withAnnotation, withAnnotations, withAnnotations, withAnyParameterAnnotation, withAnyParameterAnnotation, withClassModifier, withInterface, withModifier, withName, withParameters, withParametersAssignableFrom, withParametersAssignableTo, withParametersCount, withPattern, withPrefix, withPublic, withReturnType, withReturnTypeAssignableFrom, withStatic, withType, withTypeAssignableTo
-
-
-
-
Field Detail
-
notObjectMethod
public static final Predicate<Method> notObjectMethod
predicate to filter outObject
methods
-
SuperClass
public static final UtilQueryBuilder<Class<?>,Class<?>> SuperClass
query super classget(SuperClass.of(element)) -> Set<Class<?>>
see also
SuperTypes
,Interfaces
-
Interfaces
public static final UtilQueryBuilder<Class<?>,Class<?>> Interfaces
query interfacesget(Interfaces.of(element)) -> Set<Class<?>>
-
SuperTypes
public static final UtilQueryBuilder<Class<?>,Class<?>> SuperTypes
query super classes and interfaces including elementget(SuperTypes.of(element)) -> Set<Class<?>>
-
Annotations
public static final UtilQueryBuilder<AnnotatedElement,Annotation> Annotations
query annotationsget(Annotation.of(element)) -> Set<Annotation>
-
AnnotationTypes
public static final UtilQueryBuilder<AnnotatedElement,Class<? extends Annotation>> AnnotationTypes
query annotation typesget(AnnotationTypes.of(element)) -> Set<Class<? extends Annotation>>
-
Methods
public static final UtilQueryBuilder<Class<?>,Method> Methods
query methodsget(Methods.of(type)) -> Set<Method>
-
Constructors
public static final UtilQueryBuilder<Class<?>,Constructor> Constructors
query constructorsget(Constructors.of(type)) -> Set<Constructor>
-
Fields
public static final UtilQueryBuilder<Class<?>,Field> Fields
query fieldsget(Fields.of(type)) -> Set<Field>
-
-
Method Detail
-
get
public static <C,T> Set<T> get(QueryFunction<C,T> function)
-
get
public static <T> Set<T> get(QueryFunction<Store,T> queryFunction, Predicate<? super T>... predicates)
-
extendType
public static <T extends AnnotatedElement> UtilQueryBuilder<AnnotatedElement,T> 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
public static Set<Class<?>> getSuperTypes(Class<?> type)
get the immediate supertype and interfaces of the giventype
marked for removal, use instead
get(SuperTypes.get())
-
getAllMethods
public static Set<Method> getAllMethods(Class<?> type, Predicate<? super Method>... predicates)
get all methods of giventype
, up the super class hierarchy, optionally filtered bypredicates
marked for removal, use instead
get(Methods.of())
-
getMethods
public static Set<Method> getMethods(Class<?> t, Predicate<? super Method>... predicates)
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
public static Set<Field> getAllFields(Class<?> type, Predicate<? super Field>... predicates)
get all fields of giventype
, up the super class hierarchy, optionally filtered bypredicates
marked for removal, use instead
get(Fields.of())
-
getFields
public static Set<Field> getFields(Class<?> type, Predicate<? super Field>... predicates)
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
public static Map<String,Object> toMap(Annotation annotation)
mapannotation
to hash map of member values recursivelyAnnotations.of(type).map(ReflectionUtils::toMap)
-
toMap
public static Map<String,Object> toMap(Annotation annotation, AnnotatedElement element)
mapannotation
andannotatedElement
to hash map of member valuesAnnotations.of(type).map(a -> toMap(type, a))
-
toAnnotation
public static Annotation toAnnotation(Map<String,Object> map)
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)
-
-