How configure Intellij Idea javadoc templates?

30,073

Solution 1

Bring up the Generate menu (Cmd+N on Mac, Alt+Insert on Windows)

Generate menu

Click the ellipsis in the top right hand corner.

Generate Getters menu

Click the plus in the top left corner and create a new template. Create new template dialog

Copy the contents of the old template into the new template and add the following lines to the top of it.

/**
* Gets $field.name
*
* @return value of $field.name
*/

enter image description here

Now when you generate the getter use the 'New Template' and you should get your getter with the JavaDoc.

Select New Template

enter image description here

Solution 2

You generate Javadoc by placing the caret above the method. Then you type /** and press Enter.

Unfortunately the template can't be changed and there is a request for that: http://youtrack.jetbrains.net/issue/IDEA-28206

Solution 3

This will get you most of the way there.

File | Settings... | Live Templates

Press the green plus to add a new custom template.

Abbrevation: getter

Template text:

/**
 * Gets $FIELD$
 *
 * @return value of $FIELD$
 */
public $RET$ get$FIELD$()
{
    $END$
}

Applicable in Java: declaration.

Type getter where you would a method and tab complete.

The only shortcoming is I don't know how to make the first character of $FIELD$ capitalized in get$FIELD$ but none of the other locations.

Here is an image for reference:

IntelliJ Template "getter"

Solution 4

If you want to generate the JavaDoc after the method was written (using /**), there is currently no way to customize this. Vote for issue IDEA-97658: Edit template for javadoc stub if you'd like to see this implemented.

Share:
30,073

Related videos on Youtube

Cherry
Author by

Cherry

Updated on January 28, 2021

Comments

  • Cherry
    Cherry over 3 years

    I have some method:

    public int getSomeField()
    

    I want to generate javadoc like this:

    /**
    * Gets {someField}
    *
    * @return value of {someField}
    */
    

    Where {someField} is placeholder for field name. It is possible to create this templates for Intellij Idea (may be as live template)?

    • mattbdean
      mattbdean almost 11 years
      If you were using Eclipse I'd recommend JAutoDoc.
  • Will Humphreys
    Will Humphreys almost 8 years
    You can now edit comments on templates. See the answer below. stackoverflow.com/a/38094408/2377639
  • Dr4gon
    Dr4gon over 7 years
    Works like a charm :D