IntelliJ IDEA 2020.3 Help

Javadocs

Add a new comment

Add a javadoc using automatic comments

For documentation comments, IntelliJ IDEA provides completion that is enabled by default.

  • Type /** before a declaration and press Enter. The IDE auto-completes the doc comment for you.

    Inserting a doc comment

Disable automatic comments

  • In the Settings/Preferences dialog Ctrl+Alt+S, go to Editor | General | Smart Keys, and clear the Insert documentation comment stub checkbox.

Add a javadoc using context actions

  • Place the caret at the declaration in the editor, press Alt+Enter, and select Add Javadoc from the list.

    Adding a javadoc using the 'Add Javadoc' context action

Add a javadoc using the Fix Doc Comment action

  1. Place the caret within a class, method, function, or a field, and press Ctrl+Shift+A.

  2. Type fix doc comment and press Enter.

IntelliJ IDEA adds the missing documentation stub with the corresponding tags.

In Kotlin, the @param and other tags are not generated because the recommended style requires incorporating the description of parameters and return values directly into the documentation comment.

Fix a javadoc

If a method signature has been changed, IntelliJ IDEA highlights the tag that doesn't match the method signature and suggests a quick-fix. Press Alt+Enter to apply the fix.

You can also update an existing javadoc comment in order to account for the changes in the declaration using the Fix doc comment action:

  1. Place the caret within a class, method, function, or a field, and press Ctrl+Shift+A.

  2. Type fix doc comment and press Enter.

Render Javadocs

IntelliJ IDEA allows you to render Javadocs in the editor. Rendered comments are easier to read, and they don't overload your code with extra tags.

Click Toggle rendered view in the gutter next to the necessary documentation comment (or press Ctrl+Alt+Q) to toggle the rendered view; click Artwork studio icons avd edit to edit the comment.

Javadocs in the editing mode
Javadocs in the rendered mode

Rendered Javadocs allow you to click links to go to the referenced web pages, or view quick documentation for the referenced topics.

To change the font size, right-click a Javadoc in the editor and select Adjust Font Size from the context menu. Note that the rendered comments use the same font size as the quick documentation popup.

Render Javadocs by default

You can configure the IDE to always render Javadocs in the editor.

  • Right-click the icon in the gutter (the Toggle Rendered View icon or the Toggle Rendered View icon) and enable the Render All option.

    Alternatively, in the Settings/Preferences dialog Ctrl+Alt+S, select Editor | General | Appearance and enable the Render documentation comments option.

To edit rendered Javadocs, click the the Toggle Rendered View icon icon in the gutter next to the comment.

View Javadocs in the editor

  • Hover the mouse over the necessary symbol to view its documentation, or place the caret at the symbol, and press Ctrl+Q (View | Quick Documentation ).

    Press Ctrl+Q again to switch between the popup and the toolbar.

    Quick Documentation popup

Click the Show Options Menu icon in the popup to change the font size, display the quick documentation toolbar, or go to the source code.

For more information, refer to Quick documentation

Generate a Javadoc reference

IntelliJ IDEA provides a utility that enables you to generate a Javadoc reference for your project.

  1. From the main menu, select Tools | Generate JavaDoc.

  2. In the dialog that opens, select a scope — a set of files or directories for which you want to generate the reference, and set the output directory where the generated documentation will be placed.

    The Output directory is a mandatory field: you cannot generate a Javadoc file as long it is empty.

  3. Use the slider to define the visibility level of members that will be included in the generated documentation. Select one of the following options:

    • Private: to include all classes and members to the reference.

    • Package: to include all classes and members except the private ones.

    • Protected: to include public and protected classes and members.

    • Public: to include only public classes and members.

  4. You can specify a locale (for example en_US.UTF-8 ), command line arguments, and the maximum heap size.

  5. Click OK to generate the reference.

Javadoc reference generation dialog

Specify Generate JavaDoc Scope dialog

The Tools | Generate JavaDoc dialog invokes the JavaDoc utility. The controls of the dialog correspond to the options and tags of this utility.

ItemDescription
Generate JavaDoc scope

Use this area to specify the subset of files, folders, and packages for which JavaDoc should be generated.

This scope can be the whole project, recently modified files, current file, custom scope, and so on.

Include test sourcesInclude documentation comments for test to the generated JavaDoc.
Include JDK and library sources in -sourcepathIf this checkbox is selected, then paths to the JDK and library sources will be passed to the JavaDoc utility. Refer to documentation for details.
Include link to JDK documentation

If this checkbox is selected, the references to the classes and packages from JDK will turn into links, which corresponds to using the -link option of the JavaDoc utility.

This checkbox is only enabled when a link to the online documentation is specified in the Documentation Paths tab of the SDK settings.

Refer to JavaDoc documentation for details.

Output directory

Specify the fully qualified path to the directory where the generated documentation will be stored. Type the path manually or click the Browse button and select the location in the dialog. The specified value is passed to the -d parameter of the JavaDoc utility. If the specified directory does not exist in your system, you will be prompted to create it.

Slider

Specify the visibility level of members that you want to include in the generated documentation:

  • Private: select this level to have all classes and members included. The level corresponds to the -private JavaDoc parameter.

  • Package: select this level to have all classes and members except private ones included. The level corresponds to the -package JavaDoc parameter.

  • Protected: select this level to have only public and protected classes and members included. The level corresponds to the -protected JavaDoc parameter.

  • Public: select this level to have only public classes and members included. The level corresponds to the -public JavaDoc parameter.

Generate hierarchy treeGenerate the class hierarchy. If this checkbox is cleared, the -notree parameter is passed to JavaDoc.
Generate navigator barGenerate the navigator bar. If this checkbox is cleared, the -nonavbar parameter is passed to JavaDoc.
Generate indexGenerate the documentation index. If this checkbox is cleared, the -noindex parameter is passed to JavaDoc.
Separate index per letter

Generate a separate index file for each letter. If this checkbox is cleared, the -splitindex parameter is passed to JavaDoc.

The checkbox is available only if the Generate index checkbox is selected.

@useDocument the use of the class and the package. When selected, the checkbox corresponds to the -use JavaDoc parameter.
@authorInclude the @author paragraphs. When selected, the checkbox corresponds to the -author JavaDoc parameter.
@versionInclude the @version paragraphs. When selected, the checkbox corresponds to the -version JavaDoc parameter.
@deprecatedInclude the @deprecated information. When the checkbox is cleared, the -nodeprecated parameter is passed to JavaDoc.
deprecated list

Generate the deprecated list. When the checkbox is cleared, the -nodeprecatedlist parameter is passed to JavaDoc.

The checkbox is available only if the @deprecated checkbox is selected.

LocaleType the desired locale.
Other command line argumentsType additional arguments to be passed to JavaDoc. Use the command line syntax.
Maximum heap size (Mb)Type the maximum heap size in Mb to be used by Java VM for running JavaDoc.
Open generated documentation in browserAutomatically open the generated JavaDoc in a browser.

Troubleshoot

javadoc: error - Malformed locale name: en_US.UTF-8

Clear the Locale field. In the Other command line arguments field, add -encoding utf8 -docencoding utf8 -charset utf8.

-encoding specifies the encoding of the source files. -docencoding specifies the encoding of the output HTML files and -charset is the charset specified in the HTML head section of the output files.

Last modified: 08 March 2021