ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly go to that implementation?

…衆ロ難τιáo~ 提交于 2019-11-27 00:27:16

问题


I often have to debug java code which was written so that there is an interface and exactly one implementation of that interface.

For instance there would be an interface Foo with exactly one implementation called FooImpl. In the following code if I ctrl-click on doThings it'll jump to Foo.java when I actually want to go to FooImpl.java to see the implementation.

public void doStuff(Foo foo) {
    foo.doThings();
}   

When I end up at the interface I have to use ctrl-shift-r to open up FooImpl. It'd be really nice if I could do something lick ctrl-alt-click on doThings and end up inside FooImpl.java. If there are multiple implementations in the workspace then perhaps it would just pop up a box telling me what they are.

Is there a plugin or existing function in eclipse that does this? I know that I could go to Foo.java and then get the hierarchy and go to the implementation, but that's more clicks than are necessary when there is exactly one implementation of an interface.


回答1:


The Implementors plugin does pretty much exactly what you ask for. If there is only one implementation it will open it directly, otherwise it will let you choose.




回答2:


  1. Move the cursor to the method call
  2. Press Ctrl + T
  3. Select your desired implementation
  4. Hit Enter

This also works if there are several implementors.




回答3:


Go to Window > Preferences > General > Editors > Text Editors > Hyperlinking, and uncheck Open Declaration.

From now on, when you hold Ctrl while hovering over a method name, the following popup will be displayed. Just click on the method name and the implementation will be opened (or a Types implementing XXX box, if more than one implementation exists).

You will still be able to use the Open Declaration feature by pressing F3.




回答4:


In Eclipse 3.5, when you hover over doThings while holding down the control key, a pop up box gives you two options to click on:

  • Open Declaration
  • Open Implementation

There's a screenshot as the second section of the Eclipse 3.5 New & Noteworthy page for JDT:




回答5:


In Eclipse IDE for C/C++ Developers Version: Oxygen.3a Release (4.7.3a) I saw Ctrl+Tab (Toggle Source/Header) which worked for me (although not directly but its a workaround).



来源:https://stackoverflow.com/questions/2105979/ctrl-click-goes-to-the-declaration-of-the-method-i-clicked-for-interfaces-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!