IDEA类和方法注释自动生成

落日映苍穹つ 2023-08-17 16:21 307阅读 0赞

#

#

一、生成类注释

1.打开Preferences-->Editor-->File and Code Templates,右侧选择Filestab页,找到ClassInterface,可以看到右侧模板里引用了一个File Header.java模板,如下图:

image

1.1模板变量说明

  1. ${PACKAGE_NAME} name of the package in which the new file is created
  2. ${USER} current user system login name
  3. ${DATE} current system date
  4. ${TIME} current system time
  5. ${YEAR} current year
  6. ${MONTH} current month
  7. ${MONTH_NAME_SHORT} first 3 letters of the current month name. Example: Jan, Feb, etc.
  8. ${MONTH_NAME_FULL} full name of the current month. Example: January, February, etc.
  9. ${DAY} current day of the month
  10. ${DAY_NAME_SHORT} first 3 letters of the current day name. Example: Mon, Tue, etc.
  11. ${DAY_NAME_FULL} full name of the current day. Example: Monday, Tuesday, etc.
  12. ${HOUR} current hour
  13. ${MINUTE} current minute
  14. ${PROJECT_NAME} the name of the current project

2.建立类自动生成类注释,如下图所示

image

二、生成方法注释

1.、打开Preferences-->Editor-->Live Templates,为了方便管理,新建一个分组来管理自己添加的Live Template,名为myGroup,

image

2.复制粘贴以下的模板

  1. **
  2. * @Author:
  3. * @Description:
  4. * @Date: $date$ $time$
  5. $params$
  6. $return$
  7. **/
  8. 3.设置变量
  9. 3.1 params变量,放在Default value

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==0){result+=’* @Param ‘ + params[i] + ‘: ‘}else{result+=’\\n’ + ‘ * @Param ‘ + params[i] + ‘: ‘}}; return result;}“, methodParameters());

  1. 3.2 return变量,放在Default value
  2. groovyScript("def returnType = \"${_1}\"; def result = '* @return: ' + returnType; return result;", methodReturnType());
  3. 3.3 设置快捷键
  4. 3.4设置范围为java
3.5使用说明

需要自己打出来/*,然后按回车生成方法注释。

image

转载于:https://www.cnblogs.com/fby698/p/11440637.html

发表评论

表情:
评论列表 (有 0 条评论,307人围观)

还没有评论,来说两句吧...

相关阅读