在网上搜了一些自动添加注释的博客,无论方法是否有参数和返回值,都必须输出@param和@result,对于我这种强迫症患者着实恼火,所以修改了一下。
首先打开file->settings->live templates,点击右上角+,新增live template,如下面,abbreviation输入*z(也可以输入其他),description输入描述。template text输入如图代码(代码块见后面)

点击edit variable,按如下输入(代码块见后面):

template text代码:
**
* @desc $desc$
* @author qufeng
* @date $date$$param$$return$
*/
param代码块:
groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '');if(params.length()==0 || params=='null'){return ''};result+='\\n';params=params.split(',').toList();for(i = 0; i < params.size(); i++) {result+=' * @param ' + params[i] + '\\t' + ((i < params.size() - 1) ? '\\n'

本文介绍了如何在IntelliJ IDEA中针对强迫症患者定制自动添加类和方法注释,只在需要时添加@param和@result。通过设置Live Templates,用户可以自定义abbreviation、description和template text,实现更符合个人需求的注释风格。
最低0.47元/天 解锁文章
4380

被折叠的 条评论
为什么被折叠?



