Search in sources :

Example 76 with PsiDirectory

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

the class AntDomFileReferenceSet method computeDefaultContexts.

@NotNull
@Override
public Collection<PsiFileSystemItem> computeDefaultContexts() {
    final AntDomElement element = myValue.getParentOfType(AntDomElement.class, false);
    final AntDomProject containingProject = element != null ? element.getAntProject() : null;
    if (containingProject != null) {
        if (isAbsolutePathReference()) {
            return toFileSystemItems(ManagingFS.getInstance().getLocalRoots());
        } else {
            VirtualFile root = null;
            if (element instanceof AntDomAnt) {
                final PsiFileSystemItem dirValue = ((AntDomAnt) element).getAntFileDir().getValue();
                if (dirValue instanceof PsiDirectory) {
                    root = dirValue.getVirtualFile();
                }
            }
            if (root == null) {
                final String basedir;
                if (element instanceof AntDomIncludingDirective) {
                    basedir = containingProject.getContainingFileDir();
                } else {
                    basedir = containingProject.getContextAntProject().getProjectBasedirPath();
                }
                if (basedir != null) {
                    root = LocalFileSystem.getInstance().findFileByPath(basedir);
                }
            }
            if (root != null) {
                return toFileSystemItems(root);
            }
        }
    }
    return super.computeDefaultContexts();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with PsiDirectory

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

the class DirectoryCoverageViewExtension method getChildrenNodes.

@Override
public List<AbstractTreeNode> getChildrenNodes(AbstractTreeNode node) {
    List<AbstractTreeNode> children = new ArrayList<>();
    if (node instanceof CoverageListNode) {
        final Object val = node.getValue();
        if (val instanceof PsiFile || val == null)
            return Collections.emptyList();
        final PsiDirectory psiDirectory = (PsiDirectory) val;
        final PsiDirectory[] subdirectories = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory[]>() {

            @Override
            public PsiDirectory[] compute() {
                return psiDirectory.getSubdirectories();
            }
        });
        for (PsiDirectory subdirectory : subdirectories) {
            children.add(new CoverageListNode(myProject, subdirectory, mySuitesBundle, myStateBean));
        }
        final PsiFile[] psiFiles = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() {

            @Override
            public PsiFile[] compute() {
                return psiDirectory.getFiles();
            }
        });
        for (PsiFile psiFile : psiFiles) {
            children.add(new CoverageListNode(myProject, psiFile, mySuitesBundle, myStateBean));
        }
        for (AbstractTreeNode childNode : children) {
            childNode.setParent(node);
        }
    }
    return children;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile)

Example 78 with PsiDirectory

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

the class CoverageProjectViewDirectoryNodeDecorator method decorate.

public void decorate(PackageDependenciesNode node, ColoredTreeCellRenderer cellRenderer) {
    final PsiElement element = node.getPsiElement();
    if (element == null || !element.isValid()) {
        return;
    }
    final CoverageDataManager manager = getCoverageDataManager();
    final CoverageSuitesBundle currentSuite = manager.getCurrentSuitesBundle();
    final CoverageAnnotator coverageAnnotator = currentSuite != null ? currentSuite.getAnnotator(element.getProject()) : null;
    if (coverageAnnotator == null) {
        // N/A
        return;
    }
    String informationString = null;
    if (element instanceof PsiDirectory) {
        informationString = coverageAnnotator.getDirCoverageInformationString((PsiDirectory) element, currentSuite, manager);
    } else if (element instanceof PsiFile) {
        informationString = coverageAnnotator.getFileCoverageInformationString((PsiFile) element, currentSuite, manager);
    }
    if (informationString != null) {
        appendCoverageInfo(cellRenderer, informationString);
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 79 with PsiDirectory

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

the class CoverageProjectViewDirectoryNodeDecorator method decorate.

public void decorate(ProjectViewNode node, PresentationData data) {
    final CoverageDataManager manager = getCoverageDataManager();
    final CoverageSuitesBundle currentSuite = manager.getCurrentSuitesBundle();
    final CoverageAnnotator coverageAnnotator = currentSuite != null ? currentSuite.getAnnotator(node.getProject()) : null;
    if (coverageAnnotator == null) {
        // N/A
        return;
    }
    final Object value = node.getValue();
    PsiElement element = null;
    if (value instanceof PsiElement) {
        element = (PsiElement) value;
    } else if (value instanceof SmartPsiElementPointer) {
        element = ((SmartPsiElementPointer) value).getElement();
    }
    String informationString = null;
    if (element instanceof PsiDirectory) {
        informationString = coverageAnnotator.getDirCoverageInformationString((PsiDirectory) element, currentSuite, manager);
    } else if (element instanceof PsiFile) {
        informationString = coverageAnnotator.getFileCoverageInformationString((PsiFile) element, currentSuite, manager);
    }
    if (informationString != null) {
        data.setLocationString(informationString);
    }
}
Also used : SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 80 with PsiDirectory

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

the class DescriptionCheckerUtil method allDescriptionDirs.

/**
   * Unlike getDescriptionsDirs this includes dirs in dependent modules and even project dirs ordered by
   * search scopes (first dirs in current module, then dirs in module dependencies, then dirs in
   * dependent modules, finally other project dirs).
   *
   * @param module module to search description directories for
   * @param descriptionType type of description directory to search
   * @return lazily populated stream of candidate directories
   */
public static StreamEx<PsiDirectory> allDescriptionDirs(Module module, DescriptionType descriptionType) {
    final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(module.getProject());
    final PsiPackage psiPackage = javaPsiFacade.findPackage(descriptionType.getDescriptionFolder());
    if (psiPackage == null)
        return StreamEx.empty();
    return searchScopes(module).flatMap(scope -> StreamEx.of(psiPackage.getDirectories(scope))).distinct();
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable) PsiClass(com.intellij.psi.PsiClass) GlobalSearchScopesCore(com.intellij.psi.search.GlobalSearchScopesCore) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) StreamEx(one.util.streamex.StreamEx) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) Supplier(java.util.function.Supplier) PsiPackage(com.intellij.psi.PsiPackage)

Aggregations

PsiDirectory (com.intellij.psi.PsiDirectory)321 VirtualFile (com.intellij.openapi.vfs.VirtualFile)122 PsiFile (com.intellij.psi.PsiFile)111 PsiElement (com.intellij.psi.PsiElement)79 Project (com.intellij.openapi.project.Project)73 Module (com.intellij.openapi.module.Module)68 Nullable (org.jetbrains.annotations.Nullable)62 NotNull (org.jetbrains.annotations.NotNull)50 IdeView (com.intellij.ide.IdeView)31 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)24 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)24 PsiManager (com.intellij.psi.PsiManager)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 ArrayList (java.util.ArrayList)20 PsiPackage (com.intellij.psi.PsiPackage)17 File (java.io.File)15 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)11 IncorrectOperationException (com.intellij.util.IncorrectOperationException)11 Course (com.jetbrains.edu.learning.courseFormat.Course)11 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)10