When I study complex Java codes I didn’t write, I regularly write down in notepad the call stacks of some resources I find interesting for a given problem. These resources are generally methods or constants.
Here’s an example :
CONSTANT_NAME
com.company.common.context.business.Context.methodName1()
com.company.domain.web.controller.subdomain1.BusinessController.handleRequest(HttpServletRequest, HttpServletResponse)
com.company.domain.web.controller.subdomain2.BusinessController.handleRequest(HttpServletRequest, HttpServletResponse)
com.company.domain.web.controller.subdomain3.BusinessController.handleRequest(HttpServletRequest, HttpServletResponse)
com.company.common.context.business.Context.methodName2()
com.company.domain.web.controller.subdomain1.BusinessController.handleRequest(HttpServletRequest, HttpServletResponse)
com.company.domain.web.controller.subdomain3.BusinessController.handleRequest(HttpServletRequest, HttpServletResponse)
com.company.domain.web.controller.subdomain2.BusinessController.handleRequest(HttpServletRequest, HttpServletResponse)
com.company.common.context.business.Context.methodName3(Long, boolean)
com.company.domain.web.controller.services.ClassName.onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
For that purpose, I right-click in Eclipse on a constant/method and select “References”, “workspace” (shortcut CTRL+Shift+G). In the “Search” tab, I right-click on a result and select “Copy qualified Name”. I then copy it in notepad with a suitable tabulation (no tabulation for the first variable/method and an additional tabulation for each call level). If a method is called by 2 pieces of code, the same tabulation is added for the fully qualified names of the 2 calling methods.
The result looks thus a bit like java stacktraces.
Why do I do that ? Because I think it gives plenty information on some resources and allows to know in which execution context they are used. Of course, this does not work with configuration resources (xml configuration files for example).
For large programs, this manipulation can become cumbersome.
If I use debug mode in Eclipse, I can get an interesting stacktrace when a breakpoint is hit but this is just for a single case and I want more “abstraction” when I study codes.
Do you know if some tools could do that kind of job for me ?
Thanks !
EDIT : The best way I found to do it is :
- make an “open call hierarchy” on a constant/method/variable.
- expand all items by using the keyboard arrows in the “Call Hierarchy” view
- right-click on the root item and choose “Copy Expanded Hierarchy”.
You then have call stacks you can study in notepad
I’m not sure I understand your question correctly, but doesn’t “Open Call Hierarchy” (Ctrl+Alt+H) do what you want?