在 Eclipse 项目中查找方法调用

我有一个包含方法 myMethod ()的类 X。我希望在当前工作区中调用 myMethod ()的所有项目中找到位置。我不能使用任何搜索函数,因为有几个类使用 myMethod () ,而且它不是静态的。因此,我需要知道这个类的对象的名称,这是不可能的,如果没有手动探索的项目。

Eclipse 对此有解决方案吗?

154071 次浏览

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

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

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

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.

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.

Right click on method and click on Open call Hierarchy

eclipse right click call hierarchy