Preface
It is inevitable to comment on classes and methods during development. There will be a lot of comments. IDEA's own comments are not detailed enough. You need to add and modify each time. You can customize the comment templates of classes and methods to improve development efficiency.
Class template annotation settings
- Windows:File–>settings–>Editor–>File and Code Templates–>Files
- Mac:Preferences -->Editor–>File and Code Templates–>Files
/**
* @description: TODO
* @author ${USER}
* @date ${DATE} ${TIME}
* @version 1.0
*/
Select Class, Interface, Enum, etc., we can all see that in the area on the right, above the public class, there is a line #parse("File Header.java")
that introduces the File Header.java
file as we create Class Interface, Enum and other files, we select the Includes option on the right of Files, where you can define various templates, and import templates where needed. Header.java
We have already introduced the previous class files and modify this template.
Method template annotation settings
- Windows:File–>settings–>Editor–>Live Templates
- Mac:Preferences -->Editor–>Live Templates
1. Create a new group and rename it.
Click the + sign on the right side of Live Templates to add a Templates Group and name it methodTemplates.
2. Rename the new template
. Create a Live Templates under the methodTemplates just created and name it. *
Because IDEA generates comments by default: /*+模板名+快捷键
(For example, if you set the template name as add shortcut key enter
, the generation method is /*add+enter
). If you don’t use this generation method, methods without content in IDEA will not be available, such as methodParameters() for obtaining method parameters, methodReturnType for obtaining method return values ()
3. Set the template content (as follows).
Note that there is only one in the first line, *
not the method that /*
must be used when setting the parameter name ${参数名}$
, otherwise the parameter name you set cannot be read in the fifth step
*
* @Author $user$
* @Description //TODO $end$
* @Date $time$ $date$
* @Param $param$
* @return $return$
**/
4. Set template application scenarios
Click the warning at the bottom of the template page to set the template to be applied to those scenarios, generally select EveryWhere–>Java
Ps: If it has been modified, it will be displayed as change instead of define.
5. Set the parameter acquisition method, select the Edit variables button on the right.
6.
Create method of effect diagram , write above the method: /*+模板名+Enter
-->/**+Enter
reference
IDEA class and method annotation template settings (very detailed)