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
Nested ClassesModifier and TypeClassDescriptionstatic enumThe validation target of a constraint annotation.static enumDefines the object on which a validation is targeted.static enumThe type of an annotation with respect to the BV API.static enumPossible results of a constraint check as returned bycheckConstraint(DeclaredType, TypeMirror). -
Constructor Summary
Constructors -
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.AnnotationTypeof 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 ofAnnotationProcessorValidationTargetsupported by the given constraint annotation type.getUnwrappedToByDefault(Name typeName) booleanisComposedConstraint(TypeElement element) Checks whether the given type element represents a composed constraint or not.booleanisConstraintAnnotation(Element element) Checks whether the given type element represents a constraint annotation or not.booleanisSupportedForUnwrappingByDefault(Name typeName) resolveValidationTarget(ExecutableElement element, AnnotationMirror annotation) Resolve the actualAnnotationProcessorValidationTargetof 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@Constraintmeta-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.AnnotationTypeof 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 actualAnnotationProcessorValidationTargetof a constraint annotation, when applied to a method/constructor.When the annotation supports multiple
ConstraintHelper.AnnotationProcessorValidationTargets (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 ofAnnotationProcessorValidationTargetsupported by the given constraint annotation type.A constraint annotation can support
ConstraintHelper.AnnotationProcessorValidationTarget.ANNOTATED_ELEMENT,ConstraintHelper.AnnotationProcessorValidationTarget.PARAMETERSor both.- Parameters:
constraintAnnotationType- the constraint annotation type- Returns:
- the set of supported
AnnotationProcessorValidationTargets
-
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_FOUNDif the constraint has more than one cross-parameter validator,ConstraintCheckResult#DISALLOWEDif the constraint has one cross-parameter validator with a wrong generic type,ConstraintCheckResult#ALLOWEDotherwise
-
getTypeUtils
-
isSupportedForUnwrappingByDefault
-
getUnwrappedToByDefault
-