public final class ReflectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Object |
convertToArray(Class type,
List<?> values)
Converts a List to an array
|
static <T> T |
getAnnotation(Class c,
Class<T> annotation)
Returns an annotation on a Class if present
|
static <T> List<T> |
getAnnotations(Class c,
Class<T> annotation)
Returns the (first) instance of the annotation, on the class (or any superclass, or interfaces implemented).
|
static Class<?> |
getClass(Type type)
Get the underlying class for a type, or null if the type is a variable type.
|
static Embedded |
getClassEmbeddedAnnotation(Class c)
Returns the @Embedded annotation on a Class if present
|
static Entity |
getClassEntityAnnotation(Class c)
Returns the @Entity annotation on a Class if present
|
static Set<Class<?>> |
getClasses(ClassLoader loader,
String packageName)
Returns the classes in a package
|
static Set<Class<?>> |
getClasses(ClassLoader loader,
String packageName,
boolean mapSubPackages)
Returns the classes in a package
|
static Set<Class<?>> |
getClasses(String packageName)
Returns the classes in a package
|
static Set<Class<?>> |
getClasses(String packageName,
boolean mapSubPackages)
Returns the classes in a package
|
static Field[] |
getDeclaredAndInheritedFields(Class type,
boolean returnFinalFields)
Get an array of all fields declared in the supplied class, and all its superclasses (except java.lang.Object).
|
static List<Method> |
getDeclaredAndInheritedMethods(Class type)
Get a list of all methods declared in the supplied class, and all its superclasses (except java.lang.Object), recursively.
|
static Set<Class<?>> |
getFromDirectory(ClassLoader loader,
File directory,
String packageName)
Returns the classes in a package found in a directory
|
static Set<Class<?>> |
getFromDirectory(ClassLoader loader,
File directory,
String packageName,
boolean mapSubPackages)
Returns the classes in a package found in a directory
|
static Set<Class<?>> |
getFromJARFile(ClassLoader loader,
String jar,
String packageName)
Returns the classes in a package found in a jar
|
static Set<Class<?>> |
getFromJARFile(ClassLoader loader,
String jar,
String packageName,
boolean mapSubPackages)
Returns the classes in a package found in a jar
|
static Class |
getParameterizedClass(Class c)
Returns the parameterized type of a Class
|
static Class |
getParameterizedClass(Class c,
int index)
Returns the parameterized type in the given position
|
static Class |
getParameterizedClass(Field field)
Get the (first) class that parameterizes the Field supplied.
|
static Class |
getParameterizedClass(Field field,
int index)
Get the class that parameterizes the Field supplied, at the index supplied (field can be parameterized with multiple param classes).
|
static Type |
getParameterizedType(Field field,
int index)
Returns the parameterized type for a field
|
static <T> Class<?> |
getTypeArgument(Class<? extends T> clazz,
TypeVariable<? extends GenericDeclaration> tv)
Returns the type argument
|
static <T> List<Class<?>> |
getTypeArguments(Class<T> baseClass,
Class<? extends T> childClass)
Deprecated.
this class is unused in morphia and will be removed in a future release
|
static List<Field> |
getValidFields(Field[] fields,
boolean returnFinalFields)
Scans the array fields and returns any fields that are not static or (optionally) final.
|
static boolean |
implementsInterface(Class<?> type,
Class<?> interfaceClass)
Check if a class implements a specific interface.
|
static boolean |
isFieldParameterizedWithClass(Field field,
Class c)
Deprecated.
this class is unused in morphia and will be removed in a future release
|
static boolean |
isFieldParameterizedWithPropertyType(Field field)
Deprecated.
this class is unused in morphia and will be removed in a future release
|
static boolean |
isIntegerType(Class type)
Checks if the class is an integer type, i.e., is numeric but not a floating point type.
|
static boolean |
isPrimitiveLike(Class type)
Checks if the Class given is a primitive type.
|
static boolean |
isPropertyType(Class type)
Checks if the Class given is a property type
|
static boolean |
isPropertyType(Type type)
Check if the class supplied represents a valid property type.
|
static <T> List<T> |
iterToList(Iterable<T> it)
Converts an Iterable to a List
|
public static Field[] getDeclaredAndInheritedFields(Class type, boolean returnFinalFields)
type - the class for which we want to retrieve the FieldsreturnFinalFields - specifies whether to return final fieldspublic static List<Field> getValidFields(Field[] fields, boolean returnFinalFields)
fields - the fields to processreturnFinalFields - include final fields in the resultspublic static List<Method> getDeclaredAndInheritedMethods(Class type)
type - the class for which we want to retrieve the Methodspublic static boolean isIntegerType(Class type)
type - the class we want to checkpublic static boolean isPropertyType(Type type)
type - the class we want to checkpublic static Class getParameterizedClass(Field field)
field - the fieldpublic static Class getParameterizedClass(Field field, int index)
field - the fieldindex - the index of the parameterizing classpublic static Type getParameterizedType(Field field, int index)
field - the field to examineindex - the location of the parameter to returnpublic static Class getParameterizedClass(Class c)
c - the class to examinepublic static Class getParameterizedClass(Class c, int index)
c - the class to examineindex - the position of the type to returnpublic static boolean isFieldParameterizedWithClass(Field field, Class c)
field - the fieldc - the class to check againstpublic static boolean implementsInterface(Class<?> type, Class<?> interfaceClass)
type - the class we want to checkinterfaceClass - the interface class we want to check againstpublic static boolean isFieldParameterizedWithPropertyType(Field field)
field - the fieldpublic static boolean isPropertyType(Class type)
type - the Class to examinepublic static boolean isPrimitiveLike(Class type)
type - the Class to examinepublic static Embedded getClassEmbeddedAnnotation(Class c)
c - the class to examinepublic static <T> T getAnnotation(Class c, Class<T> annotation)
T - the type of the annotationc - the class to examineannotation - the annotation to findpublic static <T> List<T> getAnnotations(Class c, Class<T> annotation)
T - the type of the annotationc - the class to examineannotation - the annotation to findpublic static Entity getClassEntityAnnotation(Class c)
c - the class to examinepublic static Set<Class<?>> getClasses(String packageName) throws IOException, ClassNotFoundException
packageName - the package to scanIOException - thrown if an error is encountered scanning packagesClassNotFoundException - thrown if a class can not be foundpublic static Set<Class<?>> getClasses(String packageName, boolean mapSubPackages) throws IOException, ClassNotFoundException
packageName - the package to scanmapSubPackages - whether to map the sub-packages while scanningIOException - thrown if an error is encountered scanning packagesClassNotFoundException - thrown if a class can not be foundpublic static Set<Class<?>> getClasses(ClassLoader loader, String packageName) throws IOException, ClassNotFoundException
loader - the ClassLoader to usepackageName - the package to scanIOException - thrown if an error is encountered scanning packagesClassNotFoundException - thrown if a class can not be foundpublic static Set<Class<?>> getClasses(ClassLoader loader, String packageName, boolean mapSubPackages) throws IOException, ClassNotFoundException
loader - the ClassLoader to usepackageName - the package to scanmapSubPackages - whether to map the sub-packages while scanningIOException - thrown if an error is encountered scanning packagesClassNotFoundException - thrown if a class can not be foundpublic static Set<Class<?>> getFromJARFile(ClassLoader loader, String jar, String packageName) throws IOException, ClassNotFoundException
loader - the ClassLoader to usejar - the jar to scanpackageName - the package to scanIOException - thrown if an error is encountered scanning packagesClassNotFoundException - thrown if a class can not be foundpublic static Set<Class<?>> getFromJARFile(ClassLoader loader, String jar, String packageName, boolean mapSubPackages) throws IOException, ClassNotFoundException
loader - the ClassLoader to usejar - the jar to scanpackageName - the package to scanmapSubPackages - whether to map the sub-packages while scanningIOException - thrown if an error is encountered scanning packagesClassNotFoundException - thrown if a class can not be foundpublic static Set<Class<?>> getFromDirectory(ClassLoader loader, File directory, String packageName) throws ClassNotFoundException
loader - the ClassLoader to usedirectory - the directory to scanpackageName - the package to scanClassNotFoundException - thrown if a class can not be foundpublic static Set<Class<?>> getFromDirectory(ClassLoader loader, File directory, String packageName, boolean mapSubPackages) throws ClassNotFoundException
loader - the ClassLoader to usedirectory - the directory to scanpackageName - the package to scanmapSubPackages - whether to map the sub-packages while scanningClassNotFoundException - thrown if a class can not be foundpublic static <T> List<T> iterToList(Iterable<T> it)
T - the types of the elements in the Iterableit - the Iterablepublic static Object convertToArray(Class type, List<?> values)
type - the Class type of the elements of the Listvalues - the List to convertpublic static Class<?> getClass(Type type)
type - the typepublic static <T> List<Class<?>> getTypeArguments(Class<T> baseClass, Class<? extends T> childClass)
T - the type of the base classbaseClass - the base classchildClass - the child classpublic static <T> Class<?> getTypeArgument(Class<? extends T> clazz, TypeVariable<? extends GenericDeclaration> tv)
T - the type of the Classclazz - the Class to examinetv - the TypeVariable to look for