Search in sources :

Example 21 with PsiManager

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

the class TodoTreeHelper method addDirsToChildren.

protected void addDirsToChildren(List<VirtualFile> roots, ArrayList<AbstractTreeNode> children, TodoTreeBuilder builder) {
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    for (VirtualFile dir : roots) {
        final PsiDirectory directory = psiManager.findDirectory(dir);
        if (directory == null) {
            continue;
        }
        final Iterator<PsiFile> files = builder.getFiles(directory);
        if (!files.hasNext())
            continue;
        TodoDirNode dirNode = new TodoDirNode(myProject, directory, builder);
        if (!children.contains(dirNode)) {
            children.add(dirNode);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 22 with PsiManager

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

the class PlatformPackageUtil method getPackageDirectories.

private static PsiDirectory[] getPackageDirectories(Project project, String rootPackage, final GlobalSearchScope scope) {
    final PsiManager manager = PsiManager.getInstance(project);
    Query<VirtualFile> query = DirectoryIndex.getInstance(scope.getProject()).getDirectoriesByPackageName(rootPackage, true);
    query = new FilteredQuery<>(query, scope::contains);
    List<PsiDirectory> directories = ContainerUtil.mapNotNull(query.findAll(), manager::findDirectory);
    return directories.toArray(new PsiDirectory[directories.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager)

Example 23 with PsiManager

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

the class ProjectBaseDirNavigationContributor method getItemsByName.

@Override
@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null)
        return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
    final VirtualFile[] files = baseDir.getChildren();
    final ArrayList<PsiFile> list = new ArrayList<>();
    for (VirtualFile file : files) {
        if (isEditable(file, includeNonProjectItems) && Comparing.strEqual(name, file.getName())) {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile != null) {
                list.add(psiFile);
            }
        }
    }
    return PsiUtilCore.toPsiFileArray(list);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with PsiManager

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

the class DependenciesPanel method selectElementInLeftTree.

private void selectElementInLeftTree(PsiElement elt) {
    PsiManager manager = PsiManager.getInstance(myProject);
    PackageDependenciesNode root = (PackageDependenciesNode) myLeftTree.getModel().getRoot();
    Enumeration enumeration = root.breadthFirstEnumeration();
    while (enumeration.hasMoreElements()) {
        PackageDependenciesNode child = (PackageDependenciesNode) enumeration.nextElement();
        if (manager.areElementsEquivalent(child.getPsiElement(), elt)) {
            myLeftTree.setSelectionPath(new TreePath(((DefaultTreeModel) myLeftTree.getModel()).getPathToRoot(child)));
            break;
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) PsiManager(com.intellij.psi.PsiManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 25 with PsiManager

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

the class PsiElementBaseIntentionAction method isAvailable.

@Override
public final boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    if (file == null)
        return false;
    final PsiManager manager = file.getManager();
    if (manager == null)
        return false;
    if (!manager.isInProject(file))
        return false;
    final PsiElement element = getElement(editor, file);
    return element != null && isAvailable(project, editor, element);
}
Also used : PsiManager(com.intellij.psi.PsiManager) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiManager (com.intellij.psi.PsiManager)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)69 PsiFile (com.intellij.psi.PsiFile)51 NotNull (org.jetbrains.annotations.NotNull)25 PsiDirectory (com.intellij.psi.PsiDirectory)24 Project (com.intellij.openapi.project.Project)17 Module (com.intellij.openapi.module.Module)16 Nullable (org.jetbrains.annotations.Nullable)16 PsiElement (com.intellij.psi.PsiElement)15 ArrayList (java.util.ArrayList)15 File (java.io.File)14 XmlFile (com.intellij.psi.xml.XmlFile)11 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)10 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)8 PsiClass (com.intellij.psi.PsiClass)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)4 IOException (java.io.IOException)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4