@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new JavaElementVisitor() {

      @Override
      public void visitIfStatement(@NotNull PsiIfStatement statement) {
        ConditionalModel model = IfConditionalModel.from(statement, false);
        if (model == null) return;
        visitConditional(statement.getFirstChild(), model);
      }

      @Override
      public void visitConditionalExpression(@NotNull PsiConditionalExpression expression) {
        ConditionalModel model = ConditionalModel.from(expression);
        if (model == null) return;
        visitConditional(expression, model);
      }

      private void visitConditional(@NotNull PsiElement element,
                                    @NotNull ConditionalModel model) {
        PsiBinaryExpression condition = getCondition(model.getCondition());
        if (condition == null) return;
        PsiExpression left = condition.getLOperand();
        if (SideEffectChecker.mayHaveSideEffects(left, e -> e instanceof PsiMethodCallExpression)) return;
        PsiType leftType = getType(left);
        if (leftType == null) return;
        PsiExpression right = condition.getROperand();
        if (right == null || SideEffectChecker.mayHaveSideEffects(right, e -> e instanceof PsiMethodCallExpression)) return;
        PsiType rightType = getType(right);
        if (rightType == null || leftType != rightType) return;
        EquivalenceChecker equivalenceChecker = EquivalenceChecker.getCanonicalPsiEquivalence();
        boolean useMathMin = equivalenceChecker.expressionsAreEquivalent(left, model.getElseExpression());
        if (!useMathMin && !equivalenceChecker.expressionsAreEquivalent(left, model.getThenExpression())) return;
        if (!equivalenceChecker.expressionsAreEquivalent(right, useMathMin ? model.getThenExpression() : model.getElseExpression())) return;
        IElementType tokenType = condition.getOperationTokenType();
        useMathMin ^= JavaTokenType.LT.equals(tokenType) || JavaTokenType.LE.equals(tokenType);
        PsiClass containingClass = PsiUtil.getContainingClass(element);
        if (containingClass != null && CommonClassNames.JAVA_LANG_MATH.equals(containingClass.getQualifiedName())) return;
        holder.registerProblem(element,
                               JavaBundle.message("inspection.manual.min.max.calculation.description", useMathMin ? "min" : "max"),
                               new ReplaceWithMinMaxFix(useMathMin));
      }

      @Nullable
      private PsiType getType(@NotNull PsiExpression expression) {
        PsiType type = expression.getType();
        if (type == null) return null;
        int rank = TypeConversionUtil.getTypeRank(type);
        if (rank < TypeConversionUtil.INT_RANK || rank > TypeConversionUtil.DOUBLE_RANK) return null;
        return !disableForNonIntegralTypes || rank <= TypeConversionUtil.LONG_RANK ? type : null;
      }
    };
  }
@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly)