开发者

How do I get the caller(s) of a method without running this system (written in JAVA)

In java, How can I get the caller(s) of a method without running this system. My purpose is to find the callers of some methods (around 150 methods) and want to get the name of all callers of each method. Is it possible to do that?

Is there possible way to do it ( that is not to use call hierarchy or reference in Eclipse because I 开发者_StackOverflow社区need to find the callers of many methods and record it to my excel file.)?

Thank you very much.


In Eclipse, you can do this by right-clicking the method, and choosing "Open Call Hierarchy".


Also, in Eclipse, you can do this by right-clicking the method, and choosing "references" -> "XXX"


As David mentioned, this is called the Call Hierarchy. You can access it from the right-click menu, or just use the keyboard shortcut: put your cursor on the method name, then press Ctrl + Alt + H.


In Eclipse, you can do this by right-clicking the method, and choosing "Open Call Hierarchy".

See 5 options given on right side top of that panel (Refresh) (Cancel Current Search) (Show Caller Hierarchy) (Show Callee Hierarchy) (Show History List)

For You the 3rd option will work..


In eclipse you can right click on the method name and click 'Open Call Hierarchy'. Another panel opens and select 'Open caller hierarchy'


Bit late to the party, but based on your updated question and comment, you want to retrieve the names of all callers of multiple methods in one go (and not have to do the same thing, i.e. open Call Hierarchy, 150 times) and end up with something in a format you can use in a spreadsheet.

Here's how to do that with Eclipse for anyone facing the same issue (as I did recently):

  1. Get all the methods whose callers you're interested in into the same view. If they're all in the same class, the Outline view will do, otherwise do a search and get all your methods to show in the Search results view - you can specify all sorts of interesting criteria in there, in your case you might want to search for methods in selected resources (select your classes in the Package Explorer first).

    How do I get the caller(s) of a method without running this system (written in JAVA)

  2. Select all the methods whose callers you're interested in in that view. Hold down Ctrl and click to multi-select, or do Ctrl+A to Select all and then de-select the ones you don't want with Ctrl+Shift+Click.

  3. Open the Call Hierarchy on all those methods. Either drag those selected methods onto the Call Hierarchy view, or use Ctrl+Alt+H, or use the context menu. This will show all the callers of all those methods. (If you want to dive deeper, expand as required to retrieve callers of callers, etc.)

  4. Select all in the Call Hierarchy view. Just do Ctrl+A while the view has focus.

  5. Copy the methods' qualified names to the clipboard. There's no keyboard shortcut for this by default, but you can right-click on the selected files and select Copy Qualified Name. You'll end up with a bunch of lines of the format <package name>.<class name>.<method name>().

  6. Paste into your favourite text editor or spreadsheet and manipulate as required.

Tested in Eclipse neon.


In Netbeans, right click on the method and go to "find usages". Alternatively, click on the method name and then hit alt+F7.

EDIT: Oops, just seen this is tagged for eclipse and not netbeans. Still, I'll leave it here in case it's useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜