Find methods calls in Eclipse project
Asked Answered
A

6

91

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?

Alkalify answered 11/3, 2011 at 4:37 Comment(1)
See also: #4650521Mistymisunderstand
M
125

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

Mistymisunderstand answered 11/3, 2011 at 4:39 Comment(4)
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! :SMetage
in my eclipse here (mars) the shortcut is ctrl+alt+h :)Cutwork
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. ThanksWink
SHORTCUT: Ctrl+Shift+HWhereas
K
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

Koralie answered 11/3, 2011 at 4:40 Comment(2)
...which opens call hierarchy.Metage
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. ThanksWink
E
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.

Evangelical answered 20/12, 2012 at 6:0 Comment(0)
A
9

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

Accomplished answered 11/3, 2011 at 4:40 Comment(0)
B
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.

Blavatsky answered 4/5, 2015 at 9:44 Comment(0)
M
4

Right click on method and click on Open call Hierarchy

eclipse right click call hierarchy

Metronome answered 9/8, 2018 at 5:38 Comment(2)
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. ThanksWink
@Wink - Please do "mvn clean install". Then try again. It might be happening because your project is not build properly.Metronome

© 2022 - 2024 — McMap. All rights reserved.