[IDEA] IDEA 如何设置类头注释和方法注释

IDEA 设置类头、方法注释

Posted by Mr.Vincent on 2019-06-13
Estimated Reading Time 1 Minutes
Words 411 In Total
Viewed Times

类头注释:

类注释模板(快捷键–> cmt):

1
2
3
4
5
6
7
8
9
/**
* @ProjectName: $PROJECT_NAME$
* @Package: $PACKAGE_NAME$
* @ClassName: $CLASSNAME$
* @Description:
* @Author: Mr.Vincent
* @CreateDate: $DATE$ $TIME$
* @Version: 1.0.0
*/

打开 file -> setting -> Editor -> Filr and Code Templates -> Includes -> File Header
1
直接在右边的文件框里编辑你说需要注释的东西,然后应用保存之后,当你创建类的时候就会自动生成注释。

方法注释:

类注释模板(快捷键–> *):

1
2
3
4
5
6
7
8
* 
* @Method $methodName$
* @Description: $description$
* @Param: $params$
* @return: $returns$
* @Author: Mr.Vincent
* @Date: $date$
*/

打开 file -> setting -> Editor -> LiveTemplates 点击右边上面那个绿色的+号,选择 Template Group 双击,然后弹出一个窗口,随便添加一个名字,我这里添加的是 MyGroup 然后点击 OK
2
还是在 file -> setting -> Editor -> LiveTemplates 这个路径下点击一下刚刚你添加的那个名字(我这是MyGroup),然后点击右边上面那个绿色的 + 号,选择 LiveTemplate 双击,填写下面的图上的框
3
4

然后点击
然后选择 Everywhere
5
最后点击右下角的 Edit variables 按钮,然后弹出一个窗口,如下:
6
如果想把 @param:每一个参数可以这样
7
参数值要自己写的:

1
groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+=' * @param ' + params[i] + ((i < params.size() - 1) ? '\\n\\b' : '')}; return result", methodParameters())

把这个添加进去,但是还要注意一点:
8
下面红色圈中的下拉框选择相对应的参数点击 OK
再点击 apply ,点击 Ok。
然后写方法之前点写上 add(刚刚填的)按 tab,注释就出来了。


If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !