In this section:

Creating documentation comments for a method or function

To create a documentation comment for a method or function
  1. Place the caret before the declaration.
  2. Type the opening block comment /**, and press or or or Enter, or Enter, ^ M, , ⌃M, or ⌃M.
  3. Add meaningful description of parameters and return values.

Please note the following:

  • IntelliJ IDEA checks syntax in the documentation comments and treats it according to the Error settings.
  • If the entered text contains HTML tags, the closing tag will be automatically added after typing >, provided that this behavior is enabled in the editor settings.
  • When typing in a documentation comment, the caret automatically moves to an expected position. For example:

    javadoc_smart_enter

Creating tags

To create tags in a documentation comment block
  1. In a comment block, select the desired empty line and type @ character.
  2. Press ⌃Space or ⌃Space⌃Space or ⌃Space⌃Space or ⌃Space^ Space, ⌃Space or ⌃Space⌥ Slash, ⌥/ or ⌥/, or just wait for Code Completion to display the suggestion list:

    doc_comment_tags

  3. Select a tag from the suggestion list. For example, you can specify the parameters type, or return type.
  4. If a certain tag has several values, press ⌃Space or ⌃Space⌃Space or ⌃Space⌃Space or ⌃Space^ Space, ⌃Space or ⌃Space⌥ Slash, ⌥/ or ⌥/ after the tag, and select the desired value from the suggestion list. For example, IntelliJ IDEA suggests to select the desired parameter name.

    code_completion_param

Creating and fixing doc comments

Note that this section refers to JavaScript, Java and the other languages that have special beginning of documentation comments.

Documentation comment can be created with the dedicated action Fix Doc Comment. It can be invoked by means of Find Action command.

Press ⇧⌘A or ⇧⌘A⇧⌘A or ⇧⌘A⌘3 or ⌘3^ ⇧ A, ⌃⇧A or ⌃⇧A^ ⇧ A, ⌃⇧A or ⌃⇧A, with the caret somewhere within a class, method, function, or field, which should be documented, and enter the action name Fix Doc String. The missing documentation stub with the corresponding tags is added. For example:

/**
*
* @param userInput
* @return
*/
static boolean processRepeatConversion (@NotNull String userInput) {
    boolean repeatConversion = false;
if (((userInput.equals("y")) || (userInput.equals("Y")))) {
   repeatConversion = true;
}
return repeatConversion;

}

The next case lays with fixing problems in the existing documentation comments.

For example, if a method signature has been changed, IntelliJ IDEA highlights a tag that doesn't match the method signature, and suggests a quick fix.

For JavaScript, IntelliJ IDEA suggests an intention action UpdateJSDoc comment. You can also press ⇧⌘A or ⇧⌘A⇧⌘A or ⇧⌘A⌘3 or ⌘3^ ⇧ A, ⌃⇧A or ⌃⇧A^ ⇧ A, ⌃⇧A or ⌃⇧A, and type the action name:

fix_doc_comment

The action Fix doc comment has no keyboard shortcut bound with it. You can configure keyboard shortcut of your own.

Clickable comments

If a documentation comment contains a hyperlink, you can make it clickable.

To do that, do one of the following:

  • Keep the ^ key pressed and hover your mouse pointer over the hyperlink:

    clickable_link

  • Press ⌘B, ⌘Button1 Click, Button2 Click, ⌘B, ⌘Button1 Click or Button2 Click⌘B, ⌘Button1 Click, Button2 Click, ⌘B, ⌘Button1 Click or Button2 ClickF3, ⌃Button1 Click, F3 or ⌃Button1 ClickF12, ⇧ F2, ^ B, ^ Button1 Click, Button2 Click, F12, ⇧F2, ⌃B, ⌃Button1 Click, Button2 Click, F12, ⇧F2, ⌃B, ⌃Button1 Click or Button2 Click^ ⌥ G, Escape, Period, ⌥ Period, ^ Button1 Click, ⌃⌥G, ⎋, ., ⌥., ⌃Button1 Click, ⌃⌥G, ⎋, ., ⌥. or ⌃Button1 Click.