Search in sources :

Example 1 with PsiUtil

use of com.intellij.psi.util.PsiUtil 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)

Example 2 with PsiUtil

use of com.intellij.psi.util.PsiUtil in project intellij-community by JetBrains.

the class JavaAllOverridingMethodsSearcher method execute.

@Override
public boolean execute(@NotNull final AllOverridingMethodsSearch.SearchParameters p, @NotNull final Processor<Pair<PsiMethod, PsiMethod>> consumer) {
    final PsiClass psiClass = p.getPsiClass();
    final List<PsiMethod> potentials = ReadAction.compute(() -> ContainerUtil.filter(psiClass.getMethods(), PsiUtil::canBeOverriden));
    final SearchScope scope = p.getScope();
    Processor<PsiClass> inheritorsProcessor = inheritor -> {
        Project project = psiClass.getProject();
        for (PsiMethod superMethod : potentials) {
            ProgressManager.checkCanceled();
            if (superMethod.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) && !JavaPsiFacade.getInstance(project).arePackagesTheSame(psiClass, inheritor))
                continue;
            PsiMethod inInheritor = JavaOverridingMethodsSearcher.findOverridingMethod(project, inheritor, superMethod, psiClass);
            if (inInheritor != null && !consumer.process(Pair.create(superMethod, inInheritor)))
                return false;
        }
        return true;
    };
    return ClassInheritorsSearch.search(psiClass, scope, true).forEach(inheritorsProcessor);
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) PsiMethod(com.intellij.psi.PsiMethod) QueryExecutor(com.intellij.util.QueryExecutor) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) SearchScope(com.intellij.psi.search.SearchScope) AllOverridingMethodsSearch(com.intellij.psi.search.searches.AllOverridingMethodsSearch) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) PsiModifier(com.intellij.psi.PsiModifier) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) Processor(com.intellij.util.Processor) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) ClassInheritorsSearch(com.intellij.psi.search.searches.ClassInheritorsSearch) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) SearchScope(com.intellij.psi.search.SearchScope)

Aggregations

Project (com.intellij.openapi.project.Project)2 PsiUtil (com.intellij.psi.util.PsiUtil)2 NotNull (org.jetbrains.annotations.NotNull)2 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 ReadAction (com.intellij.openapi.application.ReadAction)1 Module (com.intellij.openapi.module.Module)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1