0


IDEA设置Class创建自动添加头部注释,为已存在的类或者方法快捷添加注释

IDEA快捷注释定义

设置IDEA创建Class时自动添加头部注释

打开 File->setting->Editor->File and Code Templates->Includes->File Header
设置IDEA创建Class时自动添加头部注释
我的默认类头:

/**
 * @author  zjq
 * @date $DATE $TIME
 * 博客: https://zhanjq.blog.csdn.net/?type=blog
 * @description: 
 */

这种是新建类的时候会默认添加,还有一种就是类已经存在的时候添加类注释或者方法注释。具体操作如下:

已存在的类或者方法快捷添加注释

这时候需要设置快捷模板,打开 File->Setting->Editor->Live Templates
点击右边的加号,选择Template Group(模板组):
在这里插入图片描述
添加一个personal的模板分组,里面添加类注释模板和方法注释模板。
类注释模板:

/**
 * @author  zjq
 * @date $DATE$ $TIME$
 * @description: 
 */

方法注释模板:

/**
 * @author: 共饮一杯无
 * @date: $DATE$ $TIME$
 $PARAMS$
 $RETURN$
 * @Description: 
 */

选择对应的模板,设置它的作用范围和变量的内容定义:
在这里插入图片描述

类注释模板变量定义如下:
在这里插入图片描述

方法注释模板定义如下:
方法注释模板定义
DATE变量对应表达式:

date()

TIME变量对应表达式:

time()

PARAMS变量对应表达式:

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

RETURN变量对应表达式:

groovyScript("def returnType = \"${_1}\"; def result ='';if(returnType=='null'||returnType=='void'){return;}else{result += '* @return ';cls = returnType.split('<');for(i = 0; i < cls.size(); i++){temp = cls[i].tokenize('.');result += temp[temp.size() - 1] + ((i < cls.size() - 1) ? '<' : '');};return result + ' ';}",methodReturnType());

效果如下:
aaa.gif

常用的预设变量

  • ${PACKAGE_NAME} - 将在其中创建新类或接口的目标包的名称。the name of the target package where the new class or interface will be created.
  • ${PROJECT_NAME} -当前项目的名称。 the name of the current project.
  • ${FILE_NAME} -将要创建的 PHP 文件的名称。 the name of the PHP file that will be created.
  • ${NAME} - 您在创建文件的过程中,在 “新建文件” 对话框中指定的新文件的名称。the name of the new file which you specify in the New File dialog box during the file creation.
  • ${USER} - 当前用户的登录名。the login name of the current user.
  • ${DATE} - 当前系统日期。the current system date.
  • ${TIME} - 当前系统时间。the current system time.
  • ${YEAR} - 本年。the current year.
  • ${MONTH} - 本月。the current month.
  • ${DAY} -当月的当前日期。 the current day of the month.
  • ${HOUR} - 当前小时。the current hour.
  • ${MINUTE} - 当前分钟。the current minute.
  • ${PRODUCT_NAME} - 将在其中创建文件的 IDE 的名称。the name of the IDE in which the file will be created.
  • ${MONTH_NAME_SHORT} - 月份名称的前3个字母。示例:1月,2月等。the first 3 letters of the month name. Example: Jan, Feb, etc.
  • ${MONTH_NAME_FULL} - 一个月的全名。示例:1月,2月等。full name of a month. Example: January, February, etc.

Postfix Completion(代码模板)

除了通过Live Templates添加模板也可以通过

Postfix Completion

添加代码模板,idea默认一直给我们集成了很多代码模板,入口:File->Setting->Editor->General->Postfix Completion。
Postfix Completion(代码模板)

本文内容到此结束了,
如有收获欢迎点赞👍收藏💖关注✔️,您的鼓励是我最大的动力。
如有错误❌疑问💬欢迎各位指出。
主页:共饮一杯无的博客汇总👨‍💻

保持热爱,奔赴下一场山海。🏃🏃🏃


本文转载自: https://blog.csdn.net/qq_35427589/article/details/129365200
版权归原作者 共饮一杯无 所有, 如有侵权,请联系我们删除。

“IDEA设置Class创建自动添加头部注释,为已存在的类或者方法快捷添加注释”的评论:

还没有评论