跳转到 Eclipse IDE 中的接口实现

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

Jump into interface implementation in Eclipse IDE

eclipseinterfacepolymorphism

提问by aeq

You know how in Eclipse, pressing F3over a method will take you to its declaration? Well I have a method that is part of an interface; clicking F3over this naturally takes me to the declaring interface.

您知道在 Eclipse 中,按下F3一个方法会带您到它的声明吗?好吧,我有一个作为接口一部分的方法;点击F3这个自然会带我到声明界面。

Obviously there is an object implementing this interface and this is where the method is actually implemented. I want, when I press F3, to jump to the implementation, not the interface declaration. I know that the implementation may not be known at compile-time, so is there a way for Eclipse to show me all the classes implementing the interface so that I can select which implemented method to view? Right now when this happens I am just manually searching for this to find the implemented method.

很明显,有一个对象实现了这个接口,这就是实际实现方法的地方。我想,当我按下时F3,跳转到实现,而不是接口声明。我知道在编译时可能不知道实现,那么 Eclipse 有没有办法向我显示实现接口的所有类,以便我可以选择要查看的实现方法?现在,当发生这种情况时,我只是手动搜索以找到已实现的方法。

采纳答案by Chris Lercher

Here's what I do:

这是我所做的:

  • In the interface, move the cursor to the method name. Press F4. => Type Hierarchy view appears
  • In the lower part of the view, the method should already be selected. In its toolbar, click "Lock view and show members in hierarchy" (should be the leftmost toolbar icon).
  • In the upper part of the view, you can browse through all implementations of the method.
  • 在界面中,将光标移动到方法名称。按F4。=> 出现类型层次结构视图
  • 在视图的下部,应该已经选择了该方法。在其工具栏中,单击“锁定视图并在层次结构中显示成员”(应该是最左侧的工具栏图标)。
  • 在视图的上部,您可以浏览该方法的所有实现。

The procedure isn't very quick, but it gives you a good overview.

该过程不是很快,但它为您提供了一个很好的概述。

回答by nanda

Well... well... I hope you use Eclipse Helios, because what you asked is available on Helios.

嗯……嗯……我希望你使用 Eclipse Helios,因为你问的问题在 Helios 上是可用的。

Put your text cursor again on the method and click menu Navigate → Open Implementation. Now if you have more than one implementation of the method, you will get choice to pick which implementation to open.

再次将文本光标放在方法上,然后单击菜单导航 → 打开实现。现在,如果您有多个该方法的实现,您将可以选择打开哪个实现。

alt text

替代文字

By defining a keybinding on Preferences → General → Keys you can even use the feature easier, but before you do that, see if this shortcut is fast enough for you.

通过在 Preferences → General → Keys 上定义键绑定,您甚至可以更轻松地使用该功能,但在此之前,请查看此快捷方式对您来说是否足够快。

Press Ctrl + click and hold. Now move your mouse over the same method. Tadam… you will get choice.

按 Ctrl + 单击并按住。现在将鼠标移到相同的方法上。Tadam ......你会得到选择。

alt text

替代文字

If you pick Open Implementation you'll get the same choice as before.

如果您选择 Open Implementation,您将得到与以前相同的选择。

回答by Jonathan

Press Ctrl+ Ton the method name (rather than F3). This gives the type hierarchy as a pop-up so is slightly faster than using F4and the type hierarchy view.

在方法名称上按Ctrl+ T(而不是F3)。这将类型层次结构作为弹出窗口提供,因此比使用F4类型层次结构视图稍快。

Also, when done on a method, subtypes that don't implement/override the method will be greyed out, and when you double click on a class in the list it will take you straight to the method in that class.

此外,在方法上完成后,未实现/覆盖该方法的子类型将变灰,当您双击列表中的类时,它将直接带您到该类中的方法。

回答by Lukasz Frankowski

There's a big productivity boost if you add an Alt+ F3key binding to the Open Implementation feature, and just use F3to go to interfaces, and Alt+ F3to go to implementations.

如果您将Alt+F3键绑定添加到 Open Implementation 功能,并且仅用于F3转到接口,而使用Alt+F3转到实现,则会大大提高生产力。

Open implementation keybinding

打开实现键绑定

回答by Roland

Highlight an interface and use Ctrl+Tto open "Quick Type Hierarchy".

突出显示界面并使用Ctrl+T打开“Quick Type Hierarchy”。

回答by tbraun

ctrl + mouse hover + click "Open Implementation"

On ctrl + hover, you should see the following menu:

在 上ctrl + hover,您应该会看到以下菜单:

enter image description here

在此处输入图片说明

Tested on Eclipse Mars.2 (4.5.2)

在 Eclipse Mars.2 (4.5.2) 上测试

回答by Mangusta

Here is what I do:

这是我所做的:

I press command (on Mac, probably control on PC) and then hover over the method or class. When you do this a popup window will appear with the choices "Open Declaration", "Open Implementation", "Open Return Type". You can then click on what you want and Eclipse brings you right there. I believe this works for version 3.6 and up.

我按下命令(在 Mac 上,可能在 PC 上控制)然后将鼠标悬停在方法或类上。执行此操作时,将出现一个弹出窗口,其中包含“打开声明”、“打开实现”、“打开返回类型”选项。然后,您可以单击您想要的内容,Eclipse 会将您带到那里。我相信这适用于 3.6 及更高版本。

It is just as quick as IntelliJ I think.

它和我认为的 IntelliJ 一样快。

回答by supernova

I always use this implementors plugin to find all the implementation of an Interface

我总是使用这个实现者插件来查找接口的所有实现

http://eclipse-tools.sourceforge.net/updates/

http://eclipse-tools.sourceforge.net/updates/

it's my favorite and the best

这是我最喜欢和最好的

回答by zvikico

If you are really looking to speed your code navigation, you might want to take a look at nWire for Java. It is a code exploration plugin for Eclipse. You can instantly see all the related artifacts. So, in that case, you will focus on the method call and instantly see all possible implementations, declarations, invocations, etc.

如果您真的希望加快代码导航速度,您可能需要查看nWire for Java。它是 Eclipse 的代码探索插件。您可以立即看到所有相关的工件。因此,在这种情况下,您将专注于方法调用并立即看到所有可能的实现、声明、调用等。