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?
- Would it help to run a unit test with code coverage, and see if the second method turns green?vikingsteve– vikingsteve2016-01-18 07:35:16 +00:00Commented Jan 18, 2016 at 7:35
- 2No, 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.gruszczy– gruszczy2016-01-18 15:18:34 +00:00Commented Jan 18, 2016 at 15:18
- Well if you reach 100% code coverage then you have in fact established that ;)vikingsteve– vikingsteve2016-01-18 19:13:44 +00:00Commented Jan 18, 2016 at 19:13
Add a comment |
2 Answers
The following might work for you on IntellIJ IDEA 16 and higher. It uses call hierarchies, but automates the digging;-)
- invoke
Call HierarchyCtrl+Alt+H on method 1. - click on the
Callee Methods Hierarchybutton in the tool window that appears to show all methods that are called by method 1. - click on the
Expand Allbutton a couple of times to show called methods until the desired depth. - Invoke
Find Usageson method 2 and select the ScopeHierarchy 'Callees of 1'
Result: all calls of method 2 in method 1's call hierarchy.
10 Comments
Mark
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.
cybersam
I cannot find a way to select the
Hierarchy 'Callees of 1' scope in IntelliJ IDEA 2018.3.3. Does that capability still exist?Bas Leijdekkers
The Hierarchy scope has indeed disappeared. It's a bug.
kennyg
@BasLeijdekkers the ticket now says fixed? yet I still can't find this option in 2019.2
Bas Leijdekkers
It works for me in 2019.2. Make sure you have a hierarchy tool window open, or the scope won't appear.
|