public class ConstraintHelper
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ConstraintHelper.AnnotationProcessorConstraintTarget
The validation target of a constraint annotation.
|
static class |
ConstraintHelper.AnnotationProcessorValidationTarget
Defines the object on which a validation is targeted.
|
static class |
ConstraintHelper.AnnotationType
The type of an annotation with respect to the BV API.
|
static class |
ConstraintHelper.ConstraintCheckResult
Possible results of a constraint check as returned by
checkConstraint(DeclaredType, TypeMirror) . |
Constructor and Description |
---|
ConstraintHelper(javax.lang.model.util.Types typeUtils,
AnnotationApiHelper annotationApiHelper) |
Modifier and Type | Method and Description |
---|---|
ConstraintHelper.ConstraintCheckResult |
checkConstraint(javax.lang.model.type.DeclaredType constraintAnnotationType,
javax.lang.model.type.TypeMirror typeOfAnnotatedElement)
Checks whether the given annotation type (which must be a
constraint annotation type) may be specified at elements of the specified
type.
|
ConstraintHelper.ConstraintCheckResult |
checkCrossParameterTypes(javax.lang.model.type.DeclaredType constraintAnnotationType)
Check that a constraint has at most one cross-parameter validator that resolves to Object or Object[].
|
ConstraintHelper.AnnotationType |
getAnnotationType(javax.lang.model.element.AnnotationMirror annotationMirror)
Returns the
ConstraintHelper.AnnotationType of the given annotation. |
java.util.List<javax.lang.model.element.AnnotationMirror> |
getPartsOfMultiValuedConstraint(javax.lang.model.element.AnnotationMirror annotationMirror)
Returns a list with the constraint annotations contained in the given
array-valued annotation mirror.
|
java.util.Set<ConstraintHelper.AnnotationProcessorValidationTarget> |
getSupportedValidationTargets(javax.lang.model.type.DeclaredType constraintAnnotationType)
Returns the set of
AnnotationProcessorValidationTarget supported by the given constraint annotation type. |
javax.lang.model.util.Types |
getTypeUtils() |
java.util.Optional<javax.lang.model.type.TypeMirror> |
getUnwrappedToByDefault(javax.lang.model.element.Name typeName) |
boolean |
isComposedConstraint(javax.lang.model.element.TypeElement element)
Checks whether the given type element represents a composed constraint or not.
|
boolean |
isConstraintAnnotation(javax.lang.model.element.Element element)
Checks whether the given type element represents a constraint annotation
or not.
|
boolean |
isSupportedForUnwrappingByDefault(javax.lang.model.element.Name typeName) |
ConstraintHelper.AnnotationProcessorValidationTarget |
resolveValidationTarget(javax.lang.model.element.ExecutableElement element,
javax.lang.model.element.AnnotationMirror annotation)
Resolve the actual
AnnotationProcessorValidationTarget of a constraint annotation, when applied to a method/constructor. |
public ConstraintHelper(javax.lang.model.util.Types typeUtils, AnnotationApiHelper annotationApiHelper)
public boolean isConstraintAnnotation(javax.lang.model.element.Element element)
@Constraint
meta-annotation (which is only allowed at annotation
declarations).element
- The element of interest.public ConstraintHelper.AnnotationType getAnnotationType(javax.lang.model.element.AnnotationMirror annotationMirror)
ConstraintHelper.AnnotationType
of the given annotation.annotationMirror
- The annotation mirror of interest.public java.util.List<javax.lang.model.element.AnnotationMirror> getPartsOfMultiValuedConstraint(javax.lang.model.element.AnnotationMirror annotationMirror)
annotationMirror
- An array-valued annotation mirror (meaning it has an
array-typed attribute with name "value").public ConstraintHelper.ConstraintCheckResult checkConstraint(javax.lang.model.type.DeclaredType constraintAnnotationType, javax.lang.model.type.TypeMirror typeOfAnnotatedElement)
constraintAnnotationType
- A constraint annotation type.typeOfAnnotatedElement
- A type which with an element is annotated.public boolean isComposedConstraint(javax.lang.model.element.TypeElement element)
element
- The type element of interest. Must not be null.public ConstraintHelper.AnnotationProcessorValidationTarget resolveValidationTarget(javax.lang.model.element.ExecutableElement element, javax.lang.model.element.AnnotationMirror annotation)
AnnotationProcessorValidationTarget
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.
element
- the method/constructor on which the annotation is appliedannotation
- the constraint annotationAnnotationProcessorValidationTarget
, null if the target cannot be inferredpublic java.util.Set<ConstraintHelper.AnnotationProcessorValidationTarget> getSupportedValidationTargets(javax.lang.model.type.DeclaredType constraintAnnotationType)
AnnotationProcessorValidationTarget
supported by the given constraint annotation type.
A constraint annotation can support ConstraintHelper.AnnotationProcessorValidationTarget.ANNOTATED_ELEMENT
, ConstraintHelper.AnnotationProcessorValidationTarget.PARAMETERS
or both.
constraintAnnotationType
- the constraint annotation typeAnnotationProcessorValidationTarget
spublic ConstraintHelper.ConstraintCheckResult checkCrossParameterTypes(javax.lang.model.type.DeclaredType constraintAnnotationType)
constraintAnnotationType
- the constraint typeConstraintCheckResult#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
otherwisepublic javax.lang.model.util.Types getTypeUtils()
public boolean isSupportedForUnwrappingByDefault(javax.lang.model.element.Name typeName)
public java.util.Optional<javax.lang.model.type.TypeMirror> getUnwrappedToByDefault(javax.lang.model.element.Name typeName)
Copyright © 2007-2022 Red Hat, Inc. All Rights Reserved