tags:

views:

58

answers:

3

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.

A: 

The simplest way that I know of, is to navigate manually to D.four(), use the Call Hierarchy on that method and see if A.one() is contained in the hierarchy.

gedim
I'll need to manually search through the whole hierarchy to do this. A bit hard it the tree is large.
lexicore
+1  A: 

We've just encountered a way. Not really "automatic", involves a lot of ->-button punching. :)

  • Open Call Hierarchy for A.one(), Show Callee Hierarchy.
  • Start from the root, expand the whole tree by clicking the -> button many many times. Really many times. :)
  • Right mouse click, Copy Expanded Hierarchy.
  • Paste into a text file.
  • Full-text search for D.four().

I hope there are better ways not involving punching the ->-button.

lexicore
+6  A: 

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.

Peter Jaric
`*`! Thanks! My colleagues asked me to thank you sincerely. :)
lexicore
Great! I just noticed that numpad * (It's called Numpad_Multiply in Eclipse) works too.
Peter Jaric
Interestingly enough, I can not find any documentation on these key bindings. When I go into Preferences->General->Keys, where "all" key bindings are defined, these keys are not bound to anything.
Peter Jaric
Here is some documentation, where the * key is mentioned: http://eclipse-tools.sourceforge.net/call-hierarchy/usage.html
Peter Jaric