Class TypeUtils


  • public class TypeUtils
    extends Object
    • Constructor Detail

      • TypeUtils

        public TypeUtils()
    • Method Detail

      • getClassName

        public static String getClassName​(TypeElement element)
        get class name for type element.
        Parameters:
        element - to get name for
        Returns:
        class name
      • getClassName

        public static String getClassName​(TypeMirror typeMirror)
        get class name for type element.
        Parameters:
        typeMirror - to get name for
        Returns:
        class name
      • getClassNameWithProperties

        public static String getClassNameWithProperties​(TypeMirror typeMirror)
        get class name for type mirror with properties.
        Parameters:
        typeMirror - to get name for
        Returns:
        class name
      • getClassNameWithPropertiesOfElement

        public static String getClassNameWithPropertiesOfElement​(TypeMirror typeMirror,
                                                                 Element field)
        get class name for type mirror with properties which contains given field, if it's defined in super class, the name of superclass is returned.
        Parameters:
        typeMirror - (or it's superclass) to get name for
        field - element to check if typeMirrorContains it.
        Returns:
        class name
      • isBeanConstrained

        public static boolean isBeanConstrained​(TypeMirror typeMirror,
                                                Types typeUtils,
                                                Elements elementUtils)
        Returns true if the bean involves validation.
        • a constraint is hosted on the bean itself
        • a constraint is hosted on one of the bean properties
        • or a bean property is marked for cascaded validation (Valid)

        Constrained methods and constructors are ignored.

        Parameters:
        typeMirror - to get getter from
        Returns:
        true if the bean involves validation, false otherwise
      • getTypeElementConstraintDescriptors

        public static List<TypeElementConstraintDescriptor<?>> getTypeElementConstraintDescriptors​(TypeMirror typeMirror,
                                                                                                   Elements elementUtils)
        Returns all constraint descriptors for this element in the class hierarchy or an empty Set if none are present.
        Parameters:
        typeMirror - to get getter from
        Returns:
        Set of type element constraint descriptors for this element
      • getTypeElementProperties

        public static List<TypeElementPropertyDescriptor> getTypeElementProperties​(TypeMirror typeMirror,
                                                                                   Elements elementUtils)
        Returns a set of type element property descriptors having at least one constraint defined or marked as cascaded (Valid).

        If no property matches, an empty set is returned. Properties of super types are considered.

        Parameters:
        typeMirror - to get getter from
        Returns:
        the set of PropertyDescriptors for the constraint properties; if there are no constraint properties, the empty set is returned
      • getRecursiveEnclosedElements

        public static List<Element> getRecursiveEnclosedElements​(TypeMirror typeMirror)
        get list of getters for a type mirror.
        Parameters:
        typeMirror - to get getter from
        Returns:
        list of getters
      • getGetterNames

        public static List<String> getGetterNames​(TypeMirror typeMirror)
        get list of getter names for a type mirror.
        Parameters:
        typeMirror - to get getter from
        Returns:
        list of getters
      • getGetter

        public static List<ExecutableElement> getGetter​(TypeMirror typeMirror)
        get list of getters for a type mirror.
        Parameters:
        typeMirror - to get getter from
        Returns:
        list of getters
      • getGetter

        public static Optional<ExecutableElement> getGetter​(TypeMirror typeMirror,
                                                            String valueName)
        get getter for a value name.
        Parameters:
        typeMirror - type mirror of the class
        valueName - value element name
        Returns:
        true if getter exists.
      • isGetter

        public static boolean isGetter​(Element element)
        check if element is a getter method.
        Parameters:
        element - to check
        Returns:
        true if it is a getter
      • getInterfaces

        public static List<TypeMirror> getInterfaces​(TypeMirror typeMirror)
        get list of interfaces of a type mirror.
        Parameters:
        typeMirror - to get getter from
        Returns:
        list of getters
      • getMethods

        public static List<ExecutableElement> getMethods​(TypeMirror typeMirror)
        get list of methods for a type mirror.
        Parameters:
        typeMirror - to get methods from
        Returns:
        list of methods
      • getFields

        public static List<Element> getFields​(TypeMirror typeMirror)
        get list of fields for a type mirror.
        Parameters:
        typeMirror - to get fields from
        Returns:
        list of field elements
      • getAnnotationsForType

        public static List<AnnotationMirror> getAnnotationsForType​(TypeMirror typeMirror,
                                                                   Types typeUtils,
                                                                   Elements elementUtils)
        get annotations for type.
        Parameters:
        typeMirror - to get annotations from
        typeUtils - type utils
        elementUtils - element utils
        Returns:
        list of annotation mirrors
      • getAnnotationsForElement

        public static List<AnnotationMirror> getAnnotationsForElement​(Element element,
                                                                      Types typeUtils,
                                                                      Elements elementUtils)
        get annotations for Element.
        Parameters:
        element - to get annotations from
        typeUtils - type utils
        elementUtils - element utils
        Returns:
        list of annotation mirrors
      • getterNameFromElement

        public static String getterNameFromElement​(Element element)
        get the getter name from element.
        Parameters:
        element - to get getter name from
        Returns:
        getter name
      • valueFromGetter

        public static String valueFromGetter​(String getterName)
        get element from getter.
        Parameters:
        getterName - name of getter method
        Returns:
        element name
      • hasGetter

        public static boolean hasGetter​(TypeMirror typeMirror,
                                        String valueName)
        test if a element name has a corresponding getter.
        Parameters:
        typeMirror - type mirror of the class
        valueName - value element name
        Returns:
        true if getter exists.
      • hasField

        public static boolean hasField​(TypeMirror typeMirror,
                                       String valueName)
        test if a element name has exists.
        Parameters:
        typeMirror - type mirror of the class
        valueName - value element name
        Returns:
        true if getter exists.
      • getterReturnType

        public static Optional<TypeMirror> getterReturnType​(TypeMirror typeMirror,
                                                            String valueName)
        getter return type.
        Parameters:
        typeMirror - type mirror of the class
        valueName - value element name
        Returns:
        type mirror of getters return type
      • getMethod

        public static Optional<ExecutableElement> getMethod​(TypeMirror typeMirror,
                                                            String methodName)
        getter method.
        Parameters:
        typeMirror - type mirror of the class
        methodName - name of the method
        Returns:
        type mirror of getters return type
      • fieldType

        public static Optional<TypeMirror> fieldType​(TypeMirror typeMirror,
                                                     String valueName)
        element type.
        Parameters:
        typeMirror - type mirror of the class
        valueName - value element name
        Returns:
        type mirror of getters return type
      • fieldElementByName

        public static Optional<Element> fieldElementByName​(TypeMirror typeMirror,
                                                           String valueName)
        element type.
        Parameters:
        typeMirror - type mirror of the class
        valueName - value element name
        Returns:
        type mirror of getters return type
      • getPackageOfType

        public static String getPackageOfType​(TypeMirror typeMirror)
        get package of type mirror.
        Parameters:
        typeMirror - to get package from
        Returns:
        package as string
      • getValidationInterfaceForType

        public static String getValidationInterfaceForType​(TypeMirror typeMirror)
        get validation interface for type mirror.
        Parameters:
        typeMirror - to get validation interface from
        Returns:
        interface name as string
      • getValidationInstanceForType

        public static String getValidationInstanceForType​(TypeMirror typeMirror)
        get validation interface for type mirror.
        Parameters:
        typeMirror - to get validation interface from
        Returns:
        interface name as string
      • getValidationClassForType

        public static String getValidationClassForType​(TypeMirror typeMirror)
        get validation class for type mirror.
        Parameters:
        typeMirror - to get validation class from
        Returns:
        validation class as string
      • getType

        public static Type getType​(TypeMirror typeMirror)
        get type for type mirror.
        Parameters:
        typeMirror - to get validation class from
        Returns:
        type