Intellij (or other) - Possible to see a graph/tree of all calls made in Java?
Asked Answered
A

4

35

I'm working on a project in Intellij Ultimate 14. I'm not looking to do a live debugging of the application to trace calls. The time it would take to follow all code paths would be insane. I'm hoping that Intellij has some kind of analysis tool that can provide me with all calls made within the project given a particular starting point or points. So if I start with method A(), and A calls B() and C(), and B calls D(), then I'd like to be able to have that information collected and exported/displayed somehow. I'd also like annotations on any method to be included and it would need to be able to resolve interfaces to implementations where possible (many interfaces have only one), or perhaps allow me to select an implementation if needed. I don't think Intellij has this sort of functionality built in beyond being able to find all callers/callees of a single specified method. Does such a tool exist?

Acuity answered 9/6, 2016 at 15:39 Comment(2)
Why do you want to see this?Uptotheminute
Need to graph some event/data flow in a fair amount of detail. This definitely helps to simplify the process.Acuity
L
60

In IntelliJ, when your cursor on a callable method name, pressing ctrl-alt-H will bring you to "call Hierarchy" window.

Same if you prefer menu: "Navigate->call Hierarchy"

Luttrell answered 9/6, 2016 at 15:44 Comment(6)
Well...I really should've seen that before. It's pretty close, that's for sure. I didn't realize Intellij could trace it further than one hop. Nice! Now if it could just provide info on annotations, be automated to be fed a batch of starting points, and export it somehow. Excluding calls to classes that are not directly in the project would be nice too, ie, calls made to dependencies or native Java classes. It kind of does this, but not entirely.Acuity
@Acuity my intellij's call Hierarchy window has "export to text file" button. Can you check yours?Luttrell
Nope. A number of other options, but no export. Might've been something they added later. Still, with this functionality built in as it is, I wonder if I could write a plugin that could do this without much trouble.Acuity
@Acuity ok, here the version I am working with is the latest. 2016.1.something. good luck then.Luttrell
This works okay, but I would have preferred a more visual representation like a graph etc.Giuliana
is it possible to generate entire graph of a module (or even an entire project)?Palecek
A
4

Atlas (http://www.ensoftcorp.com/atlas) is an Eclipse plugin that can do this. There is a feature called a "smart view" that does what you described. Select the "call" relation and then click on a method name and the view will display the parent and child methods in the call graph. The graph is intereactive, so if you double click on a node or edge in the graph it jumps to the corresponding source code. There are other relationships as well such as control flow and data flow, but the call graph is what you described in your question.

Atlas Smart View Screenshot

Affection answered 10/11, 2016 at 18:24 Comment(0)
N
3

There is an IntelliJ plugin called Call Graph that does this. enter image description here

Nan answered 20/3, 2023 at 22:40 Comment(1)
Not compatible with latest IntelliJ, unfortunately, says Not compatible with the version of your running IDE (Rider 2023.3.3).Hawker
D
1

This doesn't graph who calls whom in general, but for a given value you can see a tree of callers that produce or consume that value

  • To see the tree of calls that produce a value, right-click on the value and select Analyze | Analyze Data Flow to Here.
  • To see a tree of all of the calls that read a value, right-click on the value and select Analyze | Analyze Data Flow from Here.

There is also Navigate | Call Hierarchy that can switch between caller and callee trees using the buttons at the top.

Dc answered 9/6, 2016 at 16:41 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.