效果预览
类级注释
File -> Settings -> Editor -> File and Code Templates
/**
* @class ${NAME}
* @author ${USER}
* @date ${DATE} ${TIME}
* @version 1.0.0
* @description ${DESCRIPTION}
*/
触发方式:创建新类时自动触发
方法级注释
File -> Settings -> Editor -> Live Templates
**
* @method $methodName$
* @author $user$
* @date $date$ $time$
$param$
* @return $return$
* @description
*/
2021.07.12更新
**
$param$$return$
* @method $methodName$
* @author 吃猫的鱼℘, 935478677@qq.com
* @date $date$ $time$
*/
从上到下依次是:
methodName()
user()
date()
time()
param
groovyScript("if(\"${_1}\".length() == 2) {return ' * @param';} else {def result='';def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();def paramsTypes=\"${_2}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();for(i = 0; i < params.size(); i++) {if(i<(params.size()-1)){result+=' * @param ' + params[i] + ' ' + paramsTypes[i] + '\\n'}else{result+=' * @param ' + params[i] + ' ' + paramsTypes[i]}};return result;}", methodParameters(), methodParameterTypes());
return
groovyScript("def params=\"${_1}\"; if(params=='void'){return 'void';} else {return params}", methodReturnType())
2021.07.12更新
param
groovyScript("if(\"${_1}\".length() == 2) {return '';} else {def result='';def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();for(i = 0; i < params.size(); i++) {if(i<(params.size()-1)){result+=' * @param ' + params[i] + '\\n\\t'}else{result+=' * @param ' + params[i]}};return result;}", methodParameters();
return
groovyScript("def params=\"${_1}\"; if(params=='void'){return '\\r\\n\\t * @return void';} else if(params=='null'){return '';}else {return '\\r\\n\\t * @return '+params}", methodReturnType());
触发方式:在方法前一行按/**+Enter
2022.10.17更新
上班用了一阵子,稍微调整下:
- 去掉了返回值的全类名
- 返回值为void时不生成注释
- 注释第一行和各个参数后加了TODO标记,防止忘记完善注释
**
* TODO
*
$param$$return$
* @author 吃猫的鱼℘, 935478677@qq.com
* @date $date$ $time$
*/
param
groovyScript("if(\"${_1}\".length()==2){return '';}else{def result='';def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]','').split(',').toList();for(i=0;i<params.size();i++){if(i<(params.size()-1)){result+=' * @param '+params[i]+' TODO'+'\\n\\t';}else{result+=' * @param '+params[i]+' TODO';}};return result;}",methodParameters();
return
groovyScript("def returnType=\"${_1}\";if(returnType == 'void'){return '';};def result='\\r\\n * @return ';def params=returnType.replaceAll('[\\\\[|\\\\]|\\\\s]','').split('<').toList();for(i=0;i<params.size();i++){if(i!=0){result+='<';};def p1=params[i].split(',').toList();for(i2=0;i2<p1.size();i2++){def p2=p1[i2].split('\\\\.').toList();result+=p2[p2.size()-1];if(i2!=p1.size()-1){result+=','}};};return result", methodReturnType())