void (@NotNull final Collection<UsageInfo> usageInfoSet) { for (Iterator<UsageInfo> iterator = usageInfoSet.iterator(); iterator.hasNext();) { UsageInfo usageInfo = iterator.next(); final PsiElement element = usageInfo.getElement(); if (element == null || !isToBeChanged(usageInfo)) { iterator.remove(); } } String commandName = getCommandName(); LocalHistoryAction action = LocalHistory.getInstance().startAction(commandName); final UsageInfo[] writableUsageInfos = usageInfoSet.toArray(UsageInfo.EMPTY_ARRAY); final String refactoringId = getRefactoringId(); try { if (refactoringId != null) { RefactoringEventData data = getBeforeData(); if (data != null) { data.addUsages(Arrays.asList(writableUsageInfos)); } myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, data); } PsiDocumentManager.getInstance(myProject).commitAllDocuments(); RefactoringListenerManagerImpl listenerManager = (RefactoringListenerManagerImpl)RefactoringListenerManager.getInstance(myProject); myTransaction = listenerManager.startTransaction(); final Map<RefactoringHelper, Object> preparedData = new LinkedHashMap<>(); final Runnable prepareHelpersRunnable = () -> { RefactoringEventData data = ReadAction.compute(() -> getBeforeData()); PsiElement primaryElement = data != null ? data.getUserData(RefactoringEventData.PSI_ELEMENT_KEY) : null; for (final RefactoringHelper helper : RefactoringHelper.EP_NAME.getExtensionList()) { Object operation = ReadAction.compute(() -> primaryElement != null ? helper.prepareOperation(writableUsageInfos, primaryElement) : helper.prepareOperation(writableUsageInfos)); preparedData.put(helper, operation); } }; ProgressManager.getInstance().runProcessWithProgressSynchronously(prepareHelpersRunnable, RefactoringBundle.message("refactoring.prepare.progress"), false, myProject); if (refactoringId != null) { UndoManager.getInstance(myProject).undoableActionPerformed(new UndoRefactoringAction(myProject, refactoringId)); } ApplicationEx app = ApplicationManagerEx.getApplicationEx(); if (Registry.is("run.refactorings.under.progress")) { app.runWriteActionWithNonCancellableProgressInDispatchThread(commandName, myProject, null, indicator -> performRefactoring(writableUsageInfos)); } else { app.runWriteAction(() -> performRefactoring(writableUsageInfos)); } DumbService.getInstance(myProject).completeJustSubmittedTasks(); for(Map.Entry<RefactoringHelper, Object> e: preparedData.entrySet()) { //noinspection unchecked e.getKey().performOperation(myProject, e.getValue()); } myTransaction.commit(); if (Registry.is("run.refactorings.under.progress")) { app.runWriteActionWithNonCancellableProgressInDispatchThread(commandName, myProject, null, indicator -> performPsiSpoilingRefactoring()); } else { app.runWriteAction(this::performPsiSpoilingRefactoring); } } finally { if (refactoringId != null) { myProject.getMessageBus() .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, getAfterData(writableUsageInfos)); } action.finish(); myUsageView = null; } int count = writableUsageInfos.length; if (count > 0) { RefactoringUiService.getInstance().setStatusBarInfo(myProject, RefactoringBundle.message("statusBar.refactoring.result", count)); } else { if (!isPreviewUsages(writableUsageInfos)) { RefactoringUiService.getInstance().setStatusBarInfo(myProject, RefactoringBundle.message("statusBar.noUsages")); } } }