How configure Intellij Idea javadoc templates?

后端 未结 6 1429
忘掉有多难
忘掉有多难 2020-12-03 02:57

I have some method:

public int getSomeField()

I want to generate javadoc like this:

/**
* Gets {someField}
*
* @return valu         


        
相关标签:
6条回答
  • 2020-12-03 03:24

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

    Click the ellipsis in the top right hand corner.

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

    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
    */
    

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

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-03 03:37

    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.

    0 讨论(0)
  • 2020-12-03 03:41

    Surely you can add a live template for such javadoc. The easiest way to do it is to select the whole comment and invoke "Save as live template" action (Tools menu). See http://www.jetbrains.com/phpstorm/webhelp/creating-and-editing-live-templates.html for more details.

    0 讨论(0)
  • 2020-12-03 03:43

    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"

    0 讨论(0)
  • 2020-12-03 03:48

    I tried the methodName() expression, but this only works while inside a method, you want the method outside of it, in the javadoc.

    0 讨论(0)
提交回复
热议问题