一、類註釋
- File --> Settings --> Editor --> File and Code Templates --> Files。
- 選擇 Class、Interface 和 Enum,設置模板格式:
/**
* @author :weimo
* @date :Created in ${DATE}
* @description:${description}
*/
- 勾選 Enable Live Templates 激活模板,點擊 OK。
二、方法註釋
- File --> Settings --> Editor --> Live Templates。
- 選擇添加 Templates Group,輸入組名。
- 選中 Group,選擇添加 Live Template。
- 設置默認快捷鍵爲 Enter。
- Abbreviation 填寫 *,Template Text 填寫以下代碼:
*
* 功能描述:
* @auther: weimo
* @date: $date$ $time$
$params$
* @return $returns$
*/
這樣在方法上輸入 /* 按 Enter 鍵就可以觸發此模板註釋。
6. 點擊 Edit variables 設置模板參數,Skip if… 是爲了方便觸發模板後跳出編輯模式。
值得一提的是關於 params 的形式,如果選擇自帶表達式 methodParameters() 生成的模板是不會換行的,這裏提供以下代碼:
groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+=' * @param ' + params[i] + ((i < params.size() - 1) ? '\\n' : '')}; return result", methodParameters())
- 點擊下方小字 Change 設置生效範圍,勾選 Java,點擊 OK 。
- 模板示例:
/**
* 功能描述:
* @auther: weimo
* @date: 2020/4/13 18:13
* @param id
* @param decode
* @return com.alibaba.fastjson.JSONObject
*/
JSONObject demo(String id, Decode decode);
三、鼠標懸停顯示註釋
- File --> Settings --> Editor --> General
- other 欄勾選 Show quick …,點擊 OK。
- 示例: