public class ReflectionUtils
extends java.lang.Object
| Constructor and Description |
|---|
ReflectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.List<java.lang.Class<?>> |
filterSameParameterizedTypes(java.util.List<java.lang.Class<?>> types,
java.lang.reflect.Type type)
Filters a list of types to keep only elements having the same parameterized types as the given type.
|
static <T extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.reflect.Field field,
java.lang.Class<T> annotationType)
Looks for given annotationType on given field or read method for field.
|
static <T> java.util.List<java.lang.reflect.Field> |
getDeclaredFields(T type)
Get declared fields of a given type.
|
static java.lang.Object |
getFieldValue(java.lang.Object object,
java.lang.reflect.Field field)
Get the value (accessible or not accessible) of a field of a target object.
|
static java.util.List<java.lang.reflect.Field> |
getInheritedFields(java.lang.Class<?> type)
Get inherited fields of a given type.
|
static <T> java.util.List<java.lang.Class<?>> |
getPublicConcreteSubTypesOf(java.lang.Class<T> type)
Searches the classpath for all public concrete subtypes of the given interface or abstract class.
|
static java.util.Optional<java.lang.reflect.Method> |
getReadMethod(java.lang.reflect.Field field)
Get the read method for given field.
|
java.lang.Class<?> |
getWrapperType(java.lang.Class<?> primitiveType)
Get wrapper type of a primitive type.
|
static <T> boolean |
isAbstract(java.lang.Class<T> type)
Check if the type is abstract (either an interface or an abstract class).
|
static boolean |
isAnnotationPresent(java.lang.reflect.Field field,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Checks if field or corresponding read method is annotated with given annotationType.
|
static boolean |
isArrayType(java.lang.Class<?> type)
Check if a type is an array type.
|
static boolean |
isCollectionType(java.lang.Class<?> type)
Check if a type is a collection type.
|
static boolean |
isCollectionType(java.lang.reflect.Type type)
Check if a type is a collection type.
|
static boolean |
isEnumType(java.lang.Class<?> type)
Check if a type is an enum type.
|
static boolean |
isInterface(java.lang.Class<?> type)
Check if a type is an interface.
|
static boolean |
isIntrospectable(java.lang.Class<?> type)
Check if a type should be introspected for internal fields.
|
static boolean |
isJdkBuiltIn(java.lang.Class<?> type)
Check if a type is a JDK built-in collection/map.
|
static boolean |
isMapType(java.lang.Class<?> type)
Check if a type is a map type.
|
static boolean |
isParameterizedType(java.lang.reflect.Type type)
Check if a type is a parameterized type
|
static boolean |
isPopulatable(java.lang.reflect.Type type)
Check if a type is populatable.
|
static boolean |
isPrimitiveFieldWithDefaultValue(java.lang.Object object,
java.lang.reflect.Field field)
Check if a field has a primitive type and matching default value which is set by the compiler.
|
static <T> boolean |
isPublic(java.lang.Class<T> type)
Check if the type is public.
|
static boolean |
isStatic(java.lang.reflect.Field field)
Check if a field is static.
|
static boolean |
isTypeVariable(java.lang.reflect.Type type)
Check if a type is a type variable
|
static boolean |
isWildcardType(java.lang.reflect.Type type)
Check if a type is a wildcard type
|
static <T> Randomizer<T> |
newInstance(java.lang.Class<T> type,
RandomizerArgument[] randomizerArguments) |
static void |
setProperty(java.lang.Object object,
java.lang.reflect.Field field,
java.lang.Object value)
Set a value (accessible or not accessible) in a field of a target object.
|
public static <T> java.util.List<java.lang.reflect.Field> getDeclaredFields(T type)
T - the actual type to introspecttype - the type to introspectpublic static java.util.List<java.lang.reflect.Field> getInheritedFields(java.lang.Class<?> type)
type - the type to introspectpublic static void setProperty(java.lang.Object object,
java.lang.reflect.Field field,
java.lang.Object value)
throws java.lang.IllegalAccessException
object - instance to set the property onfield - field to set the property onvalue - value to setjava.lang.IllegalAccessException - if the property cannot be setpublic static java.lang.Object getFieldValue(java.lang.Object object,
java.lang.reflect.Field field)
throws java.lang.IllegalAccessException
object - instance to get the field offield - field to get the value ofjava.lang.IllegalAccessException - if field can not be accessedpublic java.lang.Class<?> getWrapperType(java.lang.Class<?> primitiveType)
primitiveType - to get its wrapper typepublic static boolean isPrimitiveFieldWithDefaultValue(java.lang.Object object,
java.lang.reflect.Field field)
throws java.lang.IllegalAccessException
object - instance to get the field value offield - field to checkjava.lang.IllegalAccessException - if field cannot be accessedpublic static boolean isStatic(java.lang.reflect.Field field)
field - the field to checkpublic static boolean isInterface(java.lang.Class<?> type)
type - the type to checkpublic static <T> boolean isAbstract(java.lang.Class<T> type)
T - the actual type to checktype - the type to checkpublic static <T> boolean isPublic(java.lang.Class<T> type)
T - the actual type to checktype - the type to checkpublic static boolean isArrayType(java.lang.Class<?> type)
type - the type to check.public static boolean isEnumType(java.lang.Class<?> type)
type - the type to check.public static boolean isCollectionType(java.lang.Class<?> type)
type - the type to check.public static boolean isCollectionType(java.lang.reflect.Type type)
type - the type to check.public static boolean isPopulatable(java.lang.reflect.Type type)
type - the type to checkpublic static boolean isIntrospectable(java.lang.Class<?> type)
type - the type to checkpublic static boolean isMapType(java.lang.Class<?> type)
type - the type to checkpublic static boolean isJdkBuiltIn(java.lang.Class<?> type)
type - the type to checkpublic static boolean isParameterizedType(java.lang.reflect.Type type)
type - the type to checkpublic static boolean isWildcardType(java.lang.reflect.Type type)
type - the type to checkpublic static boolean isTypeVariable(java.lang.reflect.Type type)
type - the type to checkpublic static <T> java.util.List<java.lang.Class<?>> getPublicConcreteSubTypesOf(java.lang.Class<T> type)
T - the actual type to introspecttype - to search concrete subtypes ofpublic static java.util.List<java.lang.Class<?>> filterSameParameterizedTypes(java.util.List<java.lang.Class<?>> types,
java.lang.reflect.Type type)
type - the type to use for the searchtypes - a list of types to filterpublic static <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.reflect.Field field,
java.lang.Class<T> annotationType)
T - the actual type of annotationfield - field to checkannotationType - Type of annotation you're looking for.public static boolean isAnnotationPresent(java.lang.reflect.Field field,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
field - Field to checkannotationType - Annotation you're looking for.public static java.util.Optional<java.lang.reflect.Method> getReadMethod(java.lang.reflect.Field field)
field - field to get the read method for.public static <T> Randomizer<T> newInstance(java.lang.Class<T> type, RandomizerArgument[] randomizerArguments)
Copyright © 2019. All Rights Reserved.