Search in sources :

Example 46 with PsiDirectory

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

the class AbstractFolderNode method containsImpl.

@Override
protected boolean containsImpl(@NotNull final VirtualFile file) {
    final PsiElement psiElement = extractPsiFromValue();
    if (psiElement == null || !psiElement.isValid()) {
        return false;
    }
    final VirtualFile valueFile = ((PsiDirectory) psiElement).getVirtualFile();
    if (!VfsUtil.isAncestor(valueFile, file, false)) {
        return false;
    }
    final Project project = psiElement.getProject();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final Module module = fileIndex.getModuleForFile(valueFile);
    if (module == null) {
        return fileIndex.getModuleForFile(file) == null;
    }
    return ModuleRootManager.getInstance(module).getFileIndex().isInContent(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 47 with PsiDirectory

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

the class AbstractFolderNode method getChildrenImpl.

@Override
@Nullable
protected Collection<AbstractTreeNode> getChildrenImpl() {
    final PsiDirectory directory = getPsiDirectory();
    if (!directory.isValid()) {
        return Collections.emptyList();
    }
    // scan folder's children
    final List<AbstractTreeNode> children = Arrays.stream(directory.getSubdirectories()).map(this::createFolderNode).collect(Collectors.toList());
    for (PsiFile file : directory.getFiles()) {
        processNotDirectoryFile(children, file);
    }
    return children;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with PsiDirectory

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

the class AbstractFolderNode method createFolderNode.

private AbstractFolderNode createFolderNode(PsiDirectory directory) {
    PsiDirectory realDirectory = directory;
    StringBuilder textBuilder = null;
    if (getSettings().isHideEmptyMiddlePackages()) {
        do {
            if (realDirectory.getFiles().length > 0)
                break;
            PsiDirectory[] subdirectories = realDirectory.getSubdirectories();
            if (subdirectories.length != 1)
                break;
            if (textBuilder == null) {
                textBuilder = new StringBuilder();
                textBuilder.append(realDirectory.getName());
            }
            realDirectory = subdirectories[0];
            textBuilder.append('.').append(realDirectory.getName());
        } while (true);
    }
    String presentableText = textBuilder == null ? directory.getName() : textBuilder.toString();
    return new AbstractFolderNode(getModule(), realDirectory, presentableText, getSettings(), FOLDER) {

        @Override
        protected void processNotDirectoryFile(List<AbstractTreeNode> nodes, PsiFile file) {
            AbstractFolderNode.this.processNotDirectoryFile(nodes, file);
        }

        @Override
        protected AbstractTreeNode createClassNode(GrTypeDefinition typeDefinition) {
            return AbstractFolderNode.this.createClassNode(typeDefinition);
        }
    };
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiDirectory(com.intellij.psi.PsiDirectory) List(java.util.List) PsiFile(com.intellij.psi.PsiFile)

Example 49 with PsiDirectory

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

the class MavenFilteredPropertiesCompletionAndResolutionTest method testReferencesInXml.

public void testReferencesInXml() throws Exception {
    createProjectSubDir("res");
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + "  <resources>" + "    <resource>" + "      <directory>res</directory>" + "      <filtering>true</filtering>" + "    </resource>" + "  </resources>" + "</build>");
    VirtualFile f = createProjectSubFile("res/foo.xml", "<root attr='${based<caret>ir}'>" + "</root>");
    myFixture.configureFromExistingVirtualFile(f);
    XmlAttribute attribute = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), XmlAttribute.class);
    PsiReference[] references = attribute.getReferences();
    for (PsiReference ref : references) {
        if (ref.resolve() instanceof PsiDirectory) {
            // Maven references was added.
            return;
        }
    }
    assertTrue("Maven filter reference was not added", false);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiDirectory(com.intellij.psi.PsiDirectory) MavenPropertyPsiReference(org.jetbrains.idea.maven.dom.references.MavenPropertyPsiReference) PsiReference(com.intellij.psi.PsiReference)

Example 50 with PsiDirectory

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

the class MavenFilteredPropertiesCompletionAndResolutionTest method testCorrectlyCalculatingBaseDir.

public void testCorrectlyCalculatingBaseDir() throws Exception {
    createProjectSubDir("res");
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + "  <resources>" + "    <resource>" + "      <directory>res</directory>" + "      <filtering>true</filtering>" + "    </resource>" + "  </resources>" + "</build>");
    VirtualFile f = createProjectSubFile("res/foo.properties", "foo=abc${basedir<caret>}abc");
    PsiDirectory baseDir = PsiManager.getInstance(myProject).findDirectory(myProjectPom.getParent());
    assertResolved(f, baseDir);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory)

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