|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vladmihalcea.hibernate.util.ReflectionUtils
public final class ReflectionUtils
ReflectionUtils - Reflection utilities holder.
| Method Summary | ||
|---|---|---|
static
|
getClass(String className)
Get the Java Class with the given fully-qualified name. |
|
static
|
getClassOrNull(String className)
Get the Java Class with the given fully-qualified name or or null
if no Class was found matching the provided name. |
|
static Method |
getDeclaredMethodOrNull(Class targetClass,
String methodName,
Class... parameterTypes)
Get the Method with the given signature (name and parameter types) belonging to
the provided Java Class, excluding inherited ones, or null if no Method was found. |
|
static Field |
getField(Class targetClass,
String fieldName)
Get the Field with the given name belonging to the provided Java Class. |
|
static Field |
getFieldOrNull(Class targetClass,
String fieldName)
Get the Field with the given name belonging to the provided Java Class or null
if no Field was found. |
|
static
|
getFieldValue(Object target,
String fieldName)
Get the value of the field matching the given name and belonging to target Object. |
|
static
|
getFieldValueOrNull(Object target,
String fieldName)
Get the value of the field matching the given name and belonging to target Object or null
if no Field was found.. |
|
static
|
getFirstSuperClassFromPackage(Class clazz,
String packageName)
Get the first super class matching the provided package name. |
|
static Set<Class> |
getGenericTypes(ParameterizedType parameterizedType)
Get the generic types of a given Class. |
|
static Method |
getGetter(Object target,
String propertyName)
Get the property getter Method with the given name belonging to
the provided Java Object. |
|
static Type |
getMemberGenericTypeOrNull(Class targetClass,
String memberName)
Get the generic Type of the Member with the given name belonging to the provided Java Class or null
if no Member was found. |
|
static Member |
getMemberOrNull(Class targetClass,
String memberName)
Get the Member with the given name belonging to the provided Java Class or null
if no Member was found. |
|
static Method |
getMethod(Class targetClass,
String methodName,
Class... parameterTypes)
Get the Method with the given signature (name and parameter types) belonging to
the provided Java Class. |
|
static Method |
getMethod(Object target,
String methodName,
Class... parameterTypes)
Get the Method with the given signature (name and parameter types) belonging to
the provided Java Object. |
|
static Method |
getMethodOrNull(Class targetClass,
String methodName,
Class... parameterTypes)
Get the Method with the given signature (name and parameter types) belonging to
the provided Java Object or null if no Method was found. |
|
static Method |
getMethodOrNull(Object target,
String methodName,
Class... parameterTypes)
Get the Method with the given signature (name and parameter types) belonging to
the provided Java Object or null if no Method was found. |
|
static Method |
getSetter(Object target,
String propertyName,
Class<?> parameterType)
Get the property setter Method with the given signature (name and parameter types)
belonging to the provided Java Object. |
|
static Class<?> |
getWrapperClass(Class<?> clazz)
Get the Java Wrapper Class associated to the given primitive type. |
|
static boolean |
hasMethod(Class<?> targetClass,
String methodName,
Class... parameterTypes)
Check if the provided Java Class contains a method matching
the given signature (name and parameter types). |
|
static
|
invokeGetter(Object target,
String propertyName)
Invoke the property getter with the provided name on the given Java Object. |
|
static
|
invokeMethod(Object target,
Method method,
Object... parameters)
Invoke the provided Method on the given Java Object. |
|
static
|
invokeMethod(Object target,
String methodName,
Object... parameters)
Invoke the method with the provided signature (name and parameter types) on the given Java Object. |
|
static void |
invokeSetter(Object target,
String propertyName,
boolean parameter)
Invoke the boolean property setter with the provided name
on the given Java Object. |
|
static void |
invokeSetter(Object target,
String propertyName,
int parameter)
Invoke the int property setter with the provided name
on the given Java Object. |
|
static void |
invokeSetter(Object target,
String propertyName,
Object parameter)
Invoke the property setter with the provided signature (name and parameter types) on the given Java Object. |
|
static
|
invokeStaticMethod(Method method,
Object... parameters)
Invoke the static Method with the provided parameters. |
|
static
|
newInstance(Class clazz)
Instantiate a new Object of the provided type. |
|
static
|
newInstance(Class clazz,
Object[] args,
Class[] argsTypes)
Instantiate a new Object of the provided type. |
|
static
|
newInstance(String className)
Instantiate a new Object of the provided type. |
|
static void |
setFieldValue(Object target,
String fieldName,
Object value)
Set the value of the field matching the given name and belonging to target Object. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> T newInstance(String className)
Object of the provided type.
T - class typeclassName - The fully-qualified Java class name of the Object to instantiate
Object of the provided typepublic static <T> T newInstance(Class clazz)
Object of the provided type.
T - class typeclazz - The Java Class of the Object to instantiate
Object of the provided type
public static <T> T newInstance(Class clazz,
Object[] args,
Class[] argsTypes)
Object of the provided type.
T - class typeclazz - The Java Class of the Object to instantiateargs - The arguments that need to be passed to the constructorargsTypes - The argument types that need to be passed to the constructor
Object of the provided type
public static Field getField(Class targetClass,
String fieldName)
Field with the given name belonging to the provided Java Class.
targetClass - the provided Java Class the field belongs tofieldName - the Field name
Field matching the given name
public static Field getFieldOrNull(Class targetClass,
String fieldName)
Field with the given name belonging to the provided Java Class or null
if no Field was found.
targetClass - the provided Java Class the field belongs tofieldName - the Field name
Field matching the given name or null
public static <T> T getFieldValue(Object target,
String fieldName)
Object.
T - field typetarget - target Object whose field we are retrieving the value fromfieldName - field name
public static <T> T getFieldValueOrNull(Object target,
String fieldName)
Object or null
if no Field was found..
T - field typetarget - target Object whose field we are retrieving the value fromfieldName - field name
null
public static void setFieldValue(Object target,
String fieldName,
Object value)
Object.
target - target objectfieldName - field namevalue - field value
public static Method getMethod(Object target,
String methodName,
Class... parameterTypes)
Method with the given signature (name and parameter types) belonging to
the provided Java Object.
target - target ObjectmethodName - method nameparameterTypes - method parameter types
Method matching the provided signature
public static Method getMethodOrNull(Class targetClass,
String methodName,
Class... parameterTypes)
Method with the given signature (name and parameter types) belonging to
the provided Java Object or null if no Method was found.
targetClass - target ClassmethodName - method nameparameterTypes - method parameter types
Method matching the provided signature or null
public static Method getMethodOrNull(Object target,
String methodName,
Class... parameterTypes)
Method with the given signature (name and parameter types) belonging to
the provided Java Object or null if no Method was found.
target - target ObjectmethodName - method nameparameterTypes - method parameter types
Method matching the provided signature or null
public static Method getMethod(Class targetClass,
String methodName,
Class... parameterTypes)
Method with the given signature (name and parameter types) belonging to
the provided Java Class.
targetClass - target ClassmethodName - method nameparameterTypes - method parameter types
Method matching the provided signature
public static Method getDeclaredMethodOrNull(Class targetClass,
String methodName,
Class... parameterTypes)
Method with the given signature (name and parameter types) belonging to
the provided Java Class, excluding inherited ones, or null if no Method was found.
targetClass - target ClassmethodName - method nameparameterTypes - method parameter types
Method matching the provided signature or null
public static boolean hasMethod(Class<?> targetClass,
String methodName,
Class... parameterTypes)
Class contains a method matching
the given signature (name and parameter types).
targetClass - target ClassmethodName - method nameparameterTypes - method parameter types
Class contains a method with the given signature
public static Method getSetter(Object target,
String propertyName,
Class<?> parameterType)
Method with the given signature (name and parameter types)
belonging to the provided Java Object.
target - target ObjectpropertyName - property nameparameterType - setter property type
Method matching the provided signature
public static Method getGetter(Object target,
String propertyName)
Method with the given name belonging to
the provided Java Object.
target - target ObjectpropertyName - property name
Method matching the provided name
public static <T> T invokeMethod(Object target,
Method method,
Object... parameters)
Method on the given Java Object.
T - return value object typetarget - target Object whose method we are invokingmethod - method to invokeparameters - parameters passed to the method call
Method invocation
public static <T> T invokeMethod(Object target,
String methodName,
Object... parameters)
Object.
T - return value object typetarget - target Object whose method we are invokingmethodName - method name to invokeparameters - parameters passed to the method call
public static <T> T invokeGetter(Object target,
String propertyName)
Object.
T - return value object typetarget - target Object whose property getter we are invokingpropertyName - property name whose getter we are invoking
public static void invokeSetter(Object target,
String propertyName,
Object parameter)
Object.
target - target Object whose property setter we are invokingpropertyName - property name whose setter we are invokingparameter - parameter passed to the setter call
public static void invokeSetter(Object target,
String propertyName,
boolean parameter)
boolean property setter with the provided name
on the given Java Object.
target - target Object whose property setter we are invokingpropertyName - property name whose setter we are invokingparameter - boolean parameter passed to the setter call
public static void invokeSetter(Object target,
String propertyName,
int parameter)
int property setter with the provided name
on the given Java Object.
target - target Object whose property setter we are invokingpropertyName - property name whose setter we are invokingparameter - int parameter passed to the setter call
public static <T> T invokeStaticMethod(Method method,
Object... parameters)
static Method with the provided parameters.
T - return value object typemethod - target static Method to invokeparameters - parameters passed to the method call
public static <T> Class<T> getClass(String className)
Class with the given fully-qualified name.
T - Class typeclassName - the Java Class name to be retrieved
Class objectpublic static <T> Class<T> getClassOrNull(String className)
Class with the given fully-qualified name or or null
if no Class was found matching the provided name.
T - Class typeclassName - the Java Class name to be retrieved
Class object or nullpublic static Class<?> getWrapperClass(Class<?> clazz)
Class associated to the given primitive type.
clazz - primitive class
Class
public static <T> Class<T> getFirstSuperClassFromPackage(Class clazz,
String packageName)
T - class generic typeclazz - Java classpackageName - package name
null.public static Set<Class> getGenericTypes(ParameterizedType parameterizedType)
parameterizedType - parameterized Type
public static Member getMemberOrNull(Class targetClass,
String memberName)
Member with the given name belonging to the provided Java Class or null
if no Member was found.
targetClass - the provided Java Class the field or method belongs tomemberName - the Field or Method name
Field or Method matching the given name or null
public static Type getMemberGenericTypeOrNull(Class targetClass,
String memberName)
Type of the Member with the given name belonging to the provided Java Class or null
if no Member was found.
targetClass - the provided Java Class the field or method belongs tomemberName - the Field or Method name
Type of the Field or Method matching the given name or null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||