Class ReflectionUtils
java.lang.Object
io.hypersistence.utils.hibernate.util.ReflectionUtils
ReflectionUtils - Reflection utilities holder.- Since:
- 1.0
- Author:
- Vlad Mihalcea
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Class<T>Get the JavaClasswith the given fully-qualified name.static <T> Class<T>getClassOrNull(String className) static MethodgetDeclaredMethodOrNull(Class targetClass, String methodName, Class... parameterTypes) static Fieldstatic FieldgetFieldOrNull(Class targetClass, String fieldName) static <T> TgetFieldValue(Object target, String fieldName) Get the value of the field matching the given name and belonging to targetObject.static <T> TgetFieldValueOrNull(Class targetClass, String fieldName) static <T> TgetFieldValueOrNull(Object target, String fieldName) static <T> Class<T>getFirstSuperClassFromPackage(Class clazz, String packageName) Get the first super class matching the provided package name.getGenericTypes(ParameterizedType parameterizedType) Get the generic types of a given Class.static Methodstatic TypegetMemberGenericTypeOrNull(Class targetClass, String memberName) static MembergetMemberOrNull(Class targetClass, String memberName) static ClassgetMemberType(Member member) Get the Member type.static Methodstatic Methodstatic MethodgetMethodOrNull(Class targetClass, String methodName, Class... parameterTypes) static MethodgetMethodOrNull(Object target, String methodName, Class... parameterTypes) static Methodstatic Class<?>getWrapperClass(Class<?> clazz) Get the Java WrapperClassassociated to the given primitive type.static booleanCheck if the provided JavaClasscontains a method matching the given signature (name and parameter types).static <T> TinvokeGetter(Object target, String propertyName) Invoke the property getter with the provided name on the given JavaObject.static <T> TinvokeMethod(Object target, Method method, Object... parameters) static <T> TinvokeMethod(Object target, String methodName, Object... parameters) Invoke the method with the provided signature (name and parameter types) on the given JavaObject.static voidinvokeSetter(Object target, String propertyName, boolean parameter) Invoke thebooleanproperty setter with the provided name on the given JavaObject.static voidinvokeSetter(Object target, String propertyName, int parameter) Invoke theintproperty setter with the provided name on the given JavaObject.static voidinvokeSetter(Object target, String propertyName, Object parameter) Invoke the property setter with the provided signature (name and parameter types) on the given JavaObject.static <T> TinvokeStaticMethod(Method method, Object... parameters) Invoke thestaticMethodwith the provided parameters.static <T> TnewInstance(Class clazz) Instantiate a newObjectof the provided type.static <T> TnewInstance(Class clazz, Object[] args, Class[] argsTypes) Instantiate a newObjectof the provided type.static <T> TnewInstance(String className) Instantiate a newObjectof the provided type.static voidsetFieldValue(Object target, String fieldName, Object value) Set the value of the field matching the given name and belonging to targetObject.
-
Method Details
-
newInstance
Instantiate a newObjectof the provided type. -
newInstance
Instantiate a newObjectof the provided type. -
newInstance
Instantiate a newObjectof the provided type. -
getField
-
getFieldOrNull
-
getFieldValueOrNull
-
getFieldValue
Get the value of the field matching the given name and belonging to targetObject.- Type Parameters:
T- field type- Parameters:
target- targetObjectwhose field we are retrieving the value fromfieldName- field name- Returns:
- field value
-
getFieldValueOrNull
Get the value of the field matching the given name and belonging to targetObjectornullif noFieldwas found..- Type Parameters:
T- field type- Parameters:
target- targetObjectwhose field we are retrieving the value fromfieldName- field name- Returns:
- field value matching the given name or
null
-
setFieldValue
Set the value of the field matching the given name and belonging to targetObject.- Parameters:
target- target objectfieldName- field namevalue- field value
-
getMethod
-
getMethodOrNull
-
getMethod
-
getMethodOrNull
-
getDeclaredMethodOrNull
public static Method getDeclaredMethodOrNull(Class targetClass, String methodName, Class... parameterTypes) -
hasMethod
Check if the provided JavaClasscontains a method matching the given signature (name and parameter types). -
getSetter
-
getGetter
-
invokeMethod
-
invokeMethod
Invoke the method with the provided signature (name and parameter types) on the given JavaObject.- Type Parameters:
T- return value object type- Parameters:
target- targetObjectwhose method we are invokingmethodName- method name to invokeparameters- parameters passed to the method call- Returns:
- the value return by the method invocation
-
invokeGetter
Invoke the property getter with the provided name on the given JavaObject.- Type Parameters:
T- return value object type- Parameters:
target- targetObjectwhose property getter we are invokingpropertyName- property name whose getter we are invoking- Returns:
- the value return by the getter invocation
-
invokeSetter
Invoke the property setter with the provided signature (name and parameter types) on the given JavaObject.- Parameters:
target- targetObjectwhose property setter we are invokingpropertyName- property name whose setter we are invokingparameter- parameter passed to the setter call
-
invokeSetter
Invoke thebooleanproperty setter with the provided name on the given JavaObject.- Parameters:
target- targetObjectwhose property setter we are invokingpropertyName- property name whose setter we are invokingparameter-booleanparameter passed to the setter call
-
invokeSetter
Invoke theintproperty setter with the provided name on the given JavaObject.- Parameters:
target- targetObjectwhose property setter we are invokingpropertyName- property name whose setter we are invokingparameter-intparameter passed to the setter call
-
invokeStaticMethod
Invoke thestaticMethodwith the provided parameters.- Type Parameters:
T- return value object type- Parameters:
method- targetstaticMethodto invokeparameters- parameters passed to the method call- Returns:
- the value return by the method invocation
-
getClass
Get the JavaClasswith the given fully-qualified name. -
getClassOrNull
-
getWrapperClass
Get the Java WrapperClassassociated to the given primitive type.- Parameters:
clazz- primitive class- Returns:
- the Java Wrapper
Class
-
getFirstSuperClassFromPackage
Get the first super class matching the provided package name.- Type Parameters:
T- class generic type- Parameters:
clazz- Java classpackageName- package name- Returns:
- the first super class matching the provided package name or
null.
-
getGenericTypes
Get the generic types of a given Class.- Parameters:
parameterizedType- parameterized Type- Returns:
- generic types for the given Class.
-
getMemberOrNull
-
getMemberGenericTypeOrNull
-
getMemberType
Get the Member type.- Parameters:
member- member- Returns:
- member type
-