Class TypeUtils
java.lang.Object
de.knightsoftnet.validators.annotation.processor.TypeUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfieldElementByName(TypeMirror typeMirror, String valueName) element type.static Optional<TypeMirror>fieldType(TypeMirror typeMirror, String valueName, ProcessingEnvironment processingEnv) element type.static List<AnnotationMirror>getAnnotationsForElement(Element element, Types typeUtils, Elements elementUtils) get annotations for Element.static List<AnnotationMirror>getAnnotationsForType(TypeMirror typeMirror, Types typeUtils, Elements elementUtils) get annotations for type.static StringgetClassName(TypeElement element) get class name for type element.static StringgetClassName(TypeMirror typeMirror) get class name for type element.static StringgetClassNameWithProperties(TypeMirror typeMirror) get class name for type mirror with properties.static StringgetClassNameWithPropertiesOfElement(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.static StringgetClassNameWithPropertiesOfElementNoType(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.static StringgetElementName(TypeElementPropertyDescriptor propertyDescription) get element name, even if descriptor is getter, return element name.getFields(TypeMirror typeMirror) get list of fields for a type mirror.static List<ExecutableElement>getGetter(TypeMirror typeMirror) get list of getters for a type mirror.static Optional<ExecutableElement>getGetter(TypeMirror typeMirror, String valueName) get getter for a value name.getGetterNames(TypeMirror typeMirror) get list of getter names for a type mirror.static List<TypeMirror>getInterfaces(TypeMirror typeMirror) get list of interfaces of a type mirror.static Optional<ExecutableElement>getMethod(TypeMirror typeMirror, String methodName) getter method.static List<ExecutableElement>getMethods(TypeMirror typeMirror) get list of methods for a type mirror.getRecursiveEnclosedElements(TypeMirror typeMirror) get list of getters for a type mirror.static StringgetterNameFromElement(Element element) get the getter name from element.static Optional<TypeMirror>getterReturnType(TypeMirror typeMirror, String valueName) getter return type.static TypegetType(TypeMirror typeMirror) get type for type mirror.static List<TypeElementConstraintDescriptor<?>>getTypeElementConstraintDescriptors(TypeMirror typeMirror, Elements elementUtils, Types typeUtils) Returns all constraint descriptors for this element in the class hierarchy or an emptySetif none are present.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).static StringgetValidationClassForType(TypeMirror typeMirror, Types typeUtils, Elements elementUtils) get validation class for type mirror.static StringgetValidationInstanceForType(TypeMirror typeMirror, Types typeUtils, Elements elementUtils) get validation interface for type mirror.static StringgetValidationInterfaceForType(TypeMirror typeMirror, Types typeUtils) get validation interface for type mirror.static booleanhasField(TypeMirror typeMirror, String valueName) test if a element name has exists.static booleanhasGetter(TypeMirror typeMirror, String valueName) test if a element name has a corresponding getter.static booleanisBeanConstrained(TypeMirror typeMirror, Types typeUtils, Elements elementUtils) Returnstrueif the bean involves validation.static booleancheck if element is a getter method.static booleancheck if element is a getter method.static StringvalueFromGetter(String getterName) get element from getter.
-
Constructor Details
-
TypeUtils
public TypeUtils()
-
-
Method Details
-
getClassName
get class name for type element.- Parameters:
element- to get name for- Returns:
- class name
-
getClassName
get class name for type element.- Parameters:
typeMirror- to get name for- Returns:
- class name
-
getClassNameWithProperties
get class name for type mirror with properties.- Parameters:
typeMirror- to get name for- Returns:
- class name
-
getClassNameWithPropertiesOfElement
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 forfield- 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 forfield- element to check if typeMirrorContains it.- Returns:
- class name
-
isBeanConstrained
public static boolean isBeanConstrained(TypeMirror typeMirror, Types typeUtils, Elements elementUtils) Returnstrueif 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:
trueif the bean involves validation,falseotherwise
-
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 emptySetif none are present.- Parameters:
typeMirror- to get getter from- Returns:
Setof 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
get list of getters for a type mirror.- Parameters:
typeMirror- to get getter from- Returns:
- list of getters
-
getGetterNames
get list of getter names for a type mirror.- Parameters:
typeMirror- to get getter from- Returns:
- list of getters
-
getGetter
get list of getters for a type mirror.- Parameters:
typeMirror- to get getter from- Returns:
- list of getters
-
getGetter
get getter for a value name.- Parameters:
typeMirror- type mirror of the classvalueName- value element name- Returns:
- true if getter exists.
-
isGetter
check if element is a getter method.- Parameters:
element- to check- Returns:
- true if it is a getter
-
isGetter
check if element is a getter method.- Parameters:
elementName- to check- Returns:
- true if it is a getter
-
getInterfaces
get list of interfaces of a type mirror.- Parameters:
typeMirror- to get getter from- Returns:
- list of getters
-
getMethods
get list of methods for a type mirror.- Parameters:
typeMirror- to get methods from- Returns:
- list of methods
-
getFields
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 fromtypeUtils- type utilselementUtils- 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 fromtypeUtils- type utilselementUtils- element utils- Returns:
- list of annotation mirrors
-
getterNameFromElement
get the getter name from element.- Parameters:
element- to get getter name from- Returns:
- getter name
-
valueFromGetter
get element from getter.- Parameters:
getterName- name of getter method- Returns:
- element name
-
hasGetter
test if a element name has a corresponding getter.- Parameters:
typeMirror- type mirror of the classvalueName- value element name- Returns:
- true if getter exists.
-
hasField
test if a element name has exists.- Parameters:
typeMirror- type mirror of the classvalueName- value element name- Returns:
- true if element exists.
-
getterReturnType
getter return type.- Parameters:
typeMirror- type mirror of the classvalueName- value element name- Returns:
- type mirror of getters return type
-
getMethod
getter method.- Parameters:
typeMirror- type mirror of the classmethodName- 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 classvalueName- value element name- Returns:
- type mirror of getters return type
-
fieldElementByName
element type.- Parameters:
typeMirror- type mirror of the classvalueName- value element name- Returns:
- type mirror of getters return type
-
getValidationInterfaceForType
get validation interface for type mirror.- Parameters:
typeMirror- to get validation interface fromtypeUtils- 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 fromtypeUtils- 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 fromtypeUtils- type utils- Returns:
- validation class as string
-
getType
get type for type mirror.- Parameters:
typeMirror- to get validation class from- Returns:
- type
-
getElementName
get element name, even if descriptor is getter, return element name.- Parameters:
propertyDescription- descriptor to test- Returns:
- name of element
-