mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add call/method/type hierarchy predefined scope
This commit is contained in:
@@ -43,9 +43,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -147,6 +148,43 @@ public abstract class HierarchyBrowserBase extends SimpleToolWindowPanel impleme
|
||||
return null;
|
||||
}
|
||||
|
||||
public PsiElement[] getAvailableElements() {
|
||||
final JTree tree = getCurrentTree();
|
||||
if (tree == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
final TreeModel model = tree.getModel();
|
||||
final Object root = model.getRoot();
|
||||
if (!(root instanceof DefaultMutableTreeNode)) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
final DefaultMutableTreeNode node = (DefaultMutableTreeNode)root;
|
||||
final HierarchyNodeDescriptor descriptor = getDescriptor(node);
|
||||
final Set<PsiElement> result = new HashSet<PsiElement>();
|
||||
collectElements(descriptor, result);
|
||||
return result.toArray(PsiElement.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private void collectElements(HierarchyNodeDescriptor descriptor, Set<PsiElement> out) {
|
||||
if (descriptor == null) {
|
||||
return;
|
||||
}
|
||||
final PsiElement element = getElementFromDescriptor(descriptor);
|
||||
if (element != null) {
|
||||
out.add(element);
|
||||
}
|
||||
final Object[] children = descriptor.getCachedChildren();
|
||||
if (children == null) {
|
||||
return;
|
||||
}
|
||||
for (Object child : children) {
|
||||
if (child instanceof HierarchyNodeDescriptor) {
|
||||
final HierarchyNodeDescriptor childDescriptor = (HierarchyNodeDescriptor)child;
|
||||
collectElements(childDescriptor, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final HierarchyNodeDescriptor[] getSelectedDescriptors() {
|
||||
final JTree tree = getCurrentTree();
|
||||
if (tree == null) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.psi.search;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.hierarchy.HierarchyBrowserBase;
|
||||
import com.intellij.ide.projectView.impl.AbstractUrl;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
@@ -30,12 +31,17 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
import com.intellij.usages.Usage;
|
||||
import com.intellij.usages.UsageView;
|
||||
import com.intellij.usages.UsageViewManager;
|
||||
@@ -47,6 +53,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProvider {
|
||||
@@ -139,6 +146,7 @@ public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProv
|
||||
}
|
||||
|
||||
if (usageView) {
|
||||
addHierarchyScope(project, result);
|
||||
UsageView selectedUsageView = UsageViewManager.getInstance(project).getSelectedUsageView();
|
||||
if (selectedUsageView != null && !selectedUsageView.isSearchInProgress()) {
|
||||
final Set<Usage> usages = selectedUsageView.getUsages();
|
||||
@@ -239,6 +247,28 @@ public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProv
|
||||
return ContainerUtil.newArrayList(result);
|
||||
}
|
||||
|
||||
private static void addHierarchyScope(@NotNull Project project, Collection<SearchScope> result) {
|
||||
final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY);
|
||||
if (toolWindow == null) {
|
||||
return;
|
||||
}
|
||||
final ContentManager contentManager = toolWindow.getContentManager();
|
||||
final Content content = contentManager.getSelectedContent();
|
||||
if (content == null) {
|
||||
return;
|
||||
}
|
||||
final String name = content.getDisplayName();
|
||||
final JComponent component = content.getComponent();
|
||||
if (!(component instanceof HierarchyBrowserBase)) {
|
||||
return;
|
||||
}
|
||||
final HierarchyBrowserBase hierarchyBrowserBase = (HierarchyBrowserBase)component;
|
||||
final PsiElement[] elements = hierarchyBrowserBase.getAvailableElements();
|
||||
if (elements.length > 0) {
|
||||
result.add(new LocalSearchScope(elements, "Hierarchy '" + name + '\''));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static SearchScope getSelectedFilesScope(final Project project, @Nullable DataContext dataContext) {
|
||||
final VirtualFile[] filesOrDirs = dataContext == null ? null : CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
|
||||
|
||||
Reference in New Issue
Block a user