public class ReflectionUtils
extends java.lang.Object
Constructor and Description |
---|
ReflectionUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
classImplementsInterface(java.lang.Class classToExamine,
java.lang.Class interfaceClass)
Checks if a class implements another class
|
static java.lang.Object[] |
coerceStringToArray(java.lang.String containingString)
Creates an array from a string
|
static java.lang.Object[] |
coerceStringToArray(java.lang.String containingString,
java.lang.Object toObject)
Creates an array from a string
|
static java.lang.Object |
coerceStringToJavaObject(java.lang.String containingString)
This attempts to coerce a string into a standard java object
|
static java.util.List<java.lang.reflect.Field> |
getDeclaredFieldsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.Class clazz)
Gets a list of declared fields with the given annotation
|
static java.util.List<java.lang.reflect.Method> |
getDeclaredMethodsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.Class clazz)
Gets a list of declared methods with the given annotation
|
static java.lang.reflect.Field |
getDeclaredOrNormalField(java.lang.String fieldName,
java.lang.Class clazz)
Attempts to find either a declared or normal field (in that order)
|
static java.lang.reflect.Method |
getDeclaredOrNormalMethod(java.lang.String methodName,
java.lang.Class clazz)
Attempts to find either a declared or normal method (in that order)
|
static java.util.List<java.lang.reflect.Field> |
getFieldsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.Class clazz)
Gets a list of fields with the given annotation
|
static java.util.List<java.lang.reflect.Method> |
getMethodsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.Class clazz)
Gets a list of methods with the given annotation
|
static java.lang.Class |
getPrimitiveSafeClassForName(java.lang.String name)
Gets classes for a given name, including primitives
|
static java.lang.String |
getSignatureFromObject(java.lang.Object o)
Gets the jvm signature for an object
|
static java.lang.Class |
getTypeFromSignature(java.lang.String signature)
Gets the class for a signature (only handles one signature at a time)
|
static boolean |
isNamePrimitive(java.lang.String name)
This method checks if the specified class name is of a primitive
|
static boolean |
isNamePrimitiveOrPrimitiveObject(java.lang.String name)
This method checks if the specified class name is of a primitive, includes primitive object names
|
static boolean |
isPrimitiveObject(java.lang.Object o)
Checks if the given object is a primitive wrapper object
|
static java.lang.Object |
objectFromString(java.lang.String objectString,
java.lang.Object object)
Tries to create an object from a string
|
static java.lang.String |
objectToString(java.lang.Object o)
Translates an object into a string readable by
objectFromString(java.lang.String, java.lang.Object) |
static java.lang.String |
objectToString(java.lang.Object o,
int tabs)
Translates an object into a string readable by
objectFromString(java.lang.String, java.lang.Object) |
static boolean |
paramsMatch(java.lang.reflect.Method method,
java.lang.Class<?>... params)
Checks if the given method has the required parameters
|
public static java.util.List<java.lang.reflect.Method> getDeclaredMethodsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Class clazz)
annotation
- The annotation to search forclazz
- The class to search inpublic static java.util.List<java.lang.reflect.Field> getDeclaredFieldsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Class clazz)
annotation
- The annotation to search forclazz
- The class to search inpublic static java.util.List<java.lang.reflect.Method> getMethodsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Class clazz)
annotation
- The annotation to search forclazz
- The class to search inpublic static java.util.List<java.lang.reflect.Field> getFieldsWithAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Class clazz)
annotation
- The annotation to search forclazz
- The class to search inpublic static boolean paramsMatch(java.lang.reflect.Method method, java.lang.Class<?>... params)
method
- The methodparams
- The parameters (ORDER MATTERS!)public static java.lang.reflect.Field getDeclaredOrNormalField(java.lang.String fieldName, java.lang.Class clazz)
fieldName
- The field to getclazz
- The class to searchpublic static java.lang.reflect.Method getDeclaredOrNormalMethod(java.lang.String methodName, java.lang.Class clazz)
methodName
- The method to getclazz
- The class to searchpublic static java.lang.String getSignatureFromObject(java.lang.Object o)
o
- The objectpublic static java.lang.Class getTypeFromSignature(java.lang.String signature) throws java.lang.ClassNotFoundException
signature
- The signaturejava.lang.ClassNotFoundException
public static java.lang.Class getPrimitiveSafeClassForName(java.lang.String name) throws java.lang.ClassNotFoundException
name
- The namejava.lang.ClassNotFoundException
public static boolean isNamePrimitive(java.lang.String name)
name
- The class namepublic static boolean isNamePrimitiveOrPrimitiveObject(java.lang.String name)
name
- The class namepublic static boolean isPrimitiveObject(java.lang.Object o)
o
- The objectpublic static java.lang.Object coerceStringToJavaObject(java.lang.String containingString)
containingString
- The string to coerceDouble
, Integer
, Character
,
Boolean
, null, or String
public static java.lang.Object[] coerceStringToArray(java.lang.String containingString)
containingString
- The stringpublic static java.lang.Object[] coerceStringToArray(java.lang.String containingString, java.lang.Object toObject) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.io.IOException
containingString
- The stringtoObject
- The type for the arrayjava.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
public static java.lang.Object objectFromString(java.lang.String objectString, java.lang.Object object) throws java.io.IOException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.lang.InstantiationException
objectString
- The string representing the objectobject
- The object to deserialize the string intojava.io.IOException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.lang.InstantiationException
public static java.lang.String objectToString(java.lang.Object o)
objectFromString(java.lang.String, java.lang.Object)
o
- The objectpublic static java.lang.String objectToString(java.lang.Object o, int tabs)
objectFromString(java.lang.String, java.lang.Object)
o
- The objecttabs
- The number of tab indentspublic static boolean classImplementsInterface(java.lang.Class classToExamine, java.lang.Class interfaceClass)
classToExamine
- The class to checkinterfaceClass
- The interface to look for