Search in sources :

Example 6 with Usage

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Usage(com.intellij.usages.Usage) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget)

Example 7 with Usage

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Usage(com.intellij.usages.Usage) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo)

Example 8 with Usage

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);
}
Also used : Usage(com.intellij.usages.Usage) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) ArrayList(java.util.ArrayList) ReplacementInfo(com.intellij.structuralsearch.plugin.replace.ReplacementInfo)

Example 9 with Usage

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;
}
Also used : UsageView(com.intellij.usages.UsageView) Usage(com.intellij.usages.Usage) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with Usage

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;
}
Also used : Usage(com.intellij.usages.Usage) TextChunk(com.intellij.usages.TextChunk) UsagePresentation(com.intellij.usages.UsagePresentation) UsageNode(com.intellij.usages.impl.UsageNode) EmptyIcon(com.intellij.util.ui.EmptyIcon) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Aggregations

Usage (com.intellij.usages.Usage)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 UsageInfo2UsageAdapter (com.intellij.usages.UsageInfo2UsageAdapter)4 RelativePoint (com.intellij.ui.awt.RelativePoint)3 SmartList (com.intellij.util.SmartList)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 PsiElement (com.intellij.psi.PsiElement)2 UsageInfo (com.intellij.usageView.UsageInfo)2 Nullable (org.jetbrains.annotations.Nullable)2 CommonBundle (com.intellij.CommonBundle)1 com.intellij.find (com.intellij.find)1 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)1 CustomUsageSearcher (com.intellij.find.findUsages.CustomUsageSearcher)1 FindUsagesOptions (com.intellij.find.findUsages.FindUsagesOptions)1 AllIcons (com.intellij.icons.AllIcons)1 FavoritesManager (com.intellij.ide.favoritesTreeView.FavoritesManager)1 AbstractUrl (com.intellij.ide.projectView.impl.AbstractUrl)1