Tuesday, May 8, 2012

Adding javadoc to a method in IntelliJ - using keyboard shortcut


Introduction

The way to add Javadoc to a method in IDEA is to put the cursor above the method and write '/**' and press Enter.
In Eclipse you can use a keyboard shortcut to produce the same result. This can be emulated in IDEA!

Implementation steps

The first thing to do is to create a macro:
  1. Start recording a a macro in Edit - Macros - Start Macro Recording
    1. Press Down
    2. Press Ctrl + Up
    3. Press ⌘ + Left
    4. Write /**
    5. Press Enter
  2. Stop the macro recording in Edit - Macros - Stop Macro Recording
  3. Give it a cool name
  4. Edit the macro in Edit - Macros - Edit Macros, select your new macro and edit it to contain the following:
    1. Action: EditorDown
    2. Action: MethodUp
    3. Action: EditorLineStart
    4. Typing "/**"
    5. Action: EditorEnter
Now you can add a keyboard shortcut to the macro:
  1. Double-click on your macro in Settings - Keymap - Macros - Your macro with the cool name
  2. Choose Add keyboard shortcut
  3. Press the keyboard combination that should trigger the macro, e.g. ⌘ + Shift + J

Result

You can now add javadoc to a method using a keyboard shortcut from anywhere within a method.

No comments:

Post a Comment