boolean (@NotNull ActionContext context, @NotNull ModUpdateReferences decl, @Nullable Editor editor) { // TODO: properly support multiple tracked declarations VirtualFile file = decl.file(); Project project = context.project(); Callable<SuggestedRefactoringState> computeNewState = () -> { PsiFile psiFile = PsiManagerEx.getInstanceEx(project).findFile(file); if (psiFile == null) return null; SuggestedRefactoringSupport support = SuggestedRefactoringSupport.Companion.forLanguage(psiFile.getLanguage()); if (support == null) return null; PsiElement newElement = findElementAtRange(psiFile, decl.newRange()); if (newElement == null || !support.isAnchor(newElement)) return null; SuggestedRefactoringStateChanges stateChanges = support.getStateChanges(); PsiFile fileCopy = (PsiFile)psiFile.copy(); Document documentCopy = fileCopy.getViewProvider().getDocument(); documentCopy.replaceString(0, documentCopy.getTextLength(), decl.oldText()); PsiDocumentManager.getInstance(project).commitDocument(documentCopy); PsiElement element = findElementAtRange(fileCopy, decl.oldRange()); if (element == null) return null; if (!support.isAnchor(element) || stateChanges.findDeclaration(element) != element) return null; SuggestedRefactoringState state = stateChanges.createInitialState(element); if (state == null) return null; SuggestedRefactoringAvailability availability = support.getAvailability(); SuggestedRefactoringState newState = stateChanges.updateState(state, newElement); if (newState.getErrorLevel() != SuggestedRefactoringState.ErrorLevel.NO_ERRORS) return null; if (availability.detectAvailableRefactoring(newState) != null && availability.isAvailable(newState)) return newState; return null; }; SuggestedRefactoringState finalState = ProgressManager.getInstance().runProcessWithProgressSynchronously( () -> ReadAction.nonBlocking(computeNewState).executeSynchronously(), LangBundle.message("dialog.title.searching.for.usages"), true, project); if (finalState == null) return false; Editor finalEditor = getEditor(project, editor, decl.file()); if (finalEditor == null) return false; PerformSuggestedRefactoringKt.performSuggestedRefactoring( finalState, finalEditor, project, ActionPlaces.INTENTION_MENU, true, null, null); return true; }