Class ConstraintHelper
java.lang.Object
org.hibernate.validator.ap.internal.util.ConstraintHelper
Helper class that deals with all constraint-related stuff, such as
determining whether a given annotation represents a constraint annotation or
whether a given annotation is allowed to be declared at a given element.
- Author:
- Gunnar Morling, Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI, Guillaume Smet
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The validation target of a constraint annotation.static enum
Defines the object on which a validation is targeted.static enum
The type of an annotation with respect to the BV API.static enum
Possible results of a constraint check as returned bycheckConstraint(DeclaredType, TypeMirror)
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncheckConstraint
(DeclaredType constraintAnnotationType, TypeMirror typeOfAnnotatedElement) Checks whether the given annotation type (which must be a constraint annotation type) may be specified at elements of the specified type.checkCrossParameterTypes
(DeclaredType constraintAnnotationType) Check that a constraint has at most one cross-parameter validator that resolves to Object or Object[].getAnnotationType
(AnnotationMirror annotationMirror) Returns theConstraintHelper.AnnotationType
of the given annotation.getPartsOfMultiValuedConstraint
(AnnotationMirror annotationMirror) Returns a list with the constraint annotations contained in the given array-valued annotation mirror.getSupportedValidationTargets
(DeclaredType constraintAnnotationType) Returns the set ofAnnotationProcessorValidationTarget
supported by the given constraint annotation type.getUnwrappedToByDefault
(Name typeName) boolean
isComposedConstraint
(TypeElement element) Checks whether the given type element represents a composed constraint or not.boolean
isConstraintAnnotation
(Element element) Checks whether the given type element represents a constraint annotation or not.boolean
isSupportedForUnwrappingByDefault
(Name typeName) resolveValidationTarget
(ExecutableElement element, AnnotationMirror annotation) Resolve the actualAnnotationProcessorValidationTarget
of a constraint annotation, when applied to a method/constructor.
-
Constructor Details
-
ConstraintHelper
-
-
Method Details
-
isConstraintAnnotation
Checks whether the given type element represents a constraint annotation or not. That's the case, if the given element is annotated with the@Constraint
meta-annotation (which is only allowed at annotation declarations).- Parameters:
element
- The element of interest.- Returns:
- True, if the given element is a constraint annotation type, false otherwise.
-
getAnnotationType
Returns theConstraintHelper.AnnotationType
of the given annotation.- Parameters:
annotationMirror
- The annotation mirror of interest.- Returns:
- The given mirror's annotation type.
-
getPartsOfMultiValuedConstraint
Returns a list with the constraint annotations contained in the given array-valued annotation mirror.- Parameters:
annotationMirror
- An array-valued annotation mirror (meaning it has an array-typed attribute with name "value").- Returns:
- A list with the constraint annotations part of the given multi-valued constraint annotation. Will return an empty list if the given annotation is no multi-valued annotation or if no constraint annotations are contained within the given array-valued annotation.
-
checkConstraint
public ConstraintHelper.ConstraintCheckResult checkConstraint(DeclaredType constraintAnnotationType, TypeMirror typeOfAnnotatedElement) Checks whether the given annotation type (which must be a constraint annotation type) may be specified at elements of the specified type.- Parameters:
constraintAnnotationType
- A constraint annotation type.typeOfAnnotatedElement
- A type which with an element is annotated.- Returns:
- Whether the given constraint annotation may be specified at elements of the given type.
-
isComposedConstraint
Checks whether the given type element represents a composed constraint or not.- Parameters:
element
- The type element of interest. Must not be null.- Returns:
- True if the given element represents a composed constraint, false otherwise.
-
resolveValidationTarget
public ConstraintHelper.AnnotationProcessorValidationTarget resolveValidationTarget(ExecutableElement element, AnnotationMirror annotation) Resolve the actualAnnotationProcessorValidationTarget
of a constraint annotation, when applied to a method/constructor.When the annotation supports multiple
ConstraintHelper.AnnotationProcessorValidationTarget
s (i.e. it is both cross-parameter and generic), the actual target is resolved using the 'validationAppliesTo()' attribute of the annotation.- Parameters:
element
- the method/constructor on which the annotation is appliedannotation
- the constraint annotation- Returns:
- the resolved
AnnotationProcessorValidationTarget
, null if the target cannot be inferred
-
getSupportedValidationTargets
public Set<ConstraintHelper.AnnotationProcessorValidationTarget> getSupportedValidationTargets(DeclaredType constraintAnnotationType) Returns the set ofAnnotationProcessorValidationTarget
supported by the given constraint annotation type.A constraint annotation can support
ConstraintHelper.AnnotationProcessorValidationTarget.ANNOTATED_ELEMENT
,ConstraintHelper.AnnotationProcessorValidationTarget.PARAMETERS
or both.- Parameters:
constraintAnnotationType
- the constraint annotation type- Returns:
- the set of supported
AnnotationProcessorValidationTarget
s
-
checkCrossParameterTypes
public ConstraintHelper.ConstraintCheckResult checkCrossParameterTypes(DeclaredType constraintAnnotationType) Check that a constraint has at most one cross-parameter validator that resolves to Object or Object[].- Parameters:
constraintAnnotationType
- the constraint type- Returns:
ConstraintCheckResult#MULTIPLE_VALIDATORS_FOUND
if the constraint has more than one cross-parameter validator,ConstraintCheckResult#DISALLOWED
if the constraint has one cross-parameter validator with a wrong generic type,ConstraintCheckResult#ALLOWED
otherwise
-
getTypeUtils
-
isSupportedForUnwrappingByDefault
-
getUnwrappedToByDefault
-