公司有统一代码注释 - 类和方法注释模板

类注释

输入图片说明
图1 idea默认的类模板

不管能不能懂 VTL 语法,当看到这里#parse("File Header.java")应该就知道它包含了另一个文件。没错,文件在这:

输入图片说明
图2 File Header.java

那我们该怎么修改呢?分情况吧

  1. 只想修改Class下的模板,那就删除图1中#parse("File Header.java"),添加新的注释进去。(推荐)

    /**
     * ${DESCRIPTION}
     * @author
     * @create ${YEAR}-${MONTH}-${DAY} ${TIME}
     */
    

    ${DESCRIPTION} 是我们自己定义的变量,自定义变量格式有两种方式:$变量名${变量名},自定义的变量在创建对应的文件时候就必须输入内容

  2. 想修改所有引用了File Header.java 的文件模板,修改图2如下。

    /**
     * @author
     * @create ${YEAR}-${MONTH}-${DAY} ${TIME}
     */
    

因为变量的命名太明了不过了,所以这里不多讲解,直接贴出官网的英文解释:

  • ${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} - 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} - the name of the IDE in which the file will be created.
  • ${MONTH_NAME_SHORT} - the first 3 letters of the month name. Example: Jan, Feb, etc.
  • ${MONTH_NAME_FULL} - full name of a month. Example: January, February, etc.

方法注释

idea的方法注释一般通过Live Templates实现

这块内容不了解的可以戳进

输入图片说明

  1. 添加Live Templates

  2. 输入Abbreviation,你可以键入之获取 Template text中的内容

  3. 在Template text中键入

    /**
    * @Description:  
    * @author: $user$  
    * @Param: $params$
    * @Return: $return$
    * @Date: $date$ $time$
    */
    

    其中,$$之间的是自定义变量,可以通过Edit variables设置

  4. 设置applicable contexts

  5. 勾选 Reformat according to style

  6. 设置变量的值

    点击Edit variables,进入后选择每个变量对应的Expression

  7. 使用

    这种方式需要获取方法的相关信息,所以须在方法内部键入Abbreviation,如果在方法外部使用,将出现获取不到值的情况

转载于:https://my.oschina.net/u/2930289/blog/1557636

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值