Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out in Eclipse if certain method is called from another method directly or indirectly?

Tags:

java

eclipse

How to find out in Eclipse if certain method is potentially invoked or reachable (directly or indirectly) from another method?

Assume I want to refactor A.one() which can be negatively influenced by a side-effect in D.four(). Therefore I'd like to find out if D.four() can potentially be invoked from A.one(). I can see which methods are called from A.one() using the Call Hierarchy. I can navigate the call tree and eventually find that A.one() calls B.two() which calls C.three() which calls D.four().

Is there a way in Eclipse to make this search somehow automatic?

ps. There's a "Filters..." option in Call Hierarchy Dialog, but it only hides matching names.

like image 932
lexicore Avatar asked Sep 15 '10 06:09

lexicore


People also ask

How do you know where a particular method is called in eclipse?

Select mymethod() and press ctrl + alt + h . To see some detailed Information about any method you can use this by selecting that particular Object or method and right click. you can see the "OpenCallHierarchy" ( Ctrl + Alt + H ).

How do you find out where a method is called?

Ctrl+Shift+G shows you from where the method is being called whereas Ctrl+Alt+H shows calls from the method in the workspace.

How do I get call hierarchy in Eclipse?

To find the references of a method, eclipse has a plugin called Open Call Hierarchy(Ctrl+Alt+H).


1 Answers

This is a modified version of the way you (@lexicore) found, that involves significantly less button punching (my changes in bold):

  • Open Call Hierarchy for A.one(), Show Callee Hierarchy.
  • Select the root node, and press the * key until the whole tree is expanded. Note that you only need to press * on the root node. This will expand the whole tree in "no time".
  • Right mouse click, Copy Expanded Hierarchy.
  • Paste into a text file.
  • Full-text search for D.four().

Notes

  • The key * expands all unexpanded leaf nodes one level.
  • The keys + and - works for expanding and closing just the selected node.
  • I've tried this on a Swedish keyboard, where * is located in a different place than on a US keyboard, but hopefully Eclipse won't care about that.

Update

Here is some documentation, where the * key is mentioned.

like image 178
Peter Jaric Avatar answered Sep 24 '22 08:09

Peter Jaric