@Override
  public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    InjectedLanguageManager manager = InjectedLanguageManager.getInstance(project);
    PsiFile topLevelFile = manager.getTopLevelFile(file);
    Editor topLevelEditor = InjectedLanguageEditorUtil.getTopLevelEditor(editor);
    // IntentionAction, offset
    List<Pair<IntentionAction, SmartPsiFileRange>> actions = new ArrayList<>();
    Document document = topLevelFile.getFileDocument();
    Processor<HighlightInfo> processor = info -> {
      IntentionAction fix = info.getSameFamilyFix(myAction);
      if (fix != null) {
        TextRange range = TextRange.create(info.getActualStartOffset(), info.getActualEndOffset());
        SmartPsiFileRange pointer = SmartPointerManager.getInstance(project)
          .createSmartPsiFileRangePointer(topLevelFile, range);
        actions.add(Pair.create(fix, pointer));
      }
      return true;
    };
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
      ReadAction.run(() -> {
        DaemonCodeAnalyzerEx.processHighlights(
          document, project, null, 0, document.getTextLength(), processor);
      });
    }, AnalysisBundle.message("command.name.gather.fixes"), true, project)) return;

    if (actions.isEmpty() || !FileModificationService.getInstance().preparePsiElementForWrite(file)) return;
    // Applying in reverse order looks safer
    Collections.reverse(actions);

    List<Pair<ModCommandAction, SmartPsiFileRange>> modCommands =
      ContainerUtil.map(actions, pair -> Pair.create(pair.first.asModCommandAction(), pair.second));
    PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
    String actionName = myAction.getFamilyName();
    if (ContainerUtil.all(modCommands, pair -> pair.first != null)) {
      runModCommands(topLevelEditor, topLevelFile, actionName, modCommands);
    }
    else {
      ApplicationManagerEx.getApplicationEx()
        .runWriteActionWithCancellableProgressInDispatchThread(actionName, project, null, indicator -> {
          indicator.setIndeterminate(false);
          for (int i = 0; i < actions.size(); i++) {
            indicator.setFraction((double)i / actions.size());
            Pair<IntentionAction, SmartPsiFileRange> pair = actions.get(i);
            IntentionAction action = pair.getFirst();
            // Some actions rely on the caret position
            Segment range = pair.getSecond().getRange();
            if (range != null) {
              topLevelEditor.getCaretModel().moveToOffset(range.getStartOffset());
              if (action.isAvailable(project, editor, file)) {
                action.invoke(project, editor, file);
                psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
                psiDocumentManager.commitDocument(document);
              }
            }
          }
        });
    }
  }
@Override
  public void invoke(@NotNull Project project, Editor editor, PsiFile file)