How to see from where a public method is called in Eclipse using Java?
I am working on a Java project in Eclipse. Sometimes when I do refactoring I would like to see from what other classes a public method is called.
There is a primitive way to do this, that I am using now. I can comment out the method and see in what classes there is an error in Eclipse. Is 开发者_JS百科there any better way to do this in Eclipse? E.g. by selecting the method signature and run a command by a key-shortcut?
Click on the method name, then press Ctrl+Alt+H to bring up the Call Hierarchy view.
You can also use Ctrl+Shift+G for "Find References in Workspace"
Search > References > Workspace
This will build a tree of results in the search view of every reference to the method. The hotkey is Shift+Ctrl+G
Another thing you could do is make it throw an exception (public void test() throws Exception{}) that way eclipse would put errors at every place that calls the method (as long as its not in a try/catch block or it throws an Exception too), this way will only work if you want to search classes in your project.
Cntrl + Shift + G
This shows where the call is made along with the hierarchy.
Eclipse 4.23 (Feb. 2022, 12 years later) does add to this view with:
Show implementations of callee
The call hierarchy view can now show implementing methods as potential callee methods when viewing callees.
This behavior can be controlled from following preference
精彩评论