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

类注释

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

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

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

那咱们该怎么修改呢?分状况吧app

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

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

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

  2. 想修改全部引用了File Header.java 的文件模板,修改图2以下。code

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

由于变量的命名太明了不过了,因此这里很少讲解,直接贴出官网的英文解释:orm

  • ${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实现图片

这块内容不了解的能够戳进ip

输入图片说明

  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,若是在方法外部使用,将出现获取不到值的状况

相关文章
相关标签/搜索