Javadoc comments are usually placed above classes, methods, or fields in your source code. A Javadoc provides a description of the code element located under it and contains block tags marked with @ with specific metadata.
You can generate an API reference for your project in HTML by using the Javadoc tool that comes with your JDK. IntelliJ IDEA provides integration with the tool and allows you to build reference guides right from the IDE.
Learn more about the correct format of Javadocs, style guide, terms and conventions from How to Write Doc Comments for the Javadoc Tool.
Documentation comments are also available in JavaScript, Python, Ruby, PHP, and Kotlin.
For documentation comments, IntelliJ IDEA provides completion that is enabled by default.
You can disable automatic insertion of Javadoc comments: in the Settings dialog Ctrl+Alt+S , go to Editor | General | Smart Keys , and clear the Insert documentation comment stub checkbox.
For method comments, the new comment stub contains the required tags ( @param tags for each method parameter, @return , or @throws ).
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.
For more information about documenting Kotlin code, refer to Kotlin documentation.
If a method signature has been changed, IntelliJ IDEA highlights the tag that doesn't match the method signature and suggests a quick-fix.
You can also update an existing Javadoc comment to account for the changes in the declaration using the Fix doc comment action :
You can use the Fix doc comment action to add missing documentation stub with the corresponding tags: place the caret within a class, method, or function and invoke the action.
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 in the gutter next to the necessary documentation comment (or press Ctrl+Alt+Q ) to toggle the rendered view; click to edit the comment.
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.
You can configure the IDE to always render Javadocs in the editor.
To edit rendered Javadocs, click the icon in the gutter next to the comment.
In Javadocs comments, you can use custom tags on top the predefined ones. Later on you can include them in your API reference guide.
When you use a custom tag for the first time, the Javadoc declaration problems inspection highlights it in the editor as a wrong tag. To avoid that, add the tag to the list recognized tags.
To include your custom tags in an HTML Javadoc reference, add them as command-line arguments.
IntelliJ IDEA provides a utility that enables you to generate a Javadoc reference for your project.
The Tools | Generate JavaDoc dialog invokes the Javadoc utility. The controls of the dialog correspond to the options and tags of this utility.
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 sources
Include documentation comments for test to the generated Javadoc.
Include JDK and library sources in -sourcepath
If this checkbox is selected, then paths to the JDK and library sources will be passed to the Javadoc utility. For more information, refer to documentation.
Link to JDK documentation (use -link option)
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.
For more information, refer to the Javadoc documentation.
Specify the fully qualified path to the directory where the generated documentation will be stored. Type the path manually or click 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.
Note that unless the output directory is specified, the OK button is disabled.
Specify the visibility level of members that you want to include in the generated documentation:
Generate hierarchy tree
Generate the class hierarchy. If this checkbox is cleared, the -notree parameter is passed to Javadoc.
Generate navigator bar
Generate the navigator bar. If this checkbox is cleared, the -nonavbar parameter is passed to Javadoc.
Generate 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.
Document the use of the class and the package. When selected, the checkbox corresponds to the -use Javadoc parameter.
Include the @author paragraphs. When selected, the checkbox corresponds to the -author Javadoc parameter.
Include the @version paragraphs. When selected, the checkbox corresponds to the -version Javadoc parameter.
Include the @deprecated information. When the checkbox is cleared, the -nodeprecated parameter is passed to Javadoc.
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.
Type the desired locale.
Command line arguments
Type additional arguments to be passed to a Javadoc. Use the command line syntax.
Maximum heap size
Type the maximum heap size in Mb to be used by Java VM for running Javadoc.
Open generated documentation in browser
Automatically open the generated Javadoc in a browser.
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.
You can configure code style for your Javadocs. Press Ctrl+Alt+S to open settings and then select Editor | Code Style | Java | Javadocs . Configure the options as necessary and use the right part of the dialog to preview the changes.
Learn how to reformat your code from Reformat code.
Define the way Javadoc comments should be aligned.
Define where blank lines should be inserted in Javadoc comments.
In this area, define whether invalid tags should be preserved or not.
In this area, specify additional formatting options for Javadoc comments.
" on empty lines : automatically insert the
tag on an empty line.In IntelliJ IDEA, you can view external Javadocs for any symbol or method signature right from the editor. To be able to do that, configure library documentation paths or add downloaded documentation to the IDE.