46

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • 11
    `Ctrl+Shift+G` shows you from where the method is being called whereas `Ctrl+Alt+H` shows calls from the method in the workspace. – Prince Jan 09 '14 at 17:11
  • 1
    @Prince ah that's what I've been looking for for ages. – snowe Feb 28 '14 at 20:17

6 Answers6

71

Click on the method name, then press Ctrl+Alt+H to bring up the Call Hierarchy view.

Jonas
  • 121,568
  • 97
  • 310
  • 388
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • @AdamParkin: I would imagine that bringing up the context menu will show you the shortcuts available. – Jon Skeet Nov 27 '12 at 17:38
  • 1
    Actually figured it out: it's under Navigate -> Call Hierarchy, or the shortcut key is CTRL+option+H – Adam Parkin Nov 27 '12 at 17:51
  • `Ctrl+Shift+G` shows you from where the method is being called whereas `Ctrl+Alt+H` shows calls from the method in the workspace. – Prince Jan 09 '14 at 17:07
  • 1
    @Prince: Ctrl+Alt+H does either - although I typically use it to show calls *to* the method rather than calls *from* the method. – Jon Skeet Jan 09 '14 at 18:39
  • @Prince : `Ctrl+Alt+H` gives me the calls only from current file which is open, i want to know all the calls being made to a function in a project (let's say a directory), cscope does the job but is there any way to do this in eclipse? (I am using C/C++ (CDT) for my project. – DarthSpeedious Jun 28 '15 at 08:06
  • 1
    @DarthSpeedious: Well if you're using C/C++, why would you expect the answer to a *Java* question to work? CDT and JDT are very different - Ctrl-Alt-H works fine showing all calls in Java... – Jon Skeet Jun 28 '15 at 08:14
  • Thanks Ctrl+Alt+H work fine in eclipse, i have tested for java – one Jul 18 '15 at 19:09
12

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

abyx
  • 69,862
  • 18
  • 95
  • 117
9

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

Jonas
  • 121,568
  • 97
  • 310
  • 388
unholysampler
  • 17,141
  • 7
  • 47
  • 64
0

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.

Derek Lesho
  • 318
  • 1
  • 3
  • 10
0

Cntrl + Shift + G

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

enter image description here

S Krishna
  • 1,255
  • 13
  • 9
0

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250