Class ConstraintHelper

java.lang.Object
org.hibernate.validator.ap.internal.util.ConstraintHelper

public class ConstraintHelper extends Object
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
  • Constructor Details

  • Method Details

    • isConstraintAnnotation

      public boolean isConstraintAnnotation(Element element)
      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

      public ConstraintHelper.AnnotationType getAnnotationType(AnnotationMirror annotationMirror)
      Returns the ConstraintHelper.AnnotationType of the given annotation.
      Parameters:
      annotationMirror - The annotation mirror of interest.
      Returns:
      The given mirror's annotation type.
    • getPartsOfMultiValuedConstraint

      public List<AnnotationMirror> getPartsOfMultiValuedConstraint(AnnotationMirror annotationMirror)
      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

      public boolean isComposedConstraint(TypeElement element)
      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 actual AnnotationProcessorValidationTarget of 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 applied
      annotation - 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 of AnnotationProcessorValidationTarget 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 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_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

      public Types getTypeUtils()
    • isSupportedForUnwrappingByDefault

      public boolean isSupportedForUnwrappingByDefault(Name typeName)
    • getUnwrappedToByDefault

      public Optional<TypeMirror> getUnwrappedToByDefault(Name typeName)