Skip to content

Commit 3cc2307

Browse files
authored
Merge pull request #144 from unv-unv/hierarchy-refactoring
Hierarchy refactoring
2 parents 4a5a978 + 082a9b3 commit 3cc2307

20 files changed

Lines changed: 1444 additions & 1539 deletions

plugin/src/main/java/com/intellij/java/impl/ide/hierarchy/JavaHierarchyUtil.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,20 @@
3131
* @author yole
3232
*/
3333
public class JavaHierarchyUtil {
34-
private JavaHierarchyUtil() {
35-
}
34+
private JavaHierarchyUtil() {
35+
}
3636

37-
@Nullable
38-
public static String getPackageName(final PsiClass psiClass) {
39-
final PsiFile file = psiClass.getContainingFile();
40-
if (file instanceof PsiClassOwner) {
41-
return ((PsiClassOwner) file).getPackageName();
42-
} else {
43-
return null;
37+
@Nullable
38+
public static String getPackageName(PsiClass psiClass) {
39+
if (psiClass.getContainingFile() instanceof PsiClassOwner classOwner) {
40+
return classOwner.getPackageName();
41+
}
42+
return null;
4443
}
45-
}
4644

47-
public static Comparator<NodeDescriptor> getComparator(Project project) {
48-
if (HierarchyBrowserManager.getInstance(project).getState().SORT_ALPHABETICALLY) {
49-
return AlphaComparator.INSTANCE;
50-
} else {
51-
return SourceComparator.INSTANCE;
45+
public static Comparator<NodeDescriptor> getComparator(Project project) {
46+
HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(project).getState();
47+
assert state != null;
48+
return state.SORT_ALPHABETICALLY ? AlphaComparator.INSTANCE : SourceComparator.INSTANCE;
5249
}
53-
}
5450
}

plugin/src/main/java/com/intellij/java/impl/ide/hierarchy/call/CallHierarchyBrowser.java

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,71 +36,69 @@
3636
import java.util.Map;
3737

3838
public class CallHierarchyBrowser extends CallHierarchyBrowserBase {
39-
private static final Logger LOG = Logger.getInstance(CallHierarchyBrowser.class);
39+
private static final Logger LOG = Logger.getInstance(CallHierarchyBrowser.class);
4040

41-
public CallHierarchyBrowser(@Nonnull Project project, @Nonnull PsiMethod method) {
42-
super(project, method);
43-
}
44-
45-
@Override
46-
protected void createTrees(@Nonnull final Map<String, JTree> type2TreeMap) {
47-
ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_CALL_HIERARCHY_POPUP);
48-
final JTree tree1 = createTree(false);
49-
PopupHandler.installPopupHandler(tree1, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
50-
final BaseOnThisMethodAction baseOnThisMethodAction = new BaseOnThisMethodAction();
51-
baseOnThisMethodAction
52-
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree1);
53-
type2TreeMap.put(CALLEE_TYPE, tree1);
41+
public CallHierarchyBrowser(@Nonnull Project project, @Nonnull PsiMethod method) {
42+
super(project, method);
43+
}
5444

55-
final JTree tree2 = createTree(false);
56-
PopupHandler.installPopupHandler(tree2, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
57-
baseOnThisMethodAction
58-
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree2);
59-
type2TreeMap.put(CALLER_TYPE, tree2);
60-
}
45+
@Override
46+
protected void createTrees(@Nonnull Map<String, JTree> type2TreeMap) {
47+
ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_CALL_HIERARCHY_POPUP);
48+
JTree tree1 = createTree(false);
49+
PopupHandler.installPopupHandler(tree1, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
50+
BaseOnThisMethodAction baseOnThisMethodAction = new BaseOnThisMethodAction();
51+
baseOnThisMethodAction
52+
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree1);
53+
type2TreeMap.put(CALLEE_TYPE, tree1);
6154

62-
@Override
63-
protected PsiElement getElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
64-
if (descriptor instanceof CallHierarchyNodeDescriptor) {
65-
CallHierarchyNodeDescriptor nodeDescriptor = (CallHierarchyNodeDescriptor)descriptor;
66-
return nodeDescriptor.getEnclosingElement();
55+
JTree tree2 = createTree(false);
56+
PopupHandler.installPopupHandler(tree2, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
57+
baseOnThisMethodAction
58+
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree2);
59+
type2TreeMap.put(CALLER_TYPE, tree2);
6760
}
68-
return null;
69-
}
7061

71-
@Override
72-
protected PsiElement getOpenFileElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
73-
if (descriptor instanceof CallHierarchyNodeDescriptor) {
74-
CallHierarchyNodeDescriptor nodeDescriptor = (CallHierarchyNodeDescriptor)descriptor;
75-
return nodeDescriptor.getTargetElement();
62+
@Override
63+
protected PsiElement getElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
64+
if (descriptor instanceof CallHierarchyNodeDescriptor nodeDescriptor) {
65+
return nodeDescriptor.getEnclosingElement();
66+
}
67+
return null;
7668
}
77-
return null;
78-
}
7969

80-
@Override
81-
protected boolean isApplicableElement(@Nonnull final PsiElement element) {
82-
return element instanceof PsiMethod;
83-
}
84-
85-
@Override
86-
protected HierarchyTreeStructure createHierarchyTreeStructure(@Nonnull final String typeName, @Nonnull final PsiElement psiElement) {
87-
if (CALLER_TYPE.equals(typeName)) {
88-
return new CallerMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());
70+
@Override
71+
protected PsiElement getOpenFileElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
72+
if (descriptor instanceof CallHierarchyNodeDescriptor nodeDescriptor) {
73+
return nodeDescriptor.getTargetElement();
74+
}
75+
return null;
8976
}
90-
else if (CALLEE_TYPE.equals(typeName)) {
91-
return new CalleeMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());
77+
78+
@Override
79+
protected boolean isApplicableElement(@Nonnull PsiElement element) {
80+
return element instanceof PsiMethod;
9281
}
93-
else {
94-
LOG.error("unexpected type: " + typeName);
95-
return null;
82+
83+
@Override
84+
protected HierarchyTreeStructure createHierarchyTreeStructure(@Nonnull String typeName, @Nonnull PsiElement psiElement) {
85+
if (CALLER_TYPE.equals(typeName)) {
86+
return new CallerMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());
87+
}
88+
else if (CALLEE_TYPE.equals(typeName)) {
89+
return new CalleeMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());
90+
}
91+
else {
92+
LOG.error("unexpected type: " + typeName);
93+
return null;
94+
}
9695
}
97-
}
9896

99-
@Override
100-
protected Comparator<NodeDescriptor> getComparator() {
101-
return JavaHierarchyUtil.getComparator(myProject);
102-
}
97+
@Override
98+
protected Comparator<NodeDescriptor> getComparator() {
99+
return JavaHierarchyUtil.getComparator(myProject);
100+
}
103101

104-
public static final class BaseOnThisMethodAction extends CallHierarchyBrowserBase.BaseOnThisMethodAction {
105-
}
102+
public static final class BaseOnThisMethodAction extends CallHierarchyBrowserBase.BaseOnThisMethodAction {
103+
}
106104
}

0 commit comments

Comments
 (0)