Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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.

like image 600
HappyEngineer Avatar asked Jan 20 '10 23:01

HappyEngineer


People also ask

How do I get to implementation method in IntelliJ?

To navigate to the implementation, press Ctrl+Alt+B .

How do you navigate to implement a method in eclipse?

F3 is the typical "go to implementation". For interfaces that go to the interface definition. Instead use Ctrl + T to see all implementations of the interface definition. You can then easily go to the one you want with the arrow keys and Enter.

How do you open the implementation method in STS?

With CTRL-T you get a Popup that let's you choose the implementation.

How do I get to the implementation class in Eclipse?

If you use the f3 key or ctrl+click over a class/method in eclipse, it opens the corresponding class/method.


2 Answers

  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.

like image 188
meriton Avatar answered Sep 28 '22 00:09

meriton


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

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).

Popup box

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

like image 40
Morgan Courbet Avatar answered Sep 28 '22 01:09

Morgan Courbet