Search in sources :

Example 1 with ModuleUtilCore

use of com.intellij.openapi.module.ModuleUtilCore in project intellij-community by JetBrains.

the class CreateModuleInfoAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    DataContext ctx = e.getDataContext();
    boolean available = Optional.ofNullable(LangDataKeys.IDE_VIEW.getData(ctx)).map(view -> getTargetDirectory(ctx, view)).filter(PsiUtil::isLanguageLevel9OrHigher).map(ModuleUtilCore::findModuleForPsiElement).map(module -> FilenameIndex.getVirtualFilesByName(module.getProject(), MODULE_INFO_FILE, module.getModuleScope(false)).isEmpty()).orElse(false);
    e.getPresentation().setEnabledAndVisible(available);
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) AllIcons(com.intellij.icons.AllIcons) DataContext(com.intellij.openapi.actionSystem.DataContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FilenameIndex(com.intellij.psi.search.FilenameIndex) IdeView(com.intellij.ide.IdeView) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) PsiUtil(com.intellij.psi.util.PsiUtil) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) INTERNAL_MODULE_INFO_TEMPLATE_NAME(com.intellij.ide.fileTemplates.JavaTemplateUtil.INTERNAL_MODULE_INFO_TEMPLATE_NAME) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) AttributesDefaults(com.intellij.ide.fileTemplates.actions.AttributesDefaults) MODULE_INFO_FILE(com.intellij.psi.PsiJavaModule.MODULE_INFO_FILE) IdeBundle(com.intellij.ide.IdeBundle) LightJavaModule(com.intellij.psi.impl.light.LightJavaModule) Nullable(org.jetbrains.annotations.Nullable) CreateFromTemplateActionBase(com.intellij.ide.fileTemplates.actions.CreateFromTemplateActionBase) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Optional(java.util.Optional) PsiDirectory(com.intellij.psi.PsiDirectory) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) NotNull(org.jetbrains.annotations.NotNull) MODULE_INFO_CLASS(com.intellij.psi.PsiJavaModule.MODULE_INFO_CLASS) Collections(java.util.Collections) DataContext(com.intellij.openapi.actionSystem.DataContext) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore)

Aggregations

AllIcons (com.intellij.icons.AllIcons)1 IdeBundle (com.intellij.ide.IdeBundle)1 IdeView (com.intellij.ide.IdeView)1 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)1 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)1 INTERNAL_MODULE_INFO_TEMPLATE_NAME (com.intellij.ide.fileTemplates.JavaTemplateUtil.INTERNAL_MODULE_INFO_TEMPLATE_NAME)1 AttributesDefaults (com.intellij.ide.fileTemplates.actions.AttributesDefaults)1 CreateFromTemplateActionBase (com.intellij.ide.fileTemplates.actions.CreateFromTemplateActionBase)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 LangDataKeys (com.intellij.openapi.actionSystem.LangDataKeys)1 Module (com.intellij.openapi.module.Module)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 Project (com.intellij.openapi.project.Project)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFile (com.intellij.psi.PsiFile)1 MODULE_INFO_CLASS (com.intellij.psi.PsiJavaModule.MODULE_INFO_CLASS)1