2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.ide
.hierarchy
.call
;
18 import com
.intellij
.ide
.hierarchy
.CallHierarchyBrowserBase
;
19 import com
.intellij
.ide
.hierarchy
.HierarchyNodeDescriptor
;
20 import com
.intellij
.ide
.hierarchy
.HierarchyTreeStructure
;
21 import com
.intellij
.ide
.hierarchy
.JavaHierarchyUtil
;
22 import com
.intellij
.ide
.util
.treeView
.NodeDescriptor
;
23 import com
.intellij
.openapi
.actionSystem
.ActionGroup
;
24 import com
.intellij
.openapi
.actionSystem
.ActionManager
;
25 import com
.intellij
.openapi
.actionSystem
.ActionPlaces
;
26 import com
.intellij
.openapi
.actionSystem
.IdeActions
;
27 import com
.intellij
.openapi
.diagnostic
.Logger
;
28 import com
.intellij
.openapi
.project
.Project
;
29 import com
.intellij
.psi
.PsiElement
;
30 import com
.intellij
.psi
.PsiMethod
;
31 import com
.intellij
.ui
.PopupHandler
;
32 import org
.jetbrains
.annotations
.NotNull
;
35 import javax
.swing
.tree
.DefaultMutableTreeNode
;
36 import java
.util
.Comparator
;
39 public final class CallHierarchyBrowser
extends CallHierarchyBrowserBase
{
41 private static final Logger LOG
= Logger
.getInstance("#com.intellij.ide.hierarchy.call.CallHierarchyBrowser");
43 public CallHierarchyBrowser(final Project project
, final PsiMethod method
) {
44 super(project
, method
);
47 protected void createTrees(@NotNull final Map
<String
, JTree
> type2TreeMap
) {
48 ActionGroup group
= (ActionGroup
)ActionManager
.getInstance().getAction(IdeActions
.GROUP_CALL_HIERARCHY_POPUP
);
49 final JTree tree1
= createTree(false);
50 PopupHandler
.installPopupHandler(tree1
, group
, ActionPlaces
.CALL_HIERARCHY_VIEW_POPUP
, ActionManager
.getInstance());
51 final BaseOnThisMethodAction baseOnThisMethodAction
= new BaseOnThisMethodAction();
52 baseOnThisMethodAction
53 .registerCustomShortcutSet(ActionManager
.getInstance().getAction(IdeActions
.ACTION_CALL_HIERARCHY
).getShortcutSet(), tree1
);
54 type2TreeMap
.put(CALLEE_TYPE
, tree1
);
56 final JTree tree2
= createTree(false);
57 PopupHandler
.installPopupHandler(tree2
, group
, ActionPlaces
.CALL_HIERARCHY_VIEW_POPUP
, ActionManager
.getInstance());
58 baseOnThisMethodAction
59 .registerCustomShortcutSet(ActionManager
.getInstance().getAction(IdeActions
.ACTION_CALL_HIERARCHY
).getShortcutSet(), tree2
);
60 type2TreeMap
.put(CALLER_TYPE
, tree2
);
63 protected PsiElement
getElementFromDescriptor(@NotNull HierarchyNodeDescriptor descriptor
) {
64 if (descriptor
instanceof CallHierarchyNodeDescriptor
) {
65 CallHierarchyNodeDescriptor nodeDescriptor
= (CallHierarchyNodeDescriptor
)descriptor
;
66 return nodeDescriptor
.getEnclosingElement();
72 protected PsiElement
getOpenFileElementFromDescriptor(@NotNull HierarchyNodeDescriptor descriptor
) {
73 if (descriptor
instanceof CallHierarchyNodeDescriptor
) {
74 CallHierarchyNodeDescriptor nodeDescriptor
= (CallHierarchyNodeDescriptor
)descriptor
;
75 return nodeDescriptor
.getTargetElement();
80 protected PsiElement
getEnclosingElementFromNode(final DefaultMutableTreeNode node
) {
81 if (node
== null) return null;
82 final Object userObject
= node
.getUserObject();
83 if (!(userObject
instanceof CallHierarchyNodeDescriptor
)) return null;
84 return ((CallHierarchyNodeDescriptor
)userObject
).getEnclosingElement();
87 protected boolean isApplicableElement(@NotNull final PsiElement element
) {
88 return element
instanceof PsiMethod
;
91 protected HierarchyTreeStructure
createHierarchyTreeStructure(@NotNull final String typeName
, @NotNull final PsiElement psiElement
) {
92 if (CALLER_TYPE
.equals(typeName
)) {
93 return new CallerMethodsTreeStructure(myProject
, (PsiMethod
)psiElement
, getCurrentScopeType());
95 else if (CALLEE_TYPE
.equals(typeName
)) {
96 return new CalleeMethodsTreeStructure(myProject
, (PsiMethod
)psiElement
, getCurrentScopeType());
99 LOG
.error("unexpected type: " + typeName
);
104 protected Comparator
<NodeDescriptor
> getComparator() {
105 return JavaHierarchyUtil
.getComparator(myProject
);
108 public static final class BaseOnThisMethodAction
extends CallHierarchyBrowserBase
.BaseOnThisMethodAction
{