void (String newName, StartMarkAction markAction) { final String refactoringId = getRefactoringId(); try { PsiNamedElement elementToRename = getVariable(); if (!isIdentifier(newName, myLanguage)) { return; } if (elementToRename != null) { WriteCommandAction.writeCommandAction(myProject).withName(getCommandName()).run(() -> renameSynthetic(newName)); } for (AutomaticRenamerFactory renamerFactory : AutomaticRenamerFactory.EP_NAME.getExtensionList()) { if (elementToRename != null && isRenamerFactoryApplicable(renamerFactory, elementToRename)) { final List<UsageInfo> usages = new ArrayList<>(); final AutomaticRenamer renamer = renamerFactory.createRenamer(elementToRename, newName, new ArrayList<>()); if (renamer.hasAnythingToRename()) { if (!ApplicationManager.getApplication().isUnitTestMode()) { final AutomaticRenamingDialog renamingDialog = new AutomaticRenamingDialog(myProject, renamer); if (!renamingDialog.showAndGet()) { continue; } } final Runnable runnable = () -> ApplicationManager.getApplication().runReadAction(() -> renamer.findUsages(usages, false, false)); if (!ProgressManager.getInstance() .runProcessWithProgressSynchronously(runnable, RefactoringBundle.message("searching.for.variables"), true, myProject)) { return; } if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, PsiUtilCore.toPsiElementArray(renamer.getElements()))) return; final ThrowableRunnable<RuntimeException> performAutomaticRename = () -> { CommandProcessor.getInstance().markCurrentCommandAsGlobal(myProject); MultiMap<PsiElement, UsageInfo> classified = RenameProcessor.classifyUsages(renamer.getElements(), usages); for (final PsiNamedElement element : renamer.getElements()) { final String newElementName = renamer.getNewName(element); if (newElementName != null) { final Collection<UsageInfo> infos = classified.get(element); RenameUtil.doRename(element, newElementName, infos.toArray(UsageInfo.EMPTY_ARRAY), myProject, RefactoringElementListener.DEAF); } } }; if (ApplicationManager.getApplication().isUnitTestMode()) { WriteCommandAction.writeCommandAction(myProject).withName(getCommandName()).run(performAutomaticRename); } else { ApplicationManager.getApplication().invokeLater(() -> WriteCommandAction.writeCommandAction(myProject).withName(getCommandName()).run(performAutomaticRename)); } } } } } finally { if (mySuggestedNameInfo != null) mySuggestedNameInfo.nameChosen(newName); if (refactoringId != null) { final RefactoringEventData afterData = new RefactoringEventData(); afterData.addElement(getVariable()); afterData.addStringProperties(newName); myProject.getMessageBus() .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, afterData); } try { stopDumbLaterIfPossible(); } finally { FinishMarkAction.finish(myProject, myEditor, markAction); } } }