Java ctrl-click 转到我单击的方法的声明。对于具有一个实现的接口,我如何直接转到该实现?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2105979/
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
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?
提问by HappyEngineer
I often have to debug java code which was written so that there is an interface and exactly one implementation of that interface.
我经常不得不调试编写的 Java 代码,以便有一个接口和该接口的一个实现。
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.
例如,将有一个接口 Foo,其中包含一个名为 FooImpl 的实现。在下面的代码中,如果我按住 ctrl 单击 doThings,它会跳转到 Foo.java,而当我真的想转到 FooImpl.java 来查看实现时。
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.
当我最终到达界面时,我必须使用 ctrl-shift-r 打开 FooImpl。如果我可以在 doThings 上执行一些 lick ctrl-alt-click 并最终进入 FooImpl.java ,那就太好了。如果工作区中有多个实现,那么它可能会弹出一个框告诉我它们是什么。
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.
eclipse中是否有插件或现有功能可以做到这一点?我知道我可以转到 Foo.java,然后获取层次结构并转到实现,但是当接口只有一个实现时,点击次数比必要的要多。
采纳答案by Micke
The Implementorsplugin 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.
该实施者插件确实非常正是你要求什么。如果只有一个实现它会直接打开它,否则它会让你选择。
回答by meriton
- Move the cursor to the method call
- Press Ctrl+ T
- Select your desired implementation
- Hit Enter
- 将光标移动到方法调用处
- 按Ctrl+T
- 选择你想要的实现
- 打 Enter
This also works if there are several implementors.
如果有多个实现者,这也适用。
回答by Stephen Denne
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:
在 Eclipse 3.5 中,当您doThings
按住 control 键的同时将鼠标悬停在上面时,会出现一个弹出框,您可以点击以下两个选项:
- Open Declaration
- Open Implementation
- 公开声明
- 开放实施
There's a screenshot as the second section of the Eclipse 3.5 New & Noteworthy page for JDT:
JDT的Eclipse 3.5 New & Noteworthy 页面的第二部分有一个屏幕截图:
回答by Morgan Courbet
Go to Window> Preferences> General> Editors> Text Editors> Hyperlinking, and uncheck Open Declaration.
转到Window> Preferences> General> Editors> Text Editors> Hyperlinking,然后取消选中Open Declaration。
From now on, when you hold Ctrlwhile 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 XXXbox, if more than one implementation exists).
从现在开始,当您将Ctrl鼠标悬停在方法名称上时按住,将显示以下弹出窗口。只需单击方法名称,就会打开实现(或一个实现 XXX的类型框,如果存在多个实现)。
You will still be able to use the Open Declarationfeature by pressing F3.
您仍然可以通过按来使用Open Declaration功能F3。
回答by didinino
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).
在 Eclipse IDE for C/C++ Developers Version: Oxygen.3a Release (4.7.3a) 我看到Ctrl+ Tab(Toggle Source/Header) 对我有用(虽然不是直接的,但它是一种解决方法)。