Explain Codes LogoExplain Codes Logo

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

java
intellij-idea
class-hierarchy
shortcuts
Nikita BarsukovbyNikita Barsukov·Nov 30, 2024
TLDR

To reveal the inheritance hierarchy in IntelliJ IDEA, utilize the shortcut Ctrl + H (Cmd + H on macOS) when your cursor is situated on your target class name. This action triggers a hierarchy pane - with superclasses nestled atop, and subclasses resting beneath the selected class. Expedite toggling between the superclasses and subtypes with the Alt + Home and Alt + End keys respectively.

// Cursor on MyClass, hits Ctrl + H public class MyClass {}

Boost your class hierarchy bird's-eye view with the Float and Unpin options.

Enhancing Navigation

Rapid fire shortcuts

Speed up your hierarchy exploration in IntelliJ IDEA with these mighty shortcuts:

  • Ctrl + Alt + B: Drills down into subclasses of the highlighted class.
  • Ctrl + Alt + U: Unveils a diagrammed overview of the class's hierarchy.
  • Alt + F7: Unearths usages of the class across the project, providing invaluable insight.

Not enough? Ctrl + Shift + A is your gateway to discover an even broader range of features, shortcuts and best practices for masterful navigation.

Implement and override methods

Encountering interfaces presenting method inheritance? Use Override/Implement ( Code -> Override/Implement ) to generate the methods' fickles.

// selects class, triggers implement methods. "No keyboard was harmed in this process." public class SubClass implements MyInterface {}

Mind the gap between IntelliJ and Eclipse

For our Eclipse expatriates, you might be missing your good ol' Ctrl + T for a quick class hierarchy peek. Have no worries! It's not exactly apples to apples, but Ctrl + H in IntelliJ IDEA offers similar capabilites coupled with a host of complementary shortcuts.

Master live templates and boost productivity

Live Templates and Find Usages are your companions on this journey, crunching your code exploration and optimizing your workflow.

Problem Solving and Troubleshooting

Class not responding? No problem!

Stumble upon a non-responsive hierarchy view or an incomplete tree structure? Quite common, though easily rectified. Take a breather and try invalidating caches (File -> Invalidate Caches / Restart). If still in a muddle, ensure all necessary project dependencies are in place and correctly configured.

For those of you trekking through large hierarchies, IntelliJ IDEA boasts features like "Scroll from Source" and collapse/expand nodes for your navigation ease. Remember, the ball's in your court; you can always tweak the display settings!

Jazz it up with diagrams

If traditional hierarchy views don't quite cut it for you, go graphic! Dive into the Class Hierarchy Diagram for an interactable, visual representation of your class relationships.