Search in sources :

Example 66 with PsiDirectory

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

the class TodoPackageNode method getFiles.

/**
   * @return read-only iterator of all valid PSI files that can have T.O.D.O items
   *         and which are located under specified {@code psiDirctory}.
   */
public Iterator<PsiFile> getFiles(PackageElement packageElement) {
    ArrayList<PsiFile> psiFileList = new ArrayList<>();
    GlobalSearchScope scope = packageElement.getModule() != null ? GlobalSearchScope.moduleScope(packageElement.getModule()) : GlobalSearchScope.projectScope(myProject);
    final PsiDirectory[] directories = packageElement.getPackage().getDirectories(scope);
    for (PsiDirectory directory : directories) {
        Iterator<PsiFile> files = myBuilder.getFiles(directory, false);
        for (; files.hasNext(); ) {
            psiFileList.add(files.next());
        }
    }
    return psiFileList.iterator();
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile)

Example 67 with PsiDirectory

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

the class TodoPackageNode method getFileCount.

private int getFileCount(final PackageElement packageElement) {
    int count = 0;
    if (getSettings().isFlattenPackages()) {
        final PsiPackage aPackage = packageElement.getPackage();
        final Module module = packageElement.getModule();
        final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(aPackage.getProject());
        final PsiDirectory[] directories = aPackage.getDirectories(scope);
        for (PsiDirectory directory : directories) {
            Iterator<PsiFile> iterator = myBuilder.getFilesUnderDirectory(directory);
            while (iterator.hasNext()) {
                PsiFile psiFile = iterator.next();
                if (getStructure().accept(psiFile))
                    count++;
            }
        }
    } else {
        Iterator<PsiFile> iterator = getFiles(packageElement);
        while (iterator.hasNext()) {
            PsiFile psiFile = iterator.next();
            if (getStructure().accept(psiFile)) {
                count++;
            }
        }
    }
    return count;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 68 with PsiDirectory

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

the class JavaProjectViewDirectoryHelper method getNodeName.

@Nullable
@Override
public String getNodeName(final ViewSettings settings, final Object parentValue, final PsiDirectory directory) {
    PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
    PsiPackage parentPackage;
    if (!ProjectRootsUtil.isSourceRoot(directory) && aPackage != null && !aPackage.getQualifiedName().isEmpty() && parentValue instanceof PsiDirectory) {
        parentPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) parentValue));
    } else if (ProjectRootsUtil.isSourceRoot(directory) && aPackage != null) {
        //package prefix
        aPackage = null;
        parentPackage = null;
    } else {
        parentPackage = null;
    }
    return PackageUtil.getNodeName(settings, aPackage, parentPackage, directory.getName(), isShowFQName(settings, parentValue, directory));
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with PsiDirectory

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

the class PackageElement method getRoots.

@NotNull
@Override
public Collection<VirtualFile> getRoots() {
    Set<VirtualFile> roots = new HashSet<>();
    final PsiDirectory[] dirs = PackageUtil.getDirectories(getPackage(), myModule, isLibraryElement());
    for (PsiDirectory each : dirs) {
        roots.add(each.getVirtualFile());
    }
    return roots;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with PsiDirectory

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

the class PackageElementNode method canRepresent.

@Override
public boolean canRepresent(final Object element) {
    if (super.canRepresent(element))
        return true;
    final PackageElement value = getValue();
    if (value == null)
        return true;
    if (element instanceof PackageElement) {
        final PackageElement packageElement = (PackageElement) element;
        final String otherPackage = packageElement.getPackage().getQualifiedName();
        final String aPackage = value.getPackage().getQualifiedName();
        if (otherPackage.equals(aPackage)) {
            return true;
        }
    }
    if (element instanceof PsiDirectory) {
        final PsiDirectory directory = (PsiDirectory) element;
        return Arrays.asList(value.getPackage().getDirectories()).contains(directory);
    }
    return false;
}
Also used : 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