Search in sources :

Example 26 with PsiPackage

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

the class PsiPackageFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null)
        return null;
    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context);
    if (elements == null) {
        final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
        if (element != null) {
            elements = new PsiElement[] { element };
        }
    }
    final Collection<AbstractTreeNode> result = new ArrayList<>();
    if (elements != null) {
        for (PsiElement element : elements) {
            if (element instanceof PsiPackage) {
                final PsiPackage psiPackage = (PsiPackage) element;
                final PsiDirectory[] directories = psiPackage.getDirectories();
                if (directories.length > 0) {
                    final VirtualFile firstDir = directories[0].getVirtualFile();
                    final boolean isLibraryRoot = ProjectRootsUtil.isLibraryRoot(firstDir, project);
                    final PackageElement packageElement = new PackageElement(LangDataKeys.MODULE.getData(context), psiPackage, isLibraryRoot);
                    result.add(new PackageElementNode(project, packageElement, viewSettings));
                }
            }
        }
        return result.isEmpty() ? null : result;
    }
    final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
    final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(context);
    if (modules != null) {
        for (Module module : modules) {
            if (PackageViewPane.ID.equals(currentViewId)) {
                result.add(new PackageViewModuleNode(project, module, viewSettings));
            } else {
                result.add(new ProjectViewModuleNode(project, module, viewSettings));
            }
        }
    } else {
        final ModuleGroup[] data = ModuleGroup.ARRAY_DATA_KEY.getData(context);
        if (data != null) {
            for (ModuleGroup moduleGroup : data) {
                if (PackageViewPane.ID.equals(currentViewId)) {
                    result.add(new PackageViewModuleGroupNode(project, moduleGroup, viewSettings));
                } else {
                    result.add(new ProjectViewModuleGroupNode(project, moduleGroup, viewSettings));
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiPackage(com.intellij.psi.PsiPackage) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 27 with PsiPackage

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

the class PsiPackageFavoriteNodeProvider method createPathFromUrl.

@Override
public Object[] createPathFromUrl(final Project project, final String url, final String moduleName) {
    final Module module = moduleName != null ? ModuleManager.getInstance(project).findModuleByName(moduleName) : null;
    // module can be null if 'show module' turned off
    final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(url);
    if (aPackage == null)
        return null;
    PackageElement packageElement = new PackageElement(module, aPackage, false);
    return new Object[] { packageElement };
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module)

Example 28 with PsiPackage

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

the class PsiPackageFavoriteNodeProvider method elementContainsFile.

@Override
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
    if (element instanceof PackageElement) {
        final Set<Boolean> find = new HashSet<>();
        final ContentIterator contentIterator = new ContentIterator() {

            @Override
            public boolean processFile(VirtualFile fileOrDir) {
                if (fileOrDir != null && fileOrDir.getPath().equals(vFile.getPath())) {
                    find.add(Boolean.TRUE);
                }
                return true;
            }
        };
        final PackageElement packageElement = (PackageElement) element;
        final PsiPackage aPackage = packageElement.getPackage();
        final Project project = aPackage.getProject();
        final GlobalSearchScope scope = packageElement.getModule() != null ? GlobalSearchScope.moduleScope(packageElement.getModule()) : GlobalSearchScope.projectScope(project);
        final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        final PsiDirectory[] directories = aPackage.getDirectories(scope);
        for (PsiDirectory directory : directories) {
            projectFileIndex.iterateContentUnderDirectory(directory.getVirtualFile(), contentIterator);
        }
        return !find.isEmpty();
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ContentIterator(com.intellij.openapi.roots.ContentIterator) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) HashSet(java.util.HashSet)

Example 29 with PsiPackage

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

the class CyclicDependenciesAction method getInspectionScopeImpl.

@Nullable
private static AnalysisScope getInspectionScopeImpl(DataContext dataContext) {
    //Possible scopes: package, project, module.
    Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
    if (projectContext != null) {
        return null;
    }
    Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    if (moduleContext != null) {
        return null;
    }
    final Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
    if (modulesArray != null && modulesArray.length > 0) {
        return new AnalysisScope(modulesArray);
    }
    PsiElement psiTarget = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (psiTarget instanceof PsiDirectory) {
        PsiDirectory psiDirectory = (PsiDirectory) psiTarget;
        if (!psiDirectory.getManager().isInProject(psiDirectory))
            return null;
        return new AnalysisScope(psiDirectory);
    } else if (psiTarget instanceof PsiPackage) {
        PsiPackage pack = (PsiPackage) psiTarget;
        PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(pack.getProject()));
        if (dirs.length == 0)
            return null;
        return new JavaAnalysisScope(pack, LangDataKeys.MODULE.getData(dataContext));
    }
    return null;
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) Project(com.intellij.openapi.project.Project) JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with PsiPackage

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

the class PackageWrapper method exists.

public boolean exists() {
    final Project project = myManager.getProject();
    final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(myQualifiedName);
    return aPackage != null && aPackage.getDirectories(GlobalSearchScope.projectScope(project)).length > 0;
}
Also used : Project(com.intellij.openapi.project.Project) PsiPackage(com.intellij.psi.PsiPackage)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)93 PsiDirectory (com.intellij.psi.PsiDirectory)24 PsiClass (com.intellij.psi.PsiClass)22 Module (com.intellij.openapi.module.Module)19 Project (com.intellij.openapi.project.Project)14 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 PsiFile (com.intellij.psi.PsiFile)12 PsiElement (com.intellij.psi.PsiElement)11 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 Nullable (org.jetbrains.annotations.Nullable)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 HashSet (java.util.HashSet)6 List (java.util.List)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 ArrayList (java.util.ArrayList)4