92

I have a class X containing method myMethod(). I would like to find locations in all projects in my current workspace where this myMethod() is being called. I cannot use any search functions as there are several classes with myMethod(), and it isn't static. Hence I need to know the name of the objects of this class, which isn't possible without manually exploring the projects.

Does Eclipse have a solution for this?

Shailesh Tainwala
  • 6,299
  • 12
  • 58
  • 69
  • 2
    See also: http://stackoverflow.com/questions/4650021/more-intelligent-eclipse-open-call-hierarchy – Thilo Mar 11 '11 at 04:42

6 Answers6

126

Go to the method in X.java, and select Open Call Hierarchy from the context menu.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • 12
    I did not know this. I was using `CTRL-G` shortcut and it wasn't working, as in it would not result the method in question being called from another method in the same class. Any ideas why this is? ...nevermind! `CTRL-SHIFT-G` is for finding references, `CTRL-G` is for finding declarations! :S – Xonatron Jan 30 '12 at 19:00
  • 4
    in my eclipse here (mars) the shortcut is ctrl+alt+h :) – thekucays Jun 07 '16 at 03:04
  • I tried all I could find, Ctrl+Shift+G, ctrl+Alt+H and bunch more but all show me "The resource is not on the build path of a Java project". So, none work. Someone suggested to right click on project in the tree and choose "build path" from context menu, but I dont see this. I am on eclipse photon. Thanks – pixel Dec 30 '19 at 20:54
58

Select mymethod() and press ctrl+alt+h.

To see some detailed Information about any method you can use this by selecting that particular Object or method and right click. you can see the "OpenCallHierarchy" (Ctrl+Alt+H). Like that many tools are there to make your work Easier like "Quick Outline" (Ctrl+O) to view the Datatypes and methods declared in a particular .java file.

To know more about this, refer this eclipse Reference

GabrielOshiro
  • 7,986
  • 4
  • 45
  • 57
Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46
  • 3
    ...which opens call hierarchy. – Xonatron Jan 30 '12 at 19:02
  • I tried all I could find, Ctrl+Shift+G, ctrl+Alt+H, Ctrl+O and bunch more but all show me "The resource is not on the build path of a Java project". So, none work. Someone suggested to right click on project in the tree and choose "build path" from context menu, but I dont see this. I am on eclipse photon. Thanks – pixel Dec 30 '19 at 20:54
10

You can also search for specific methods. For e.g. If you want to search for isEmpty() method of the string class you have to got to - Search -> Java -> type java.lang.String.isEmpty() and in the 'Search For' option use Method.

You can then select the scope that you require.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
9

Move the cursor to the method name. Right click and select References > Project or References > Workspace from the pop-up menu.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
6
select method > right click > References > Workspace/Project (your preferred context ) 

or

(Ctrl+Shift+G) 

This will show you a Search view containing the hierarchy of class and method which using this method.

Saif
  • 6,804
  • 8
  • 40
  • 61
4

Right click on method and click on Open call Hierarchy

eclipse right click call hierarchy

piet.t
  • 11,718
  • 21
  • 43
  • 52
Manjeet
  • 949
  • 14
  • 23
  • I tried all I could find, Ctrl+Shift+G, ctrl+Alt+H and bunch more but all show me "The resource is not on the build path of a Java project". So, none work. Someone suggested to right click on project in the tree and choose "build path" from context menu, but I dont see this. I am on eclipse photon. Thanks – pixel Dec 30 '19 at 20:55
  • @pixel - Please do "mvn clean install". Then try again. It might be happening because your project is not build properly. – Manjeet Dec 31 '19 at 11:39