57

Details:

  • IDE: IntelliJ IDEA 14
  • O.S.:: Windows 7

If I want to navigate to the declaration of a method I can choose one of the following approaches:

  • press Ctrl + left click
  • right click > Go To > Declaration
  • press Ctrl + B

If I want to navigate to the implementation of a method I can choose one of the following approaches:

  • press Ctrl + Alt + left click
  • right click > Go To > Implementation(s)
  • press Ctrl + Alt + B

In Eclipse, if I press Ctrl and the mouse is over a method, a popup appears and I can choose what to do (go to Implementation/Declaration). If I press "left click" ( Ctrl is still pressed ) the first option will be chosen.

enter image description here

How can I achieve the same / a similar behavior in IntelliJ IDEA ?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

5 Answers5

67

There is not a built-in option for this. You would need to configure a custom quick list to do such.

  1. Open the Settings dialog and go to "Quick Lists" (It's under "Appearance & Behavior" in IDEA 14)
  2. Click the add button enter image description here to the right of the middle pane
  3. Give your list a name
  4. Click the add button enter image description here to the right of the far right pane (where is reads "no actions")
  5. Add the Go to Declaration action (Main Menu > Navigate > Go to Declaration)
  6. Add the Go to Implementation(s) action (Main Menu > Navigate > Go to Implementation(s))
  7. Click Apply
  8. Go to Keymap in the settings
  9. Under the "Quick List" node, find the Quick List you just created and map a short-cut (keyboard or mouse) to it. You can, of course, remap one of the shortcuts used by the Go to Declaration or the Go to Implementation(s) action
  10. Click OK to close out of the settings and give it a try.

Note that in the quick list that opens, you will have numbers next to each action for quick selection.

Edit: Adding a screenshot of final quick list for additional clarity

enter image description here

Mason Bryant
  • 1,372
  • 14
  • 23
Javaru
  • 30,412
  • 11
  • 93
  • 70
  • 1
    Even it is not exactly what I wanted, I accepted your answer because this is an interesting solution and probably the best one that can be offered by IntelliJ if we want to achieve a similar functionality as it is in Eclipse. Thanks! – ROMANIA_engineer Jan 28 '15 at 13:23
  • I was about to comment to say that this answer no longer applied; intellij provides a popup to choose between jumping to multiple implementations of an interface. Then I realized this question asks to choose between Declaration and Implementation. In my project the declaration is one of the implementations listed in the menu, but in other projects I suppose that may not be true so this is an excellent approach. – David Mann Jan 16 '17 at 20:06
  • macOS users: I've customized my keymap to use `force touch` to go to implementation: https://ibb.co/xDP9739 – vault Jan 21 '21 at 16:18
29

I was looking for the same thing, because I was also used to it in Eclipse. Nevertheless, in 99% of the cases, I went to the implementation. If that's your case too, you may consider changing the Ctrl+click shortcut in IntelliJ:

  • Open File → Settings... → Keymap
  • Search for "implementation", and identify the item "Main menu → Navigate → Implementation(s)" in the list
  • Right-click the item and choose "Add Mouse Shortcut"
  • Add the Ctrl+click shortcut by making a Ctrl+left click on the window
  • When hitting the OK button, you have two choises :
    • Remove the existing shortcut (opening the declaration)
    • Leave the existing shortcut : In that case, when using then Ctrl+click, both the declaration and the implementation will be opened (at least when they are in different files)

I know this answer comes like 2 years too late, but hopefully it may help others?

EDIT : This shortcut also applies when you want to navigate to the declaration of a super class. Therefore, my "99%" first declared above drops a bit. I've added the ctrl + right-click as a shortcut to go the declaration (which conflicts with no other shortcut - but you need a mouse with at least two buttons...).

Nedorot
  • 391
  • 3
  • 4
  • thanks for the help! I use "go to implementation" much much more often than "go to declaration", so I assigned "ctrl + click" to implementation and then "ctrl + alt + click" to declaration.... – John Smith Jul 22 '21 at 03:43
6

If you select the method and hit Ctrl+T it will show the implementations of the methods. You can click on the options to navigate to that implemented method. Hope this helps.

Sabarish
  • 862
  • 1
  • 14
  • 23
1

On mac you can open the implementation(s) with command + option + click. Right -click on the method and check "go to" for the other options and shortcuts you might need.

Gismo Ranas
  • 6,043
  • 3
  • 27
  • 39
0

My IntelliJ (2016.2) shows the declaration of a method (in a PHP interface) as one of the implementations in the implementation popup, so maybe you can do this all from the Implementations popup now.

David Mann
  • 1,874
  • 2
  • 16
  • 19