java.lang.Object
de.knightsoftnet.validators.annotation.processor.TypeUtils

public class TypeUtils extends Object
  • Constructor Details

    • TypeUtils

      public TypeUtils()
  • Method Details

    • 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
    • getClassNameWithoutPath

      public static String getClassNameWithoutPath(TypeMirror typeMirror)
      get class name for type element without path.
      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
    • getClassNameWithPropertiesOfElementNoType

      public static String getClassNameWithPropertiesOfElementNoType(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, Types typeUtils)
      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, ProcessingEnvironment processingEnv)
      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
    • isGetter

      public static boolean isGetter(String elementName)
      check if element is a getter method.
      Parameters:
      elementName - 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 element 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, ProcessingEnvironment processingEnv)
      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
    • getValidationInterfaceForType

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

      public static String getValidationInstanceForType(TypeMirror typeMirror, Types typeUtils, Elements elementUtils)
      get validation interface for type mirror.
      Parameters:
      typeMirror - to get validation interface from
      typeUtils - type utils
      Returns:
      interface name as string
    • getValidationClassForType

      public static String getValidationClassForType(TypeMirror typeMirror, Types typeUtils, Elements elementUtils)
      get validation class for type mirror.
      Parameters:
      typeMirror - to get validation class from
      typeUtils - type utils
      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
    • getElementName

      public static String getElementName(TypeElementPropertyDescriptor propertyDescription)
      get element name, even if descriptor is getter, return element name.
      Parameters:
      propertyDescription - descriptor to test
      Returns:
      name of element