MemberUtil¶
-
public final class
MemberUtil
¶ Util class that provides convenient methods connected with the class members.
Fields¶
Methods¶
getCorrectType¶
-
public static Class<?>
getCorrectType
(AnnotatedElement object)¶ Gets annotated element type. If this element is not a member of the class, it returns null. Otherwise, it will try to resolve the type by checking it directly, or via getter/setter methods. If member is neither a field or getter/setter method, it returns null.
Parameters: - object – annotated element to retrieve type from
Returns: type of the element, or null if not applicable
getCorrectType¶
-
public static Class<?>
getCorrectType
(Member object)¶ Gets member type. It will try to resolve the type by checking it directly, or via getter/setter methods. If member is neither a field or getter/setter method, it returns null.
Parameters: - object – annotated element to retrieve type from
Returns: type of the element, or null if not applicable
getDeclaringClass¶
-
public static Class<?>
getDeclaringClass
(AccessibleObject ac)¶ Retrieves a declaring class for the given object. Returns null if the given object is not a member of a class.
Parameters: - ac – object to verify
Returns: A class, to which this object belongs
getDefaultEnumName¶
getFieldAndAccessorsForElement¶
-
public static List<AccessibleObject>
getFieldAndAccessorsForElement
(AccessibleObject ao)¶ Returns a list of objects, that are either field or getter/setter methods of this field, based on single accessible object of a class. If it fails to find anything, it returns the passed object.
Parameters: - ao – an object to find field, getter/setter method for
Returns: a list of field and getter/setter methods or
ao
if nothing has been found
getFieldName¶
-
public static String
getFieldName
(AnnotatedElement object)¶ Gets field name, from the specified annotated element. It will return null, if annotated element is not a class member. Otherwise, it will try to resolve the field name, by either reading it directly from the member, or by determining the name, based on the getter/setter method. It will return null if member is neither a field or getter/setter.
Parameters: - object – annotated element to retrieve field name from
Returns: field name, if possible; null otherwise
getFieldName¶
-
public static String
getFieldName
(Member object)¶ Gets field name, from the specified member. It will try to resolve the field name, by either reading it directly from the member, or by determining the name, based on the getter/setter method. It will return null if member is neither a field or getter/setter.
Parameters: - object – class member to retrieve field name from
Returns: field name, if possible; null otherwise
getFieldNameFromGetterSetterName¶
-
public static String
getFieldNameFromGetterSetterName
(String getterSetterName)¶ Attempts to retrieve field name from the getter/setter method name. It will throw
java.lang.IllegalArgumentException
if provided value is empty or does not match the setter/getter naming convention.Parameters: - getterSetterName – getter/setter method name
Returns: field name
getGenericType¶
-
public static Class<?>
getGenericType
(AnnotatedElement object)¶ Retrieves an actual type from the parameterized class member. If annotated element is not a class member, it returns null. It always checks for the first parameter. If you want to specify which parameter to retrieve, use
getGenericType(java.lang.reflect.AnnotatedElement,int)
. This will work on fields and getter/setter methods. It will return null for other class members or if there is no parameterized type on them.Parameters: - object – annotated element to retrieve actual type from
Returns: Actual type of the parameterized class member
getGenericType¶
-
public static Class<?>
getGenericType
(AnnotatedElement object, int typeNumber)¶ Retrieves an actual type from the parameterized class member. If annotated element is not a class member, it returns null. It will check the parameter on position
typeNumber
. This will work on fields and getter/setter methods. It will return null for other class members or if there is no parameterized type on them.Parameters: - object – annotated element to retrieve actual type from
- typeNumber – position of the parameterized type
Returns: Actual type of the parameterized class member
getGenericType¶
-
public static Class<?>
getGenericType
(Member object, int typeNumber)¶ Retrieves an actual type from the parameterized class member. It will check the parameter on position
typeNumber
This will work on fields and getter/setter methods. It will return null for other class members or if there is no parameterized type on them.Parameters: - object – class member to retrieve actual type from
- typeNumber – position of the parameterized type
Returns: Actual type of the parameterized class member