void (@NotNull PsiElement callElement, @NotNull Editor editor, @NotNull Consumer<? super Pair<SimpleMatch, PsiElement>> replacer, @NotNull List<? extends SimpleMatch> duplicates) { if (!duplicates.isEmpty()) { final String message = RefactoringBundle .message("0.has.detected.1.code.fragments.in.this.file.that.can.be.replaced.with.a.call.to.extracted.method", ApplicationNamesInfo.getInstance().getProductName(), duplicates.size()); final boolean isUnittest = ApplicationManager.getApplication().isUnitTestMode(); boolean isPerformanceScript = System.getProperty("testscript.filename") != null; final Project project = callElement.getProject(); final boolean exitCode = isUnittest || isPerformanceScript || MessageDialogBuilder.yesNo(RefactoringBundle.message("refactoring.extract.method.dialog.title"), message, UIUtil.getInformationIcon()).ask(project); if (exitCode) { boolean replaceAll = false; final Map<SimpleMatch, RangeHighlighter> highlighterMap = new HashMap<>(); for (SimpleMatch match : duplicates) { if (!match.getStartElement().isValid() || !match.getEndElement().isValid()) continue; final Pair<SimpleMatch, PsiElement> replacement = Pair.create(match, callElement); if (!replaceAll) { highlightInEditor(project, match, editor, highlighterMap); int promptResult = FindManager.PromptResult.ALL; if (!isUnittest && !isPerformanceScript) { promptResult = RefactoringUiService.getInstance().showReplacePromptDialog(false, RefactoringBundle.message("replace.fragment"), project); } 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(project, replacer, replacement); } else if (promptResult == FindManager.PromptResult.ALL) { replaceDuplicate(project, replacer, replacement); replaceAll = true; } } else { replaceDuplicate(project, replacer, replacement); } } } } }