@Override
  public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new JavaElementVisitor() {
      @Override
      public void visitMethod(@NotNull PsiMethod method) {
        PsiClass aClass = method.getContainingClass();
        if (aClass == null || !aClass.isRecord()) return;
        if (JavaPsiRecordUtil.isCompactConstructor(method)) {
          checkCompact(method);
        }
        else {
          checkCanonical(method);
        }
      }

      private void checkCanonical(PsiMethod ctor) {
        ConstructorSimplifier simplifier = createCtorSimplifier(ctor);
        if (simplifier instanceof RemoveRedundantCtorSimplifier) {
          PsiIdentifier nameIdentifier = ctor.getNameIdentifier();
          if (nameIdentifier == null) return;
          holder.registerProblem(nameIdentifier, JavaBundle.message("inspection.redundant.record.constructor.canonical.message"),
                                 ProblemHighlightType.GENERIC_ERROR_OR_WARNING, simplifier);
        }
        else if (simplifier instanceof MakeCtorCompactSimplifier) {
          holder.registerProblem(ctor.getParameterList(),
                                 JavaBundle.message("inspection.redundant.record.constructor.can.be.compact.message"),
                                 ProblemHighlightType.GENERIC_ERROR_OR_WARNING, simplifier);
        }
      }

      private void checkCompact(PsiMethod ctor) {
        PsiCodeBlock body = ctor.getBody();
        if (body == null) return;
        PsiIdentifier ctorNameIdentifier = ctor.getNameIdentifier();
        if (ctorNameIdentifier == null) return;
        PsiStatement[] statements = body.getStatements();
        if (statements.length > 0) {
          PsiParameter[] parameters = ctor.getParameterList().getParameters();
          PsiRecordComponent[] components = Objects.requireNonNull(ctor.getContainingClass()).getRecordComponents();
          int count = getAssignedComponentsCount(components, parameters, statements);
          if (count < statements.length) {
            for (int i = statements.length - count; i < statements.length; i++) {
              holder.problem(statements[i], JavaBundle.message("inspection.redundant.record.constructor.statement.message"))
                .fix(new DeleteElementFix(statements[i])).register();
            }
            return;
          }
        }
        if (ctor.getModifierList().getAnnotations().length == 0 &&
            ctor.getDocComment() == null) {
          holder.registerProblem(ctorNameIdentifier,
                                 JavaBundle.message("inspection.redundant.record.constructor.compact.message"),
                                 ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new RemoveRedundantCtorSimplifier());
        }
      }
    };
  }
@Override
  public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly)