如何查看使用 Java 在 Eclipse 中调用公共方法的位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3839726/
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-08-14 05:41:40  来源:igfitidea点击:

How to see from where a public method is called in Eclipse using Java?

javaeclipsekeyboard-shortcutsmethod-call

提问by Jonas

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.

我正在 Eclipse 中开发一个 Java 项目。有时,当我进行重构时,我希望从其他哪些类中查看公共方法被调用。

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?

有一种原始的方法可以做到这一点,我现在正在使用它。我可以注释掉该方法并查看 Eclipse 中哪些类存在错误。在 Eclipse 中有没有更好的方法来做到这一点?例如,通过选择方法签名并通过快捷键运行命令?

采纳答案by Jon Skeet

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

单击方法名称,然后按Ctrl+ Alt+ 调H出 Call Hierarchy 视图。

回答by unholysampler

Search > References > Workspace

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

这将在对方法的每个引用的搜索视图中构建结果树。热键是Shift+ Ctrl+G

回答by abyx

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

您还可以使用Ctrl+ Shift+G的“查找工作区参考”

回答by Derek Lesho

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.

你可以做的另一件事是让它抛出一个异常(public void test() throws Exception{}),这样 eclipse 就会在调用该方法的每个地方放置错误(只要它不在 try/catch 块中或它抛出例外),这种方式仅适用于您想在项目中搜索类的情况。

回答by S Krishna

Cntrl + Shift + G

Ctrl + Shift + G

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

这显示了调用的位置以及层次结构。

enter image description here

在此处输入图片说明