190

In Eclipse, I can press Alt+Shift+J and get a javadoc comment automatically generated with fields, returns, or whatever would be applicable for that specific javadoc comment. I'm assuming that IntelliJ IDEA has this feature. Can anyone tell me if there is a keyboard shortcut for this?

gvlasov
  • 18,638
  • 21
  • 74
  • 110
josh-cain
  • 4,997
  • 7
  • 35
  • 55

3 Answers3

380

Typing /** + then pressing Enter above a method signature will create Javadoc stubs for you.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
  • 3
    When overriding a method, eclipse adds an @see tag with a link to the parent method. Can IntelliJ do the same? – Καrτhικ Dec 01 '14 at 18:28
  • 4
    @RachelGallen link is dead, see [jetbrains.com/help/idea/creating-documentation-comments.html](https://www.jetbrains.com/help/idea/creating-documentation-comments.html) – boardtc Nov 21 '18 at 14:24
  • 1
    @boardtc thanks for the update. I actually tried to revisit the link recently and the whole site was down. Nice one. – Rachel Gallen Nov 21 '18 at 14:28
  • 5
    this seem to only create the comment block, no actual stub – Ghilteras Jun 11 '19 at 00:06
97

You can use the action 'Fix doc comment'. It doesn't have a default shortcut, but you can assign the Alt+Shift+J shortcut to it in the Keymap, because this shortcut isn't used for anything else. By default, you can also press Ctrl+Shift+A two times and begin typing Fix doc comment in order to find the action.

xav
  • 5,452
  • 7
  • 48
  • 57
krm
  • 2,074
  • 2
  • 18
  • 21
42

Shortcut Alt+Enter shows intention actions where you can choose "Add Javadoc".

  • 2
    I think that 3 could disagree with that statement. You should set pointer on the name. – Robert Jakubowski Mar 16 '17 at 13:05
  • 5
    put the cursor on the method name you want to add javadoc ,and then press alt + enter, there will be an add javadoc option in the popup.If the method already has a javadoc,then there will be no add javadoc option. – lin Jun 12 '17 at 03:11
  • 2
    The only confusion I saw is people asking to put the cursor in function/class/variable to generate java docs. You have to keep the cursor on the object for which you are generating the documentation, just the way you will import a class by keeping cursor on the object and hit `Alt`+`Enter` – Doogle Feb 02 '19 at 14:15
  • Getting to the intention is fine and all, but the goal is - what keymap can I use to add the comment without having to do extra stuff, thus the answer above - adding the keymapping to "Fix doc comment" is the correct answer for someone coming from Eclipse – Charles Hasegawa Aug 13 '21 at 18:55
  • @user1742058 Yes, you're right, but there are many people that found that answer helpful. Furthermore, The accepted answer is also not a shortcut. I think that all 3 answers are good and everyone could pick one. – Robert Jakubowski Aug 23 '21 at 11:08