27

I have two methods in my code base. I would like to figure out, if there exists a path in which one will be called from the other. Is there some way to achieve this easily in IntelliJ without digging manually through call hierarchies?

3
  • Would it help to run a unit test with code coverage, and see if the second method turns green? Commented Jan 18, 2016 at 7:35
  • 2
    No, the code has hundreds of possible code paths. Right now I am only trying to determine if a method could be called, not whether it definitely is called in some scenario. Commented Jan 18, 2016 at 15:18
  • Well if you reach 100% code coverage then you have in fact established that ;) Commented Jan 18, 2016 at 19:13

2 Answers 2

31

The following might work for you on IntellIJ IDEA 16 and higher. It uses call hierarchies, but automates the digging;-)

  • invoke Call Hierarchy Ctrl+Alt+H on method 1.
  • click on the Callee Methods Hierarchy button in the tool window that appears to show all methods that are called by method 1.
  • click on the Expand All button a couple of times to show called methods until the desired depth.
  • Invoke Find Usages on method 2 and select the Scope Hierarchy 'Callees of 1'

Result: all calls of method 2 in method 1's call hierarchy.

Sign up to request clarification or add additional context in comments.

10 Comments

Genius! Can get really slow with wide hierarchies, and it's hard to see the actual path, but still great! Much faster than searching manually, that's for sure.
I cannot find a way to select the Hierarchy 'Callees of 1' scope in IntelliJ IDEA 2018.3.3. Does that capability still exist?
The Hierarchy scope has indeed disappeared. It's a bug.
@BasLeijdekkers the ticket now says fixed? yet I still can't find this option in 2019.2
It works for me in 2019.2. Make sure you have a hierarchy tool window open, or the scope won't appear.
|
4

I've done the following:

  • Select method 2 and invoke call hierarchy with Ctrl+Alt+H.
  • Click Expand All on the hierarchy panel
  • Click inside the hierarchy panel, and start typing the name of method 1

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.