Package yakworks.commons.lang
Class ReflectionUtils
- java.lang.Object
-
- yakworks.commons.lang.ReflectionUtils
-
public class ReflectionUtils extends java.lang.ObjectProvides methods to help with reflective operations- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map<java.lang.Class<?>,java.lang.Class<?>>PRIMITIVE_TYPE_COMPATIBLE_CLASSES
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisAssignableFrom(java.lang.Class<?> leftType, java.lang.Class<?> rightType)Tests whether or not the left hand type is compatible with the right hand type in Groovy terms, i.e.static booleanisGetter(java.lang.String name, java.lang.Class<?>[] args)Returns true if the name of the method specified and the number of arguments make it a javabean propertystatic booleanisSetter(java.lang.String name, java.lang.Class[] args)static voidmakeAccessible(java.lang.reflect.Field field)Make the given field accessible, explicitly setting it accessible if necessary.static voidmakeAccessible(java.lang.reflect.Method method)Make the given method accessible, explicitly setting it accessible if necessary.
-
-
-
Method Detail
-
makeAccessible
public static void makeAccessible(java.lang.reflect.Field field)
Make the given field accessible, explicitly setting it accessible if necessary. ThesetAccessible(true)method is only called when actually necessary, to avoid unnecessary conflicts with a JVM SecurityManager (if active). Based on the same method in Spring core.- Parameters:
field- the field to make accessible- See Also:
Field.setAccessible(boolean)
-
makeAccessible
public static void makeAccessible(java.lang.reflect.Method method)
Make the given method accessible, explicitly setting it accessible if necessary. ThesetAccessible(true)method is only called when actually necessary, to avoid unnecessary conflicts with a JVM SecurityManager (if active). Based on the same method in Spring core.- Parameters:
method- the method to make accessible- See Also:
Method.setAccessible(boolean)
-
isAssignableFrom
public static boolean isAssignableFrom(java.lang.Class<?> leftType, java.lang.Class<?> rightType)Tests whether or not the left hand type is compatible with the right hand type in Groovy terms, i.e. can the left type be assigned a value of the right hand type in Groovy.
This handles Java primitive type equivalence and uses isAssignableFrom for all other types, with a bit of magic for native types and polymorphism i.e. Number assigned an int. If either parameter is null an exception is thrown
- Parameters:
leftType- The type of the left hand part of a notional assignmentrightType- The type of the right hand part of a notional assignment- Returns:
- True if values of the right hand type can be assigned in Groovy to variables of the left hand type.
-
isGetter
public static boolean isGetter(java.lang.String name, java.lang.Class<?>[] args)Returns true if the name of the method specified and the number of arguments make it a javabean property- Parameters:
name- True if its a Javabean propertyargs- The arguments- Returns:
- true if it is a javabean property method
-
isSetter
public static boolean isSetter(java.lang.String name, java.lang.Class[] args)
-
-