Search in sources :

Example 26 with PsiManager

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

the class AddToFavoritesAction method createNodes.

@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
    if (project == null)
        return Collections.emptyList();
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
        final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
        if (treeNode != null) {
            result.add(treeNode);
            return result;
        }
    }
    final PsiManager psiManager = PsiManager.getInstance(project);
    final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
    AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
    //on psi elements
    if (object instanceof PsiElement[]) {
        for (PsiElement psiElement : (PsiElement[]) object) {
            addPsiElementNode(psiElement, project, result, favoritesConfig);
        }
        return result;
    }
    //on psi element
    if (object instanceof PsiElement) {
        Module containingModule = null;
        if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
            if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
                AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
                while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
                    abstractTreeNode = abstractTreeNode.getParent();
                }
                if (abstractTreeNode != null) {
                    containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
                }
            }
        }
        addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
        return result;
    }
    if (object instanceof VirtualFile[]) {
        for (VirtualFile vFile : (VirtualFile[]) object) {
            PsiElement element = psiManager.findFile(vFile);
            if (element == null)
                element = psiManager.findDirectory(vFile);
            addPsiElementNode(element, project, result, favoritesConfig);
        }
        return result;
    }
    //on form in editor
    if (object instanceof VirtualFile) {
        final VirtualFile vFile = (VirtualFile) object;
        final PsiFile psiFile = psiManager.findFile(vFile);
        addPsiElementNode(psiFile, project, result, favoritesConfig);
        return result;
    }
    //on module groups
    if (object instanceof ModuleGroup[]) {
        for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
            result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
        }
        return result;
    }
    //on module nodes
    if (object instanceof Module)
        object = new Module[] { (Module) object };
    if (object instanceof Module[]) {
        for (Module module1 : (Module[]) object) {
            result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
        }
        return result;
    }
    //on library group node
    if (object instanceof LibraryGroupElement[]) {
        for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
            result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
        }
        return result;
    }
    //on named library node
    if (object instanceof NamedLibraryElement[]) {
        for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
            result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
        }
        return result;
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiManager(com.intellij.psi.PsiManager) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) FavoriteNodeProvider(com.intellij.ide.favoritesTreeView.FavoriteNodeProvider) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with PsiManager

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

the class BookmarkItem method setupRenderer.

public static void setupRenderer(SimpleColoredComponent renderer, Project project, Bookmark bookmark, boolean selected) {
    VirtualFile file = bookmark.getFile();
    if (!file.isValid()) {
        return;
    }
    PsiManager psiManager = PsiManager.getInstance(project);
    PsiElement fileOrDir = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file);
    if (fileOrDir != null) {
        renderer.setIcon(fileOrDir.getIcon(0));
    }
    String description = bookmark.getDescription();
    if (description != null) {
        renderer.append(description + " ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    }
    FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
    TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
    renderer.append(file.getName(), SimpleTextAttributes.fromTextAttributes(attributes));
    if (bookmark.getLine() >= 0) {
        renderer.append(":", SimpleTextAttributes.GRAYED_ATTRIBUTES);
        renderer.append(String.valueOf(bookmark.getLine() + 1), SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
    renderer.append(" (" + VfsUtilCore.getRelativeLocation(file, project.getBaseDir()) + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
    if (!selected) {
        FileColorManager colorManager = FileColorManager.getInstance(project);
        if (fileOrDir instanceof PsiFile) {
            Color color = colorManager.getRendererBackground((PsiFile) fileOrDir);
            if (color != null) {
                renderer.setBackground(color);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileStatus(com.intellij.openapi.vcs.FileStatus) PsiManager(com.intellij.psi.PsiManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 28 with PsiManager

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

the class AddAllOpenFilesToFavorites method getFilesToAdd.

static ArrayList<PsiFile> getFilesToAdd(Project project) {
    ArrayList<PsiFile> result = new ArrayList<>();
    final FileEditorManager editorManager = FileEditorManager.getInstance(project);
    final PsiManager psiManager = PsiManager.getInstance(project);
    for (VirtualFile openFile : editorManager.getOpenFiles()) {
        if (!openFile.isValid())
            continue;
        final PsiFile psiFile = psiManager.findFile(openFile);
        if (psiFile != null) {
            result.add(psiFile);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 29 with PsiManager

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

the class ProjectViewModuleNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    Module module = getValue();
    if (module == null || module.isDisposed()) {
        // module has been disposed
        return Collections.emptyList();
    }
    final List<VirtualFile> contentRoots = ProjectViewDirectoryHelper.getInstance(myProject).getTopLevelModuleRoots(module, getSettings());
    final List<AbstractTreeNode> children = new ArrayList<>(contentRoots.size());
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    for (final VirtualFile contentRoot : contentRoots) {
        if (contentRoot.isDirectory()) {
            PsiDirectory directory = psiManager.findDirectory(contentRoot);
            if (directory != null) {
                children.add(new PsiDirectoryNode(getProject(), directory, getSettings()));
            }
        } else {
            PsiFile file = psiManager.findFile(contentRoot);
            if (file != null) {
                children.add(new PsiFileNode(getProject(), file, getSettings()));
            }
        }
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with PsiManager

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

the class LibraryGroupNode method addLibraryChildren.

public static void addLibraryChildren(final LibraryOrSdkOrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    VirtualFile[] files = entry instanceof LibraryOrderEntry ? getLibraryRoots((LibraryOrderEntry) entry) : entry.getRootFiles(OrderRootType.CLASSES);
    for (final VirtualFile file : files) {
        if (!file.isValid())
            continue;
        if (file.isDirectory()) {
            final PsiDirectory psiDir = psiManager.findDirectory(file);
            if (psiDir == null) {
                continue;
            }
            children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
        } else {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile == null)
                continue;
            children.add(new PsiFileNode(project, psiFile, node.getSettings()));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

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