类注释
File–Setting–Editor–File and Code Templates–Class
注释模板:
/**
* @description:
* @author: ${USER}
* @time: ${DATE} ${TIME}
*/
方法注释
-
为了获取参数信息,我们需要使用 “ Live Templates” 。
-
创建 Live Templates 分组
- File–Setting–Live Templates。
- File–Setting–Live Templates。
-
创建 Template
- 我们上一步创建了 zwl 分组,现在我们将在 zwl 分组中创建 Template。
- 注意:Abbreviation 的名字为 * ,Expaned with Enter,这样注释功能的快捷键就为 :/** + Enter
- 右键模板,选择 change context:定义模板的是适用范围,这里选择Java所有即可
模板内容:
*
* @description:
$params$
* @return: $return$
* @author: $user$
* @time: $date$ $time$
*/
定义模板内容中引用的变量
- 我们上一步的截图中,点击 Edit variables 按钮可以弹出变量设置窗口。
- 这里,我们把参数变量 params 设置为一个自定义函数 groovyScript() 。groovyScript 函数调用 Idea 的 methodParameters() 函数获得参数数组,并进行格式化。
- params 的值(即 groovyScript 函数):
-
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' : '')}; return result", methodParameters())
- 其他变量的值,直接使用 Idea 的函数进行赋值。
- date → date()
- time → time()
- author → user()
- return → methodReturnType()
最终效果: