天天看點

公司有統一代碼注釋 - 類和方法注釋模闆

2019獨角獸企業重金招聘Python工程師标準>>>

公司有統一代碼注釋 - 類和方法注釋模闆

類注釋

公司有統一代碼注釋 - 類和方法注釋模闆

圖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