Search in sources :

Example 1 with UsageInFile

use of com.intellij.usages.rules.UsageInFile in project intellij-community by JetBrains.

the class UsageViewManagerImpl method isInScope.

public static boolean isInScope(@NotNull Usage usage, @NotNull SearchScope searchScope) {
    PsiElement element = null;
    VirtualFile file = usage instanceof UsageInFile ? ((UsageInFile) usage).getFile() : usage instanceof PsiElementUsage ? PsiUtilCore.getVirtualFile(element = ((PsiElementUsage) usage).getElement()) : null;
    if (file != null) {
        return isFileInScope(file, searchScope);
    }
    return element != null && (searchScope instanceof EverythingGlobalScope || searchScope instanceof ProjectScopeImpl || searchScope instanceof ProjectAndLibrariesScope);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UsageInFile(com.intellij.usages.rules.UsageInFile) PsiElement(com.intellij.psi.PsiElement) PsiElementUsage(com.intellij.usages.rules.PsiElementUsage)

Example 2 with UsageInFile

use of com.intellij.usages.rules.UsageInFile in project intellij-community by JetBrains.

the class UsageFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null) {
        return null;
    }
    final Usage[] usages = UsageView.USAGES_KEY.getData(context);
    if (usages != null) {
        final List<AbstractTreeNode> result = new SmartList<>();
        final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
        final List<Usage> nonMapped = new ArrayList<>();
        for (Usage usage : usages) {
            if (usage instanceof UsageInFile) {
                map.putValue(((UsageInFile) usage).getFile(), usage);
            } else if (usage instanceof UsageInFiles) {
                final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
                for (VirtualFile file : files) {
                    map.putValue(file, usage);
                }
            } else {
                nonMapped.add(usage);
            }
        }
        final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
        keys.addAll(map.keySet());
        for (VirtualFile key : keys) {
            final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
            result.add(grouping);
            final Collection<Usage> subUsages = map.get(key);
            for (Usage usage : subUsages) {
                if (usage instanceof UsageInfo2UsageAdapter) {
                    final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                    grouping.addChild(node);
                } else if (NullUsage.INSTANCE.equals(usage)) {
                    continue;
                } else {
                    grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
                }
            }
        }
        for (Usage usage : nonMapped) {
            if (usage instanceof UsageInfo2UsageAdapter) {
                final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                result.add(node);
            } else if (NullUsage.INSTANCE.equals(usage)) {
                continue;
            } else {
                result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
            }
        }
        return result;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NullUsage(com.intellij.usages.impl.NullUsage) Usage(com.intellij.usages.Usage) UsageInFiles(com.intellij.usages.rules.UsageInFiles) UsageInFile(com.intellij.usages.rules.UsageInFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) MultiMap(com.intellij.util.containers.MultiMap) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) SmartList(com.intellij.util.SmartList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) UsageInFile(com.intellij.usages.rules.UsageInFile) File(java.io.File)

Example 3 with UsageInFile

use of com.intellij.usages.rules.UsageInFile in project intellij-community by JetBrains.

the class DirectoryGroupingRule method groupUsage.

@Override
@Nullable
public UsageGroup groupUsage(@NotNull Usage usage) {
    if (usage instanceof UsageInFile) {
        UsageInFile usageInFile = (UsageInFile) usage;
        VirtualFile file = usageInFile.getFile();
        if (file != null) {
            if (file instanceof VirtualFileWindow) {
                file = ((VirtualFileWindow) file).getDelegate();
            }
            VirtualFile dir = file.getParent();
            if (dir == null)
                return null;
            return getGroupForFile(dir);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) UsageInFile(com.intellij.usages.rules.UsageInFile) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with UsageInFile

use of com.intellij.usages.rules.UsageInFile in project intellij-community by JetBrains.

the class ShowUsagesTableCellRenderer method getBackgroundColor.

private Color getBackgroundColor(boolean isSelected, Usage usage) {
    Color fileBgColor = null;
    if (isSelected) {
        fileBgColor = UIUtil.getListSelectionBackground();
    } else {
        VirtualFile virtualFile = usage instanceof UsageInFile ? ((UsageInFile) usage).getFile() : null;
        if (virtualFile != null) {
            Project project = myUsageView.getProject();
            PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
            if (psiFile != null && psiFile.isValid()) {
                final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile);
                if (color != null)
                    fileBgColor = color;
            }
        }
    }
    return fileBgColor;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) UsageInFile(com.intellij.usages.rules.UsageInFile) PsiFile(com.intellij.psi.PsiFile)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 UsageInFile (com.intellij.usages.rules.UsageInFile)4 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1 PsiElement (com.intellij.psi.PsiElement)1 Usage (com.intellij.usages.Usage)1 UsageInfo2UsageAdapter (com.intellij.usages.UsageInfo2UsageAdapter)1 NullUsage (com.intellij.usages.impl.NullUsage)1 PsiElementUsage (com.intellij.usages.rules.PsiElementUsage)1 UsageInFiles (com.intellij.usages.rules.UsageInFiles)1 SmartList (com.intellij.util.SmartList)1 MultiMap (com.intellij.util.containers.MultiMap)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1