Package org.hibernate.testing.util
Class ReflectionUtil
- java.lang.Object
-
- org.hibernate.testing.util.ReflectionUtil
-
public class ReflectionUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Field
getField(Class clazz, String name)
Get a field from a given classstatic <T> T
getFieldValue(Object target, String name)
Get a field value from a given objectstatic Method
getMethod(Object target, String methodName, Class... parameterTypes)
Get target methodstatic Method
getSetter(Object target, String property, Class<?> parameterType)
Get setter methodstatic <T> T
getStaticFieldValue(Class<?> target, String name)
Get a field value from a given classstatic <T> T
newInstance(String className)
New target Object instance using the given Class namestatic <T> T
newInstance(Supplier<Constructor<T>> constructorSupplier, Object... args)
New target Object instance using the given argumentsstatic void
setField(Object target, Field field, Object value)
Set target Object field to a certain valuestatic void
setField(Object target, String fieldName, Object value)
Set target Object field to a certain valuestatic void
setProperty(Object target, String property, Object parameter)
Invoke setter method with the given parameterstatic void
setStaticField(Class<?> target, String fieldName, Object value)
Set target Class field to a certain value
-
-
-
Method Detail
-
getField
public static Field getField(Class clazz, String name)
Get a field from a given class- Parameters:
clazz
- clazzname
- field name- Returns:
- field object
-
getFieldValue
public static <T> T getFieldValue(Object target, String name)
Get a field value from a given object- Parameters:
target
- Object whose field is being readname
- field name- Returns:
- field object
-
getStaticFieldValue
public static <T> T getStaticFieldValue(Class<?> target, String name)
Get a field value from a given class- Parameters:
target
- Class whose field is being readname
- field name- Returns:
- field value
-
setField
public static void setField(Object target, Field field, Object value)
Set target Object field to a certain value- Parameters:
target
- Object whose field is being setfield
- Object field to setvalue
- the new value for the given field
-
setField
public static void setField(Object target, String fieldName, Object value)
Set target Object field to a certain value- Parameters:
target
- Object whose field is being setfieldName
- Object field naem to setvalue
- the new value for the given field
-
setStaticField
public static void setStaticField(Class<?> target, String fieldName, Object value)
Set target Class field to a certain value- Parameters:
target
- Class whose field is being setfieldName
- Class field name to setvalue
- the new value for the given field
-
newInstance
public static <T> T newInstance(Supplier<Constructor<T>> constructorSupplier, Object... args)
New target Object instance using the given arguments- Parameters:
constructorSupplier
- constructor supplierargs
- Constructor arguments- Returns:
- new Object instance
-
newInstance
public static <T> T newInstance(String className)
New target Object instance using the given Class name- Parameters:
className
- class name- Returns:
- new Object instance
-
getSetter
public static Method getSetter(Object target, String property, Class<?> parameterType)
Get setter method- Parameters:
target
- target objectproperty
- propertyparameterType
- setter parameter type- Returns:
- setter method
-
getMethod
public static Method getMethod(Object target, String methodName, Class... parameterTypes)
Get target method- Parameters:
target
- target objectmethodName
- method nameparameterTypes
- method parameter types- Returns:
- return value
-
-