147

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.

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.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
aeq
  • 10,377
  • 15
  • 45
  • 46

11 Answers11

140

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.

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

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
133

Well... well... I hope you use Eclipse Helios, because what you asked is available on 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.

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

alt text

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

exic
  • 2,220
  • 1
  • 22
  • 29
nanda
  • 24,458
  • 13
  • 71
  • 90
  • 4
    Fantastic. This solves something that has always bugged me about eclipse. :) Thanks a lot. – brimborium May 29 '13 at 07:10
  • Great tip! but also you may just hover cursor over and press ctrl then select from dropdown [in eclipse oxygen].... I mean you may not need to hold ctrl + click now. – old-monk Apr 11 '18 at 20:58
78

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.

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.

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
Jonathan
  • 3,203
  • 2
  • 23
  • 25
  • 2
    Works also great with keyboard-only. Just CTRL+T and use arrow keys to navigate. Press Enter to jump to the implementation. – It's Leto Mar 12 '15 at 11:28
55

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.

Open implementation keybinding

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
Lukasz Frankowski
  • 2,955
  • 1
  • 31
  • 32
15

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

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
Roland
  • 1,109
  • 13
  • 15
14
ctrl + mouse hover + click "Open Implementation"

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

enter image description here

Tested on Eclipse Mars.2 (4.5.2)

tbraun
  • 2,636
  • 31
  • 26
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.

It is just as quick as IntelliJ I think.

Mangusta
  • 443
  • 4
  • 4
2

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

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

it's my favorite and the best

k-den
  • 853
  • 13
  • 28
supernova
  • 3,111
  • 4
  • 33
  • 30
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.

  • Anyway, I think you might be looking for something like this:

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

Community
  • 1
  • 1
mahju
  • 1,156
  • 1
  • 14
  • 21
  • Thanks this was helpful too. From that link you can also click on the method while hold down 'cntrl' and then choose 'Open Implementation'. This is even faster. – aeq Jul 15 '10 at 13:07
0

The best solution would be Ctrl+Alt+I.

computingfreak
  • 4,939
  • 1
  • 34
  • 51
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.

zvikico
  • 9,765
  • 4
  • 38
  • 49