Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@
* @author yole
*/
public class JavaHierarchyUtil {
private JavaHierarchyUtil() {
}
private JavaHierarchyUtil() {
}

@Nullable
public static String getPackageName(final PsiClass psiClass) {
final PsiFile file = psiClass.getContainingFile();
if (file instanceof PsiClassOwner) {
return ((PsiClassOwner) file).getPackageName();
} else {
return null;
@Nullable
public static String getPackageName(PsiClass psiClass) {
if (psiClass.getContainingFile() instanceof PsiClassOwner classOwner) {
return classOwner.getPackageName();
}
return null;
}
}

public static Comparator<NodeDescriptor> getComparator(Project project) {
if (HierarchyBrowserManager.getInstance(project).getState().SORT_ALPHABETICALLY) {
return AlphaComparator.INSTANCE;
} else {
return SourceComparator.INSTANCE;
public static Comparator<NodeDescriptor> getComparator(Project project) {
HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(project).getState();
assert state != null;
return state.SORT_ALPHABETICALLY ? AlphaComparator.INSTANCE : SourceComparator.INSTANCE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,71 +36,69 @@
import java.util.Map;

public class CallHierarchyBrowser extends CallHierarchyBrowserBase {
private static final Logger LOG = Logger.getInstance(CallHierarchyBrowser.class);
private static final Logger LOG = Logger.getInstance(CallHierarchyBrowser.class);

public CallHierarchyBrowser(@Nonnull Project project, @Nonnull PsiMethod method) {
super(project, method);
}

@Override
protected void createTrees(@Nonnull final Map<String, JTree> type2TreeMap) {
ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_CALL_HIERARCHY_POPUP);
final JTree tree1 = createTree(false);
PopupHandler.installPopupHandler(tree1, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
final BaseOnThisMethodAction baseOnThisMethodAction = new BaseOnThisMethodAction();
baseOnThisMethodAction
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree1);
type2TreeMap.put(CALLEE_TYPE, tree1);
public CallHierarchyBrowser(@Nonnull Project project, @Nonnull PsiMethod method) {
super(project, method);
}

final JTree tree2 = createTree(false);
PopupHandler.installPopupHandler(tree2, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
baseOnThisMethodAction
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree2);
type2TreeMap.put(CALLER_TYPE, tree2);
}
@Override
protected void createTrees(@Nonnull Map<String, JTree> type2TreeMap) {
ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_CALL_HIERARCHY_POPUP);
JTree tree1 = createTree(false);
PopupHandler.installPopupHandler(tree1, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
BaseOnThisMethodAction baseOnThisMethodAction = new BaseOnThisMethodAction();
baseOnThisMethodAction
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree1);
type2TreeMap.put(CALLEE_TYPE, tree1);

@Override
protected PsiElement getElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
if (descriptor instanceof CallHierarchyNodeDescriptor) {
CallHierarchyNodeDescriptor nodeDescriptor = (CallHierarchyNodeDescriptor)descriptor;
return nodeDescriptor.getEnclosingElement();
JTree tree2 = createTree(false);
PopupHandler.installPopupHandler(tree2, group, ActionPlaces.CALL_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
baseOnThisMethodAction
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_CALL_HIERARCHY).getShortcutSet(), tree2);
type2TreeMap.put(CALLER_TYPE, tree2);
}
return null;
}

@Override
protected PsiElement getOpenFileElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
if (descriptor instanceof CallHierarchyNodeDescriptor) {
CallHierarchyNodeDescriptor nodeDescriptor = (CallHierarchyNodeDescriptor)descriptor;
return nodeDescriptor.getTargetElement();
@Override
protected PsiElement getElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
if (descriptor instanceof CallHierarchyNodeDescriptor nodeDescriptor) {
return nodeDescriptor.getEnclosingElement();
}
return null;
}
return null;
}

@Override
protected boolean isApplicableElement(@Nonnull final PsiElement element) {
return element instanceof PsiMethod;
}

@Override
protected HierarchyTreeStructure createHierarchyTreeStructure(@Nonnull final String typeName, @Nonnull final PsiElement psiElement) {
if (CALLER_TYPE.equals(typeName)) {
return new CallerMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());
@Override
protected PsiElement getOpenFileElementFromDescriptor(@Nonnull HierarchyNodeDescriptor descriptor) {
if (descriptor instanceof CallHierarchyNodeDescriptor nodeDescriptor) {
return nodeDescriptor.getTargetElement();
}
return null;
}
else if (CALLEE_TYPE.equals(typeName)) {
return new CalleeMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());

@Override
protected boolean isApplicableElement(@Nonnull PsiElement element) {
return element instanceof PsiMethod;
}
else {
LOG.error("unexpected type: " + typeName);
return null;

@Override
protected HierarchyTreeStructure createHierarchyTreeStructure(@Nonnull String typeName, @Nonnull PsiElement psiElement) {
if (CALLER_TYPE.equals(typeName)) {
return new CallerMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());
}
else if (CALLEE_TYPE.equals(typeName)) {
return new CalleeMethodsTreeStructure(myProject, (PsiMethod)psiElement, getCurrentScopeType());
}
else {
LOG.error("unexpected type: " + typeName);
return null;
}
}
}

@Override
protected Comparator<NodeDescriptor> getComparator() {
return JavaHierarchyUtil.getComparator(myProject);
}
@Override
protected Comparator<NodeDescriptor> getComparator() {
return JavaHierarchyUtil.getComparator(myProject);
}

public static final class BaseOnThisMethodAction extends CallHierarchyBrowserBase.BaseOnThisMethodAction {
}
public static final class BaseOnThisMethodAction extends CallHierarchyBrowserBase.BaseOnThisMethodAction {
}
}
Loading
Loading