@SuppressWarnings("Duplicates")
  public static void replaceDuplicates(@NotNull PsiElement file,
                                       @NotNull Editor editor,
                                       @NotNull List<SmartPsiElementPointer<PsiElement>> duplicates,
                                       @NotNull String referenceText,
                                       boolean showWarning) {

    String warningMessage = "";
    if (showWarning) {
      warningMessage = "\n\n" + MarkdownBundle.message("markdown.extract.link.extract.duplicates.warning");
    }
    final String message =
      MarkdownBundle.message("markdown.extract.link.extract.duplicates.description", ApplicationNamesInfo.getInstance().getProductName(),
                             duplicates.size()) + warningMessage;
    final boolean isUnittest = ApplicationManager.getApplication().isUnitTestMode();
    final Project project = file.getProject();
    final int exitCode =
      !isUnittest ? Messages.showYesNoDialog(project, message, MarkdownBundle.message("markdown.extract.link.refactoring.dialog.title"),
                                             Messages.getInformationIcon()) : Messages.YES;

    if (exitCode == Messages.YES) {
      boolean replaceAll = false;
      final Map<PsiElement, RangeHighlighter> highlighterMap = new HashMap<>();
      for (SmartPsiElementPointer<PsiElement> smartPsiElementPointer : duplicates) {
        PsiElement match = smartPsiElementPointer.getElement();
        if (match == null) {
          continue;
        }

        if (!match.isValid()) continue;

        if (!replaceAll) {
          highlightInEditor(project, editor, highlighterMap, match);

          int promptResult = FindManager.PromptResult.ALL;
          if (!isUnittest) {
            ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, MarkdownBundle.message(
              "markdown.extract.link.extract.link.replace"), project);
            promptDialog.show();
            promptResult = promptDialog.getExitCode();
          }
          if (promptResult == FindManager.PromptResult.SKIP) {
            final HighlightManager highlightManager = HighlightManager.getInstance(project);
            final RangeHighlighter highlighter = highlighterMap.get(match);
            if (highlighter != null) highlightManager.removeSegmentHighlighter(editor, highlighter);
            continue;
          }

          if (promptResult == FindManager.PromptResult.CANCEL) break;

          if (promptResult == FindManager.PromptResult.OK) {
            replaceDuplicate(match, referenceText);
          }
          else if (promptResult == FindManager.PromptResult.ALL) {
            replaceDuplicate(match, referenceText);
            replaceAll = true;
          }
        }
        else {
          replaceDuplicate(match, referenceText);
        }
      }
    }
  }
@SuppressWarnings("Duplicates")
  public static void replaceDuplicates(@NotNull PsiElement file,
                                       @NotNull Editor editor,
                                       @NotNull List<SmartPsiElementPointer<PsiElement>> duplicates,
                                       @NotNull String referenceText,
                                       boolean showWarning)