use of com.intellij.usages.rules.UsageInFiles 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;
}
Aggregations