We have used our favorite IDEs (IntelliJ and Eclipse) to examine the call hierarchy tree of the source code in order to get a tree view of all the callers and callees of the selected method. in this  article we described in detail how we did it.

1. IntelliJ

To view the call hierarchy of selected methods in IntelliJ, we first need to build at least one hierarchy in the Navigate menu and then view the hierarchy of callers and callees in the Hierarchy tool window.

1.1. Build a hierarchy of method calls

  1. With your mouse, move to the method you are interested in.
  2. On the main menu select Navigate and then click on Call Hierarchy. Alternatively you can build a hierarchy by using a keyboard shortcut Ctrl+Alt+H.
    intellij build call hierarchy​

1.2. View the hierarchy

  1. With your mouse, move to the method you are interested in.
  2. Click on View on the main menu, then select Tool Windows and Hierarchy. Alternatively, you can access the view by using a keyboard shortcut Alt+8.
    intellij hierarchy tool win
  3. Depending on the method you selected, you should be able to see a hierarchy similar to this:
    intellij hierarchy callees main
  4. By default you will see the Callee Methods Hierarchy. If you'd like to switch to Caller Methods Hierarchy, select the top left button on the image above. 

2. Eclipse

To open call hierarchy in Eclipse, select a method, click on Navigate on the main menu and select Open Call Hierarchy. Alternatively use a keyboard shortcut Ctrl+Alt+H.

eclipse call hierarchy menu

2.1. Call hierarchy view

On the image below you can see an example of a call hierarchy, displaying all callees of the selected method getIntegerArrayList

eclipse call hierarchy example

If you'd like to see all callers of a selected method, you can use the menu on the right hand side to switch to Caller Hierarchy.

eclipse switch call hierarchy view

After you switch, you will see all the callers of the selected method, in our example on the image below we looked into method parseInt.

eclipse call hierarchy callers