korat.utils
Class ReflectionUtils
java.lang.Object
korat.utils.ReflectionUtils
public class ReflectionUtils
- extends Object
- Author:
- Aleksandar Milicevic
Method Summary |
static Field[] |
getAllFields(Class clz)
|
private static void |
getAllFieldsRecursive(Class clz,
List<Field> fldLst)
|
static Field[] |
getAllNonStaticFields(Class clz)
|
static Field[] |
getDeclaredNonStaticFields(Class clz)
|
static Field |
getField(Class cls,
String fieldName)
Gets field from class cls, either declared in cls or in one
of its superclasses |
static Object |
getFieldValue(Object obj,
Field field)
|
static Field |
getFieldWithAccess(Class cls,
String fieldName)
|
static Field |
getFieldWithAccess(Object obj,
String fieldName)
|
static Method |
getMethod(Class<? extends Object> clz,
String methodName,
Class[] methodArgs)
Gets method from class clz or any of its superclasses. |
static Object |
invoke(Object obj,
String method,
Class[] params,
Object[] args)
Invokes method of a given obj and set of parameters |
static void |
setFieldValue(Object obj,
Field field,
Object value)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
cache
static Map<Class,Map<String,Field>> cache
ReflectionUtils
public ReflectionUtils()
getFieldWithAccess
public static Field getFieldWithAccess(Object obj,
String fieldName)
getFieldWithAccess
public static Field getFieldWithAccess(Class cls,
String fieldName)
getField
public static Field getField(Class cls,
String fieldName)
- Gets field from class cls, either declared in cls or in one
of its superclasses
- Parameters:
cls
- - declaring class of the fieldfieldName
- - name of the field
- Returns:
- requested field
getFieldValue
public static Object getFieldValue(Object obj,
Field field)
setFieldValue
public static void setFieldValue(Object obj,
Field field,
Object value)
getAllFieldsRecursive
private static void getAllFieldsRecursive(Class clz,
List<Field> fldLst)
getAllFields
public static Field[] getAllFields(Class clz)
getAllNonStaticFields
public static Field[] getAllNonStaticFields(Class clz)
getDeclaredNonStaticFields
public static Field[] getDeclaredNonStaticFields(Class clz)
getMethod
public static Method getMethod(Class<? extends Object> clz,
String methodName,
Class[] methodArgs)
throws NoSuchMethodException
- Gets method from class
clz
or any of its superclasses. If no method can be found
NoSuchMethodException
is raised.
- Parameters:
clz
- - declaring class of the methodmethodName
- - name of the methodmethodArgs
- - method arguments
- Returns:
- requested method
- Throws:
NoSuchMethodException
invoke
public static Object invoke(Object obj,
String method,
Class[] params,
Object[] args)
Invokes method of a given obj and set of parameters
- Parameters:
obj
- - Object for which the method is going to be executed. Special
if obj is of type java.lang.Class, method is executed as static method
of class given as obj parametermethod
- - name of the objectparams
- - actual parameters for the method
- Returns:
- - result of the method execution
If there is any problem with method invocation, a RuntimeException is thrown