As a programmer, adding Javadoc comments can be considered an essential step. However, manually adding extensive content each time can undoubtedly become a cumbersome task.

This article serves as a record, aiming to facilitate the process of reconfiguration when changing environments in the future:

(The method described here is auto-generated by IntelliJ IDEA and does not require installing additional plugins.)

Class、Interface Comments

  1. File–>settings–>Editor–>File and Code Templates–>Files–>Class
  2. Add documentation comment templates to the template:
1
2
3
4
5
6
7
8
9
10
/**
*@ClassName ${NAME}
*@Description TODO
*@Author ${USER}
*@DATE ${DATE} ${TIME}
*@Version 1.0
*/
public class ${Name}{

}

Once completed, every time a class or interface is created, the comments will be automatically generated.

Method Comments

  1. File–>Settings–>Editor–>Live Templates
  2. Click on the right-hand side + icon, select `Template Group…, and create a new custom template group. You can name it with your desired name.
  3. Select the created template group, click on the right-hand side + icon, choose Live Template, and set the value of abbreviation to *.
  4. Set the template content: Choose Template Text and enter the following code below:
1
2
3
4
5
6
7
*
* @Author $user$
* @Description //TODO
* @Date $time$ $date$
* @Param $param$
* @return $return$
**/
  1. Configure where this template should be effective: Select Define“ below, then choose Everywhere and Java to ensure it only takes effect in Java files.
  2. Select the Edit variables button on the right-hand side and configure as follows:

注释图片

  1. Use /* + the template name we just set (in this case, it’s the asterisk *) + tab (this is the default template expansion shortcut, as set in By default expand with above). So now, when you use /** + tab, it will auto-complete, and the effect will be as follows:

注释图片2

With this, the configuration is complete.