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);
}
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;
}
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;
}
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;
}
Aggregations