'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 there any better way to do this in Eclipse? E.g. by selecting the method signature and run a command by a key-shortcut?



Solution 1:[1]

You can also use Ctrl+Shift+G for "Find References in Workspace"

Solution 2:[2]

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

Solution 3:[3]

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.

Solution 4:[4]

Cntrl + Shift + G

This shows where the call is made along with the hierarchy.

enter image description here

Solution 5:[5]

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.

Callee call hierarchy -- https://www.eclipse.org/eclipse/news/4.23/images/callee_on_implementations.png

This behavior can be controlled from following preference

Call hierarchy preference -- https://www.eclipse.org/eclipse/news/4.23/images/callee_preference.png

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 abyx
Solution 2 Jonas
Solution 3 Derek Lesho
Solution 4 S Krishna
Solution 5 VonC