Idea 添加注釋:類注釋、方法注釋
- 類注釋
- 方法注釋
類注釋
- File–Setting–Editor–File and Code Templates–Class:
- 注釋模闆:
/** * * *@description: *@author: Andy *@time: ${DATE} ${TIME} * */
- 操作截圖:
- 效果:
- 注釋模闆:
方法注釋
- 為了擷取參數資訊,我們需要使用 “ Live Templates” 。
- 建立 Live Templates 分組
- File–Setting–Live Templates。
- 建立 Template
- 我們上一步建立了 Andy 分組,現在我們将在 Andy 分組中建立 Template。
- 設定模闆内容
- 模闆縮寫(Abbreviation):例如,我們可以把它設定為 “a”。
- 模闆描述(Description):例如,我們可以設定為 “方法注釋”。
- 模闆内容:
/** * * * @description: $params$ * @return: $return$ * @author: Andy * @time: $date$ $time$ */
- 定義模闆内容中引用的變量
- 我們上一步的截圖中,點選 Edit variables 按鈕可以彈出變量設定視窗。
- 這裡,我們把參數變量 params 設定為一個自定義函數 groovyScript() 。groovyScript 函數調用 Idea 的 methodParameters() 函數獲得參數數組,并進行格式化。
- params 的值(即 groovyScript 函數):
- 其他變量的值,直接使用 Idea 的函數進行指派。
- date → date()
- time → time()
- return → methodReturnType()
- 定義模闆的使用範圍
- 效果: