@Override
  @NotNull
  protected FutureTask<Boolean> prepareTask(@NotNull final PsiFile file, final boolean processChangedTextOnly)
    throws IncorrectOperationException
  {
    Pair<PsiFile, Runnable> fileToFormatAndCommitActionIfNeed = ReadAction.compute(() -> {
      PsiFile psiFile = ensureValid(file);
      if (psiFile != null) {
        PsiDocumentManager instance = PsiDocumentManager.getInstance(myProject);
        Document document = instance.getDocument(psiFile);
        if (document != null) {
          return Pair.create(psiFile, () -> instance.commitDocument(document));
        }
      }
      return Pair.create(psiFile, null);
    });

    PsiFile fileToProcess = fileToFormatAndCommitActionIfNeed.first;
    if (fileToProcess == null) {
      return new FutureTask<>(() -> false);
    }

    Computable<List<TextRange>> prepareRangesForFormat = () -> {
      List<TextRange> formattingRanges = getRangesToFormat(file, processChangedTextOnly);
      CodeFormattingData.prepare(fileToProcess, formattingRanges);
      return formattingRanges;
    };

    Ref<List<TextRange>> rangesForFormat = Ref.create();
    final Runnable commitAction = fileToFormatAndCommitActionIfNeed.second;
    if (commitAction == null) {
      rangesForFormat.set(ReadAction.compute(() -> prepareRangesForFormat.compute()));
    }

    boolean doNotKeepLineBreaks = confirmSecondReformat(file);
    return new FutureTask<>(() -> {
      Ref<Boolean> result = new Ref<>();
      CodeStyle.runWithLocalSettings(myProject, CodeStyle.getSettings(fileToProcess), (settings) -> {
        if (doNotKeepLineBreaks) {
          settings.getCommonSettings(fileToProcess.getLanguage()).KEEP_LINE_BREAKS = false;
        }
        if (commitAction != null) {
          commitAction.run();
          rangesForFormat.set(prepareRangesForFormat.compute());
        }
        result.set(doReformat(file, rangesForFormat.get(), processChangedTextOnly));
      });
      return result.get();
    });
  }
@Override
  @NotNull
  protected FutureTask<Boolean> prepareTask(@NotNull final PsiFile file, final boolean processChangedTextOnly)