Promise<Void> (@NotNull final Project project, @NotNull final Set<? extends Module> modulesWithoutAnnotations, @NotNull String annoFQN, final @NlsContexts.DialogTitle String title) { final Library annotationsLib = LibraryUtil.findLibraryByClass(annoFQN, project); if (annotationsLib != null) { String message = JavaBundle.message("dialog.message.modules.dont.refer.to.existing.annotations.library", modulesWithoutAnnotations.size(), StringUtil.join(modulesWithoutAnnotations, Module::getName, ", "), annotationsLib.getName()); if (createDependencyDialog(title, message, project).ask(project)) { ApplicationManager.getApplication().runWriteAction(() -> { for (Module module : modulesWithoutAnnotations) { ModuleRootModificationUtil.addDependency(module, annotationsLib); } }); return Promises.resolvedPromise(); } return Promises.rejectedPromise(); } String message = JavaBundle.message("dialog.message.jetbrains.annotations.library.is.missing"); if (createDependencyDialog(title, message, project).ask(project)) { Module firstModule = modulesWithoutAnnotations.iterator().next(); return JavaProjectModelModificationService.getInstance(project) .addDependency(modulesWithoutAnnotations, JetBrainsAnnotationsExternalLibraryResolver.getAnnotationsLibraryDescriptor(firstModule), DependencyScope.COMPILE); } return Promises.rejectedPromise(); }