void () { if (!PsiDocumentManager.getInstance(myProject).commitAllDocumentsUnderProgress()) { return; } final Ref<UsageInfo[]> refUsages = new Ref<>(); final Ref<Language> refErrorLanguage = new Ref<>(); final Ref<Boolean> refProcessCanceled = new Ref<>(); final Ref<Boolean> anyException = new Ref<>(); final Ref<Boolean> indexNotReadyException = new Ref<>(); DumbService.getInstance(myProject).completeJustSubmittedTasks(); final Runnable findUsagesRunnable = () -> { try { refUsages.set(ReadAction.compute(this::findUsages)); } catch (UnknownReferenceTypeException e) { refErrorLanguage.set(e.getElementLanguage()); } catch (ProcessCanceledException e) { refProcessCanceled.set(Boolean.TRUE); } catch (IndexNotReadyException e) { indexNotReadyException.set(Boolean.TRUE); } catch (Throwable e) { anyException.set(Boolean.TRUE); LOG.error(e); } }; long findUsagesStart = System.currentTimeMillis(); boolean isProgressFinished = ProgressManager.getInstance() .runProcessWithProgressSynchronously(findUsagesRunnable, RefactoringBundle.message("progress.text"), true, myProject); long findUsagesDuration = System.currentTimeMillis() - findUsagesStart; RefactoringUsageCollector.USAGES_SEARCHED.log(this.getClass(), !isProgressFinished, findUsagesDuration); if (!isProgressFinished) { return; } if (!refErrorLanguage.isNull()) { MessagesService.getInstance().showErrorDialog(myProject, RefactoringBundle.message("unsupported.refs.found", refErrorLanguage.get().getDisplayName()), RefactoringBundle.message("error.title")); return; } if (!indexNotReadyException.isNull() || DumbService.isDumb(myProject)) { DumbService.getInstance(myProject).showDumbModeNotificationForFunctionality(RefactoringBundle.message("refactoring.dumb.mode.notification"), DumbModeBlockedFunctionality.Refactoring); return; } if (!refProcessCanceled.isNull()) { MessagesService.getInstance().showErrorDialog(myProject, RefactoringBundle.message("refactoring.index.corruption.notifiction"), RefactoringBundle.message("error.title")); return; } if (!anyException.isNull()) { //do not proceed if find usages fails return; } assert !refUsages.isNull(): "Null usages from processor " + this; if (!preprocessUsages(refUsages)) return; final UsageInfo[] usages = refUsages.get(); assert usages != null; UsageViewDescriptor descriptor = createUsageViewDescriptor(usages); boolean isPreview = isPreviewUsages(usages) || !computeUnloadedModulesFromUseScope(descriptor).isEmpty(); if (!isPreview) { isPreview = !ensureElementsWritable(usages, descriptor) || UsageViewUtil.hasReadOnlyUsages(usages); if (isPreview) { RefactoringUiService.getInstance().setStatusBarInfo(myProject, RefactoringBundle.message("readonly.occurences.found")); } } long executeStart = System.currentTimeMillis(); if (isPreview) { for (UsageInfo usage : usages) { LOG.assertTrue(usage != null, getClass()); } previewRefactoring(usages); } else { execute(usages); } long executeDuration = System.currentTimeMillis() - executeStart; RefactoringUsageCollector.EXECUTED.log(this.getClass(), executeDuration); }