<commit_before>/*
 * Hibernate Validator, declare and validate application constraints
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
 */
package org.hibernate.validator.ap;

import java.util.List;
import java.util.Set;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementKindVisitor6;
import javax.tools.Diagnostic.Kind;

import org.hibernate.validator.ap.checks.ConstraintCheckError;
import org.hibernate.validator.ap.checks.ConstraintCheckFactory;
import org.hibernate.validator.ap.checks.ConstraintChecks;
import org.hibernate.validator.ap.util.AnnotationApiHelper;
import org.hibernate.validator.ap.util.Configuration;
import org.hibernate.validator.ap.util.ConstraintHelper;
import org.hibernate.validator.ap.util.MessagerAdapter;

/**
 * An {@link javax.lang.model.element.ElementVisitor} that visits annotated elements (type declarations,
 * methods and fields) and applies different {@link org.hibernate.validator.ap.checks.ConstraintCheck}s to them.
 * Each {@link ConstraintCheckError} occurred will be reported using the
 * {@link javax.annotation.processing.Messager} API.
 *
 * @author <NAME>
 */
final class ConstraintAnnotationVisitor extends ElementKindVisitor6<Void, List<AnnotationMirror>> {

	private final MessagerAdapter messager;

	private final ConstraintCheckFactory constraintCheckFactory;

	private final boolean verbose;

	public ConstraintAnnotationVisitor(
			ProcessingEnvironment processingEnvironment, MessagerAdapter messager, Configuration configuration) {

		this.messager = messager;
		this.verbose = configuration.isVerbose();

		AnnotationApiHelper annotationApiHelper = new AnnotationApiHelper(
				processingEnvironment.getElementUtils(), processingEnvironment.getTypeUtils()
		);

		ConstraintHelper constraintHelper = new ConstraintHelper(
				processingEnvironment.getTypeUtils(), annotationApiHelper
		);

		constraintCheckFactory = new ConstraintCheckFactory(
				processingEnvironment.getTypeUtils(),
				constraintHelper,
				annotationApiHelper,
				configuration.methodConstraintsSupported()
		);
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * method. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * Constraint annotations may only be given at non-static, JavaBeans getter
	 * methods which's return type is supported by the constraints.</li>
	 * <li>
	 * The <code>@Valid</code> annotation may only be given at non-static,
	 * non-primitive JavaBeans getter methods.</li>
	 * </ul>
	 */
	@Override
	public Void visitExecutableAsMethod(ExecutableElement method,
										List<AnnotationMirror> mirrors) {

		checkConstraints( method, mirrors );

		return null;
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * field. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * Constraint annotations may only be given at non-static fields which's
	 * type is supported by the constraints.</li>
	 * <li>
	 * The <code>@Valid</code> annotation may only be given at non-static,
	 * non-primitive fields.</li>
	 * </ul>
	 */
	@Override
	public Void visitVariableAsField(VariableElement annotatedField, List<AnnotationMirror> mirrors) {

		checkConstraints( annotatedField, mirrors );

		return null;
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * method parameter. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * Overridden method parameters cannot have wider range of constraints.
	 * </li>
	 * </ul>
	 */
	@Override
	public Void visitVariableAsParameter(VariableElement annotatedField, List<AnnotationMirror> mirrors) {
		checkConstraints( annotatedField, mirrors );
		return null;
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * annotation type declaration. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * The only annotation types allowed to be annotated with other constraint<commit_msg>HV-1119 updated JavaDoc with the checks made on method parameters<commit_after>/*
 * Hibernate Validator, declare and validate application constraints
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
 */
package org.hibernate.validator.ap;

import java.util.List;
import java.util.Set;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementKindVisitor6;
import javax.tools.Diagnostic.Kind;

import org.hibernate.validator.ap.checks.ConstraintCheckError;
import org.hibernate.validator.ap.checks.ConstraintCheckFactory;
import org.hibernate.validator.ap.checks.ConstraintChecks;
import org.hibernate.validator.ap.util.AnnotationApiHelper;
import org.hibernate.validator.ap.util.Configuration;
import org.hibernate.validator.ap.util.ConstraintHelper;
import org.hibernate.validator.ap.util.MessagerAdapter;

/**
 * An {@link javax.lang.model.element.ElementVisitor} that visits annotated elements (type declarations,
 * methods and fields) and applies different {@link org.hibernate.validator.ap.checks.ConstraintCheck}s to them.
 * Each {@link ConstraintCheckError} occurred will be reported using the
 * {@link javax.annotation.processing.Messager} API.
 *
 * @author <NAME>
 */
final class ConstraintAnnotationVisitor extends ElementKindVisitor6<Void, List<AnnotationMirror>> {

	private final MessagerAdapter messager;

	private final ConstraintCheckFactory constraintCheckFactory;

	private final boolean verbose;

	public ConstraintAnnotationVisitor(
			ProcessingEnvironment processingEnvironment, MessagerAdapter messager, Configuration configuration) {

		this.messager = messager;
		this.verbose = configuration.isVerbose();

		AnnotationApiHelper annotationApiHelper = new AnnotationApiHelper(
				processingEnvironment.getElementUtils(), processingEnvironment.getTypeUtils()
		);

		ConstraintHelper constraintHelper = new ConstraintHelper(
				processingEnvironment.getTypeUtils(), annotationApiHelper
		);

		constraintCheckFactory = new ConstraintCheckFactory(
				processingEnvironment.getTypeUtils(),
				constraintHelper,
				annotationApiHelper,
				configuration.methodConstraintsSupported()
		);
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * method. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * Constraint annotations may only be given at non-static, JavaBeans getter
	 * methods which's return type is supported by the constraints.</li>
	 * <li>
	 * The <code>@Valid</code> annotation may only be given at non-static,
	 * non-primitive JavaBeans getter methods.</li>
	 * </ul>
	 */
	@Override
	public Void visitExecutableAsMethod(ExecutableElement method,
										List<AnnotationMirror> mirrors) {

		checkConstraints( method, mirrors );

		return null;
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * field. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * Constraint annotations may only be given at non-static fields which's
	 * type is supported by the constraints.</li>
	 * <li>
	 * The <code>@Valid</code> annotation may only be given at non-static,
	 * non-primitive fields.</li>
	 * </ul>
	 */
	@Override
	public Void visitVariableAsField(VariableElement annotatedField, List<AnnotationMirror> mirrors) {

		checkConstraints( annotatedField, mirrors );

		return null;
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * method parameter. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * Constraint annotation parameter values are meaningful and valid.
	 * </li>
	 * </ul>
	 */
	@Override
	public Void visitVariableAsParameter(VariableElement annotatedField, List<AnnotationMirror> mirrors) {
		checkConstraints( annotatedField, mirrors );
		return null;
	}

	/**
	 * <p>
	 * Checks whether the given annotations are correctly specified at the given
	 * annotation type declaration. The following checks are performed:
	 * </p>
	 * <ul>
	 * <li>
	 * The only annotation types allowed to be annotated with other constraint
{'fraction_non_alphanumeric': 0.09407625964593735, 'fraction_numerical': 0.0018157058556513845, 'mean_word_length': 4.656611039794608, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1469280', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2277, 'n_words': 706}