boolean () { final boolean replaceAllOccurrences = isReplaceAllOccurrences(); final Ref<Boolean> result = new Ref<>(false); CommandProcessor.getInstance().executeCommand(myProject, () -> { final String[] names = suggestNames(replaceAllOccurrences, getLocalVariable()); boolean started = false; try (AccessToken ignore = SlowOperations.allowSlowOperations(SlowOperations.ACTION_PERFORM)) { if (replaceAllOccurrences) { int segmentsLimit = Registry.intValue("inplace.rename.segments.limit", -1); // Too many occurrences: rename template won't start, see InplaceRefactoring.buildTemplateAndStart // 2 = variable type + variable name if (segmentsLimit != -1 && getOccurrences().length + 2 > segmentsLimit) return; } final V variable = createFieldToStartTemplateOn(replaceAllOccurrences, names); if (variable != null) { int caretOffset = getCaretOffset(); myEditor.getCaretModel().moveToOffset(caretOffset); myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<>(); nameSuggestions.add(variable.getName()); nameSuggestions.addAll(Arrays.asList(names)); initOccurrencesMarkers(); setElementToRename(variable); updateTitle(getVariable()); started = super.performInplaceRefactoring(nameSuggestions); if (started) { myDocumentAdapter = new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent e) { if (myPreview == null) return; final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); if (templateState != null) { final TextResult value = templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME); if (value != null) { updateTitle(getVariable(), value.getText()); } } } }; myEditor.getDocument().addDocumentListener(myDocumentAdapter); updateTitle(getVariable()); if (TemplateManagerImpl.getTemplateState(myEditor) != null) { myEditor.putUserData(ACTIVE_INTRODUCE, this); } } } result.set(started); } finally { if (!started) { finish(true); } } }, getCommandName(), getCommandName()); return result.get(); }