Search in sources :

Example 36 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 37 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 38 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 39 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)

Example 40 with PsiManager

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

the class PsiFileReferenceHelper method getContextsForModule.

static Collection<PsiFileSystemItem> getContextsForModule(@NotNull Module module, @NotNull String packageName, @Nullable GlobalSearchScope scope) {
    List<PsiFileSystemItem> result = null;
    Query<VirtualFile> query = DirectoryIndex.getInstance(module.getProject()).getDirectoriesByPackageName(packageName, false);
    PsiManager manager = null;
    for (VirtualFile file : query) {
        if (scope != null && !scope.contains(file))
            continue;
        if (result == null) {
            result = new ArrayList<>();
            manager = PsiManager.getInstance(module.getProject());
        }
        PsiDirectory psiDirectory = manager.findDirectory(file);
        if (psiDirectory != null)
            result.add(psiDirectory);
    }
    return result != null ? result : Collections.<PsiFileSystemItem>emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

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