private void reformatText(@NotNull PsiFile file,
                            @NotNull FormatTextRanges ranges, BiFunction<FormatTextRanges, PsiFile, Boolean> isFullRange)
    throws IncorrectOperationException
  {
    if (ranges.isEmpty()) {
      return;
    }
    ensureDocumentCommitted(file);

    CheckUtil.checkWritable(file);
    if (!SourceTreeToPsiMap.hasTreeElement(file)) {
      return;
    }

    ASTNode treeElement = SourceTreeToPsiMap.psiElementToTree(file);
    transformAllChildren(treeElement);

    LOG.assertTrue(file.isValid(), "File name: " + file.getName() + " , class: " + file.getClass().getSimpleName());

    myProject.getMessageBus().syncPublisher(Listener.TOPIC).beforeReformatText(file);

    try {
      if (FormatterUtil.isFormatterCalledExplicitly()) {
        removeEndingWhiteSpaceFromEachRange(file, ranges);
      }

      FormattingServiceUtil.formatRanges(file, ranges, false, isFullRange.apply(ranges, file));
    }
    finally {
      myProject.getMessageBus().syncPublisher(Listener.TOPIC).afterReformatText(file);
    }
  }
private void reformatText(@NotNull PsiFile file,
                            @NotNull FormatTextRanges ranges, BiFunction<FormatTextRanges, PsiFile, Boolean> isFullRange)