Eclipse - 查看一个类的哪些方法在另一个类中使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6530750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:32:12  来源:igfitidea点击:

Eclipse - see which methods of one class are used in another?

javaeclipse

提问by Konrad Garus

With Eclipse, given the following classes:

使用 Eclipse,给出以下类:

class Dao {
    public void one() {}
    public void two() {}
    public void three() {}
}

class ServiceA {
    Dao dao;
    public void a() {
        dao.one();
        dao.two();
    }
    public void b() {
        dao.one();
    }
}

class ServiceB {
    Dao dao;
    public void z() {
        dao.two();
        dao.three();
    }
}

... is it possible to see a list of all Daomethods referenced from ServiceA? I'm looking for one view that will show that ServiceAuses one()and two()(don't mind it if one()is listed twice).

...是否可以看到所有Dao引用的方法的列表ServiceA?我正在寻找一个视图,该视图将显示ServiceA使用one()two()(如果one()列出两次,请不要介意)。

I know how to see callers of one specific method. I really need a list of all methods referenced within a class. Think of legacy code orders of magnitude larger: dao and services that have tens (hundreds?) of methods. I don't feel like going through call hierarchy method by method.

我知道如何查看一种特定方法的调用者。我真的需要一个类中引用的所有方法的列表。想想更大数量级的遗留代码:具有数十(数百?)个方法的 dao 和服务。我不想逐个调用层次结构方法。

回答by Vagif

Actually you can click by right mouse button at Dao method and then click at 'Open Call Hierarchy Ctrl+Alt+H' and Eclipse will find for you all Dao method calls.

实际上,您可以在 Dao 方法上单击鼠标右键,然后单击“Open Call Hierarchy Ctrl+Alt+H”,Eclipse 将为您找到所有 Dao 方法调用。

回答by knb

Konrad Garus Jun 30 '11 at 7:37 said in a comment:

Konrad Garus 2011 年 6 月 30 日 7:37 在评论中说:

Yes, except for that I need it from the opposite side. See all methods called from Service, not all calls of Dao.conreteMethod().

是的,除此之外,我需要从相反的一侧使用它。查看从 Service 调用的所有方法,而不是所有 Dao.conreteMethod() 调用。

– I need to create a new answer because I'll use two pictures to illustrate my point. (Cannot use images in comments)

– 我需要创建一个新答案,因为我将使用两张图片来说明我的观点。(评论中不能使用图片)

'Ctrl+Alt+H' brings up call hierarchy, as has been mentioned here by other people.

'Ctrl+Alt+H' 调出呼叫层次结构,正如其他人在此处提到的那样。

Then you need to click on these icons, depending on what you need:

然后您需要单击这些图标,具体取决于您的需要:

Show Callee Hierarchy

显示被调用者层次结构

And

Show Caller Hierarchy

显示呼叫者层次结构

Edit:

编辑

What about VonC's answer here(it's the one with the saw-tooth-rimmed screenshot image inside)?

VonC在这里的回答怎么样(里面有锯齿边框的截图)?

Here I've used CTRL-H to code-search for calls to Dao.one().

在这里,我使用 CTRL-H 来代码搜索对 Dao.one() 的调用。

Result: In the search result view, there's another little icon "group by type).

结果:在搜索结果视图中,还有一个小图标“按类型分组”。

code search result

代码搜索结果

回答by bhagyas

Press Ctrl+Shift+Gto perform a search which shows all the places where your method or selected class is being used.

Ctrl+Shift+G执行搜索,其中显示使用您的方法或所选类的所有位置。

Additionally, you can temporarily set all the publicmethods to privatevisibility and check the places where errors are popping up.

此外,您可以临时将所有public方法设置为private可见性并检查出现错误的位置。

回答by bhagyas

You can use a Code Coverage plugin/tool for this.

您可以为此使用代码覆盖率插件/工具。

For example:

例如:

  • Dependency Analyzer (http://www.dependency-analyzer.org/)
  • Codecover
  • UCDetector
  • FindBugs
  • PMD
  • CodePro Analytics (free from Google)
  • 依赖分析器 (http://www.dependency-analyzer.org/)
  • 代码覆盖
  • UC探测器
  • 查找错误
  • PMD
  • CodePro 分析(免费来自 Google)

回答by GuruKulki

If you right click on a method and select Open Call Hierarchy you all get the list of all the classes using the particular method.

如果您右键单击一个方法并选择 Open Call Hierarchy,您将获得使用特定方法的所有类的列表。