19

I work on a relatively complex Java project where classes commonly have four or five ancestors before Object. Given such a class, e.g. D in a hierarchy like this: Object > A > B > C > D, I would like to know what all interfaces it effectively implements. That is, I am also interested in seeing that D implements, say, Serializable even if that is declared only in the declaration of class B and even when D does not actually implement any of the methods specified by the interface (naturally, if talking about Serializable).

Some potential sources of this information I tried include:

  • using "Group by Defining Type" in the Structure window -- but that won't show empty interfaces (= interfaces without methods), and
  • the "Hierarchy" window -- but that does not include interfaces when viewing the hierarchy for a class.

Is there a way to obtain this information in IDEA without having to open files of all ancestor classes of the class in question?

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
mkorvas
  • 563
  • 3
  • 10
  • Not sure about the InteliJ but you can do it in a one line of code http://stackoverflow.com/questions/6616055/get-all-derived-interfaces-of-a-class – Egor Zhuk Feb 21 '17 at 20:36
  • see also the almost duplicate https://stackoverflow.com/questions/3990781/how-to-show-all-parents-and-subclasses-of-a-class-in-intellij-idea/9990283 – elonderin Jul 14 '21 at 14:06

2 Answers2

22

You can try

  • Open the class file.
  • Press Ctrl + H. (or just navigate through project window and press the keys.)
  • You can see the Hierarchy Diagram appears right hand side.
  • Try switch to Supertypes Hierarchy(circled in red in below image) button. :))

enter image description here

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
2

If you are fine with UML representation, then use

Press ⌥⇧⌘U or ⌥⌘U on mac

Press Ctrl+Shift+Alt+U or Ctrl+Alt+U on default windows keymap

See https://www.jetbrains.com/help/idea/2016.3/viewing-class-hierarchy-as-a-class-diagram.html

Martin Linha
  • 979
  • 9
  • 21
  • I seem to not have this option somehow. I have an IDEA v2016.2.5, but this functionality should already be there: https://www.jetbrains.com/help/idea/2016.2/viewing-class-hierarchy-as-a-class-diagram.html. However, the shortcuts do not work (I am on Linux) and I do not see that option in the context menu. If it's not caused by some plugin missing, I guess it's because this project is in fact a mix of Java and Groovy, which might not be supported by the diagramming functionality. – mkorvas Feb 22 '17 at 12:28