简体   繁体   English

如何在 IntelliJ IDEA 中显示一个类的所有父类和子类?

[英]How to show all parents and subclasses of a class in IntelliJ IDEA?

When I'm editing a Java class in Eclipse, when my cursor is over a class variable, I can do Ctrl + T to have a popup that shows all its parents and subclasses.当我在 Eclipse 中编辑 Java 类时,当我的光标位于类变量上时,我可以按 Ctrl + T来弹出一个显示其所有父类和子类的弹出窗口。 What is the equivalent in IntelliJ? IntelliJ 中的等价物是什么?

Example:示例:

Use|r user = new User();

The pipe is my cursor.管道是我的光标。

Navigate |导航 | Type Hierarchy Ctrl + H will show similar information, however in the Panel. Type Hierarchy Ctrl + H将显示类似的信息,但在面板中。 You can Float and Unpin the Panel so that it appears on the fixed display position only when you use the keyboard shortcut.您可以浮动取消固定面板,使其仅在您使用键盘快捷键时出现在固定显示位置。

在行为方面,IntelliJ IDEA 中 Eclipse Ctrl + T的等价物是Ctrl + Alt + B

不是 IntelliJ IDEA 用户,但这篇博文似乎表明在 8.1.1 及更高版本中Ctrl + Alt + U将显示“快速类层次结构”。

Intellij does - in contrast to Eclipse - distinguish between type hierachies and implementation classes .与 Eclipse 相比,Intellij 确实区分了类型层次结构实现类 I'm still undecided whether this is a good thing or not (just switched over from Eclipse to Intellij myself)我仍然不确定这是否是一件好事(我自己刚刚从 Eclipse 切换到 Intellij)

On a Mac Intellij 14在 Mac Intellij 14 上

  • Ctrl + H will bring up the type hierarchy showing you sub- and supertypes Ctrl + H将显示类型层次结构,显示子类型和超类型
  • Cmd + Alt + B will show you all implementing classes and subclasses of the interface/class you're interested in Cmd + Alt + B将显示您感兴趣的接口/类的所有实现类和子类

Also try CTRL + SHIFT + A in case of any doubt.如果有任何疑问,也可以尝试CTRL + SHIFT + A。 The short cut for short cut information.快捷方式信息的快捷方式。

在 IntelliJ IDEA 12 中,导航 > 类型层次结构(默认为Ctrl + H )。

For Mac users who come here, this is the shortcut for IntelliJ 14.1.4:对于来到这里的 Mac 用户,这是 IntelliJ 14.1.4 的快捷方式:

+ H by default.默认为 + H。

For Mac Users, the shortcut is对于Mac用户,快捷方式是

^ (control) + h ^ (对照)+ h

In IntelliJ 13, it's Navigate > Implementations or CMD + ALT + B by default.在 IntelliJ 13 中,默认为Navigate > ImplementationsCMD + ALT + B。 Of course, this shortcut can be overridden in your Keymap preferences.当然,可以在您的键盘映射首选项中覆盖此快捷方式。

I don't know about prior versions, but in IntelliJ version 13 you can go into your Keymap preferences, search for "Implementations", and bind that to Ctrl + T .我不知道以前的版本,但在 IntelliJ 版本 13 中,您可以进入您的键盘映射首选项,搜索“实现”,并将其绑定到Ctrl + T It will work very much like the Eclipse equivalent.它将非常像 Eclipse 等价物一样工作。

With Eclipse, hitting Ctrl + T on a type displays its subtypes and hit again Ctrl + T displays so supertypes.使用 Eclipse,在类型上按 Ctrl + T会显示其子类型,然后再次按 Ctrl + T会显示超类型。 And so for... this is a toggle.所以对于......这是一个切换。
That is really helpful and also very straight.这真的很有帮助,也很直接。

Unfortunately with IntelliJ, the switch between the supertypes and the subtypes doesn't have any default shortcut.不幸的是,对于 IntelliJ,超类型和子类型之间的切换没有任何默认快捷方式。 So you will have to click on the icons of the hierarchy windows.因此,您必须单击层次结构窗口的图标。
If like me you favor the keyboard shortcuts to the "move cursor and click on mouse" option, I encourage you to set a binding for these two operations.如果您像我一样喜欢“移动光标并单击鼠标”选项的键盘快捷键,我鼓励您为这两个操作设置绑定。 For example Ctrl + Down for subtypes and Ctrl + Up for supertypes.例如Ctrl + Down用于子类型, Ctrl + Up用于超类型。

Where you can change the binding ("Bas" means "Down" and "Haut" means "Up") :您可以在哪里更改绑定(“Bas”表示“Down”,“Haut”表示“Up”): 投标

Note that these bindings are contextual to the "Other" context (Eclipse does have a similar enough concept).请注意,这些绑定与“其他”上下文相关(Eclipse 确实有一个足够相似的概念)。 1) In this way, enter Ctrl + T on a ArrayList type produces : 1) 这样,在ArrayList类型上输入Ctrl + T产生:

默认层次结构

2) Enter Ctrl + Down focuses on subtypes : 2) 输入Ctrl + Down重点关注子类型:

亚型焦点

3) And Enter Ctrl + Up focuses on supertypes : 3) 并输入Ctrl + Up关注超类型:

超类型焦点

In this way, I find it better than the default behavior but to be honest even with that shortcut adding, the IntelliJ feature is not as good as Eclipse which the Ctrl + T shortcut also works on methods...这样,我发现它比默认行为更好,但说实话,即使添加了快捷方式,IntelliJ 功能也不如 Eclipse 好,其中Ctrl + T快捷方式也适用于方法......

Whilst Eclipse includes the type hierarchy and class structure (methods, fields etc.) in a single view, IntelliJ splits these up: In addition to the CTRL + H (or ALT + 8 ) "Type Hierarchy" view, the other relevant IntelliJ window is called "Structure" and can be invoked via ALT + 7 (Structure Tool Window) or CTRL + F12 (Structure popup).虽然 Eclipse 在单个视图中包含类型层次结构和类结构(方法、字段等),但 IntelliJ 将它们分开:除了CTRL + H (或ALT + 8“类型层次结构”视图之外,其他相关的 IntelliJ 窗口称为“结构” ,可以通过ALT + 7 (结构工具窗口)或CTRL + F12 (结构弹出窗口)调用。

(Not a direct answer to the exact question posted but would expect others from an Eclipse background may arrive here having googled for "intellij type hierarchy", as I did.) (不是对所发布的确切问题的直接回答,但希望来自 Eclipse 背景的其他人可能会像我一样在谷歌上搜索“intellij 类型层次结构”。)

Ctrl+U - go to base class Ctrl+U - 转到基类

Ctrl+Alt+B - got to implementation. Ctrl+Alt+B - 开始实施。 Type parts of class name to narrow down the list键入部分类名以缩小列表范围

Ctrl+H - open type hierarchy tool window Ctrl+H - 打开文字层次工具窗口

Ctrl+Alt+U - peek class/interface inheritance hierarchy Ctrl+Alt+U - 查看类/接口继承层次结构

在 Eclipse 中有一个层次视图,查看菜单 View / Tool Windows / Hierarchy 或按 Alt-8 或 F4。

One more option to do this:执行此操作的另一种选择:

For Windows user:对于Windows用户:

Ctrl + Alt + Left mouse click on type, method etc. Ctrl + Alt + Left mouse click类型、方法等。

你会得到这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM