use of com.intellij.usages.Usage in project intellij-community by JetBrains.
the class VirtualFileArrayRule method getData.
@Override
public Object getData(final DataProvider dataProvider) {
// Try to detect multiselection.
Set<VirtualFile> result = null;
FileSystemTree fileSystemTree = FileSystemTree.DATA_KEY.getData(dataProvider);
if (fileSystemTree != null) {
result = addFiles(result, fileSystemTree.getSelectedFiles());
}
Project project = PlatformDataKeys.PROJECT_CONTEXT.getData(dataProvider);
if (project != null && !project.isDisposed()) {
result = addFiles(result, ProjectRootManager.getInstance(project).getContentRoots());
}
Module[] selectedModules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataProvider);
if (selectedModules != null && selectedModules.length > 0) {
for (Module selectedModule : selectedModules) {
result = addFiles(result, ModuleRootManager.getInstance(selectedModule).getContentRoots());
}
}
Module selectedModule = LangDataKeys.MODULE_CONTEXT.getData(dataProvider);
if (selectedModule != null && !selectedModule.isDisposed()) {
result = addFiles(result, ModuleRootManager.getInstance(selectedModule).getContentRoots());
}
PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataProvider);
if (psiElements != null) {
for (PsiElement element : psiElements) {
result = addFilesFromPsiElement(result, element);
}
}
result = addFile(result, CommonDataKeys.VIRTUAL_FILE.getData(dataProvider));
PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataProvider);
if (psiFile != null) {
result = addFile(result, psiFile.getVirtualFile());
}
if (result != null) {
return VfsUtilCore.toVirtualFileArray(result);
}
PsiElement elem = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
if (elem != null) {
result = addFilesFromPsiElement(result, elem);
}
Usage[] usages = UsageView.USAGES_KEY.getData(dataProvider);
UsageTarget[] usageTargets = UsageView.USAGE_TARGETS_KEY.getData(dataProvider);
if (usages != null || usageTargets != null) {
for (VirtualFile file : UsageDataUtil.provideVirtualFileArray(usages, usageTargets)) {
result = addFile(result, file);
}
}
if (result == null) {
final Object[] objects = (Object[]) dataProvider.getData(PlatformDataKeys.SELECTED_ITEMS.getName());
if (objects != null) {
final VirtualFile[] files = new VirtualFile[objects.length];
for (int i = 0, objectsLength = objects.length; i < objectsLength; i++) {
Object object = objects[i];
if (!(object instanceof VirtualFile))
return null;
files[i] = (VirtualFile) object;
}
return files;
}
return null;
} else {
return VfsUtilCore.toVirtualFileArray(result);
}
}
use of com.intellij.usages.Usage in project intellij-community by JetBrains.
the class UsageViewUtil method getNotExcludedUsageInfos.
public static Set<UsageInfo> getNotExcludedUsageInfos(final UsageView usageView) {
Set<Usage> excludedUsages = usageView.getExcludedUsages();
Set<UsageInfo> usageInfos = new LinkedHashSet<>();
for (Usage usage : usageView.getUsages()) {
if (usage instanceof UsageInfo2UsageAdapter && !excludedUsages.contains(usage)) {
UsageInfo usageInfo = ((UsageInfo2UsageAdapter) usage).getUsageInfo();
usageInfos.add(usageInfo);
}
}
return usageInfos;
}
use of com.intellij.usages.Usage in project intellij-community by JetBrains.
the class ReplaceUsageViewContext method doReplace.
private void doReplace() {
List<Usage> infos = myUsageView.getSortedUsages();
List<ReplacementInfo> results = new ArrayList<>(infos.size());
for (final Usage info : infos) {
UsageInfo2UsageAdapter usage = (UsageInfo2UsageAdapter) info;
if (isValid(usage)) {
results.add(usage2ReplacementInfo.get(usage));
}
}
getReplacer().replaceAll(results);
}
use of com.intellij.usages.Usage in project intellij-community by JetBrains.
the class RemoveUsageAction method getUsages.
@NotNull
private static Usage[] getUsages(AnActionEvent context) {
ApplicationManager.getApplication().assertIsDispatchThread();
UsageView usageView = context.getData(UsageView.USAGE_VIEW_KEY);
if (usageView == null)
return Usage.EMPTY_ARRAY;
Usage[] usages = context.getData(UsageView.USAGES_KEY);
return usages == null ? Usage.EMPTY_ARRAY : usages;
}
use of com.intellij.usages.Usage in project intellij-community by JetBrains.
the class ShowUsagesTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable list, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
UsageNode usageNode = value instanceof UsageNode ? (UsageNode) value : null;
Usage usage = usageNode == null ? null : usageNode.getUsage();
Color fileBgColor = getBackgroundColor(isSelected, usage);
Color bg = UIUtil.getListSelectionBackground();
Color fg = UIUtil.getListSelectionForeground();
Color panelBackground = isSelected ? bg : fileBgColor == null ? list.getBackground() : fileBgColor;
Color panelForeground = isSelected ? fg : list.getForeground();
SimpleColoredComponent textChunks = new SimpleColoredComponent();
if (usageNode == null || usageNode instanceof ShowUsagesAction.StringNode) {
textChunks.append(ObjectUtils.notNull(value, "").toString(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
return textComponentSpanningWholeRow(textChunks, panelBackground, panelForeground, column, list);
}
if (usage == ShowUsagesAction.MORE_USAGES_SEPARATOR) {
textChunks.append("...<");
textChunks.append("more usages", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
textChunks.append(">...");
return textComponentSpanningWholeRow(textChunks, panelBackground, panelForeground, column, list);
}
if (usage == ShowUsagesAction.USAGES_OUTSIDE_SCOPE_SEPARATOR) {
textChunks.append("...<");
textChunks.append(UsageViewManagerImpl.outOfScopeMessage(myOutOfScopeUsages.get(), mySearchScope), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
textChunks.append(">...");
return textComponentSpanningWholeRow(textChunks, panelBackground, panelForeground, column, list);
}
boolean lineNumberColumn = column == 1;
JPanel panel = new JPanel(new FlowLayout(lineNumberColumn ? FlowLayout.RIGHT : FlowLayout.LEFT, 0, 0) {
@Override
public void layoutContainer(Container container) {
super.layoutContainer(container);
for (Component component : container.getComponents()) {
// align inner components
Rectangle b = component.getBounds();
Insets insets = container.getInsets();
component.setBounds(b.x, b.y, b.width, container.getSize().height - insets.top - insets.bottom);
}
}
});
panel.setFont(null);
panel.setBackground(panelBackground);
panel.setForeground(panelForeground);
// greying the current usage you originated your "find usages" from is turned off by @nik orders
//!myUsageView.isOriginUsage(usage);
boolean isEnabled = true;
if (!isEnabled) {
fg = UIUtil.getLabelDisabledForeground();
}
if (column == 0) {
appendGroupText(list, (GroupNode) usageNode.getParent(), panel, fileBgColor, isSelected);
} else {
if (usage != ShowUsagesAction.MORE_USAGES_SEPARATOR && usage != ShowUsagesAction.USAGES_OUTSIDE_SCOPE_SEPARATOR) {
UsagePresentation presentation = usage.getPresentation();
TextChunk[] text = presentation.getText();
if (lineNumberColumn) {
// line number
if (text.length != 0) {
TextChunk chunk = text[0];
textChunks.append(chunk.getText(), getAttributes(isSelected, fileBgColor, bg, fg, chunk));
}
} else if (column == 2) {
Icon icon = presentation.getIcon();
textChunks.setIcon(icon == null ? EmptyIcon.ICON_16 : icon);
textChunks.append("").appendTextPadding(JBUI.scale(16 + 5));
for (int i = 1; i < text.length; i++) {
TextChunk chunk = text[i];
textChunks.append(chunk.getText(), getAttributes(isSelected, fileBgColor, bg, fg, chunk));
}
} else {
assert false : column;
}
}
SpeedSearchUtil.applySpeedSearchHighlighting(list, textChunks, false, isSelected);
panel.add(textChunks);
}
if (!isEnabled) {
GuiUtils.enableChildren(panel, false);
}
return panel;
}
Aggregations