在Eclipse IDE中跳转到接口实现

时间:2023-02-05 13:09:58

You know how in Eclipse, pressing F3 over a method will take you to its declaration? Well I have a method that is part of an interface; clicking F3 over 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是否有办法向我展示实现接口的所有类,以便我可以选择要查看的实现方法?现在,当这种情况发生时,我只是手动搜索这个来找到实现的方法。

11 个解决方案

#1


124  

Here's what I do:

这是我做的:

  • In the interface, move the cursor to the method name. Press F4. => Type Hierarchy view appears
  • 在接口中,将光标移动到方法名。按下F4。=出现>类型层次结构视图
  • 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.
  • 在视图的上部,您可以浏览该方法的所有实现。

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

这个过程不是很快,但它给你一个很好的概述。

#2


126  

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.

再次把你的文本光标和单击菜单导航→开放实现的方法。现在,如果您有多个方法的实现,您就可以选择打开哪个实现。

在Eclipse IDE中跳转到接口实现

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.

通过定义一个keybinding偏好→一般→键您甚至可以使用该功能,但在你这样做之前,看看这个快捷方式对你来说是足够快。

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

按Ctrl +单击并保持。现在将鼠标移动到相同的方法上。塔达姆,你会有选择的。

在Eclipse IDE中跳转到接口实现

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

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

#3


65  

Press Ctrl + T on the method name (rather than F3). This gives the type hierarchy as a pop-up so is slightly faster than using F4 and 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.

同样,当对一个方法执行操作时,不实现/覆盖该方法的子类型将被设置为灰色,当您双击列表中的一个类时,它将直接将您带到该类中的方法。

#4


52  

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

如果您在开放实现特性中添加Alt + F3键绑定,并使用F3到接口,使用Alt + F3到实现,则会大大提高生产率。

在Eclipse IDE中跳转到接口实现

#5


12  

ctrl + mouse hover + click "Open Implementation"

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

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

在Eclipse IDE中跳转到接口实现

Tested on Eclipse Mars.2 (4.5.2)

在Eclipse Mars.2(4.5.2)上测试

#6


10  

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

突出显示一个界面,使用Ctrl+T打开“快速类型层次结构”。

#7


3  

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一样快。

#8


2  

See In eclipse, ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly to that implementation? for some alternative solutions.

在eclipse中可以看到,ctrl-click指向我单击的方法的声明。对于具有一个实现的接口,我如何直接到那个实现呢?一些替代方案。

  • Anyway, I think you might be looking for something like this:
  • 不管怎样,我想你可能在找这样的东西:

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

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

#9


2  

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

这是我的最爱,也是最好的

#10


0  

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.

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

#11


0  

The best solution would be Ctrl+Alt+I.

最好的解决方案是Ctrl+Alt+I。

#1


124  

Here's what I do:

这是我做的:

  • In the interface, move the cursor to the method name. Press F4. => Type Hierarchy view appears
  • 在接口中,将光标移动到方法名。按下F4。=出现>类型层次结构视图
  • 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.
  • 在视图的上部,您可以浏览该方法的所有实现。

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

这个过程不是很快,但它给你一个很好的概述。

#2


126  

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.

再次把你的文本光标和单击菜单导航→开放实现的方法。现在,如果您有多个方法的实现,您就可以选择打开哪个实现。

在Eclipse IDE中跳转到接口实现

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.

通过定义一个keybinding偏好→一般→键您甚至可以使用该功能,但在你这样做之前,看看这个快捷方式对你来说是足够快。

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

按Ctrl +单击并保持。现在将鼠标移动到相同的方法上。塔达姆,你会有选择的。

在Eclipse IDE中跳转到接口实现

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

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

#3


65  

Press Ctrl + T on the method name (rather than F3). This gives the type hierarchy as a pop-up so is slightly faster than using F4 and 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.

同样,当对一个方法执行操作时,不实现/覆盖该方法的子类型将被设置为灰色,当您双击列表中的一个类时,它将直接将您带到该类中的方法。

#4


52  

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

如果您在开放实现特性中添加Alt + F3键绑定,并使用F3到接口,使用Alt + F3到实现,则会大大提高生产率。

在Eclipse IDE中跳转到接口实现

#5


12  

ctrl + mouse hover + click "Open Implementation"

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

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

在Eclipse IDE中跳转到接口实现

Tested on Eclipse Mars.2 (4.5.2)

在Eclipse Mars.2(4.5.2)上测试

#6


10  

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

突出显示一个界面,使用Ctrl+T打开“快速类型层次结构”。

#7


3  

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一样快。

#8


2  

See In eclipse, ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly to that implementation? for some alternative solutions.

在eclipse中可以看到,ctrl-click指向我单击的方法的声明。对于具有一个实现的接口,我如何直接到那个实现呢?一些替代方案。

  • Anyway, I think you might be looking for something like this:
  • 不管怎样,我想你可能在找这样的东西:

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

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

#9


2  

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

这是我的最爱,也是最好的

#10


0  

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.

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

#11


0  

The best solution would be Ctrl+Alt+I.

最好的解决方案是Ctrl+Alt+I。