Runnable (final Project project, final Computable<UsageInfo[]> computable) { return () -> { final LocalHistoryAction action = LocalHistory.getInstance().startAction( JavaBundle.message("action.description.infer.nullity.annotations")); try { ReadAction.run(() -> { final UsageInfo[] infos = computable.compute(); if (infos.length > 0) { Runnable command = () -> { final Set<VirtualFile> files = StreamEx.of(infos).map(UsageInfo::getElement).nonNull() .map(PsiElement::getContainingFile).nonNull() .map(PsiFile::getVirtualFile).nonNull() .toCollection(LinkedHashSet::new); if (!FileModificationService.getInstance().prepareVirtualFilesForWrite(project, files)) return; final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, JavaBundle .message("action.title.infer.nullity.annotations")); progressTask.setMinIterationTime(200); progressTask.setTask(new AnnotateTask(project, progressTask, infos)); ProgressManager.getInstance().run(progressTask); }; CommandProcessor.getInstance() .executeCommand(project, command, JavaBundle.message("action.title.infer.nullity.annotations"), null); NOTIFICATION_GROUP.createNotification(JavaBundle.message("notification.content.added.annotations", infos.length), NotificationType.INFORMATION) .notify(project); } else { NullityInferrer.nothingFoundMessage(project); } }); } finally { action.finish(); } }; }