public static void processDuplicates(@NotNull final PsiElement callElement,
                                       @NotNull final PsiElement generatedMethod,
                                       final @NotNull List<? extends PsiElement> scope,
                                       @NotNull final SimpleDuplicatesFinder finder,
                                       @NotNull final Editor editor,
                                       @NotNull final Consumer<? super Pair<SimpleMatch, PsiElement>> replacer) {
    finder.setReplacement(callElement);
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      replaceDuplicates(callElement, editor, replacer, finder.findDuplicates(scope, generatedMethod));
      return;
    }
    final Project project = callElement.getProject();
    ProgressManager.getInstance().run(new Task.Backgroundable(project, RefactoringBundle.message("searching.for.duplicates"), true) {
      @Override
      public void run(@NotNull ProgressIndicator indicator) {
        if (myProject == null || myProject.isDisposed()) return;
        final List<SimpleMatch> duplicates = ReadAction.compute(() -> finder.findDuplicates(scope, generatedMethod));

        ApplicationManager.getApplication().invokeLater(() -> replaceDuplicates(callElement, editor, replacer, duplicates));
      }
    });
  }
public static void processDuplicates(@NotNull final PsiElement callElement,
                                       @NotNull final PsiElement generatedMethod,
                                       final @NotNull List<? extends PsiElement> scope,
                                       @NotNull final SimpleDuplicatesFinder finder,
                                       @NotNull final Editor editor,
                                       @NotNull final Consumer<? super Pair<SimpleMatch, PsiElement>> replacer)