定義類注釋
1.在File -> Settings -> Editor -> File and Code Templates -> Includes
這里配置后,會在所有的java文件的頭部添加注釋,但是如果在創建文件時就引入其他類的話,那么注釋會在引入的類上面.
2.在File -> Settings -> Editor -> File and Code Templates -> Files
這里配置后,表示只會在創建該類文件時才會有注釋.
3.在File -> Settings -> Editor -> Live Templates
- 新建一個Template Group,如果不新建的話則默認為user組里.
- 新建一個Live Template
- 配置Abbreviation為/**(是模板名,用於調用模板的)
4.配置Template Test為
/**
* @author:: fate
* @description:
* @date: $date$ $time$
**/
5.設置應用場景為java的comment就可以了.
6.點擊EDIT VARIABLES
7.配置參數,可以在Expression中選擇參數,可以設置默認值(如果是調用當前其他參數,則將其放在被調用的下面;如果為常量則需要用雙引號),Skip if Def是判斷是否需要跳過(勾上,則直接跳過;不勾,則在創建注釋后把光標放在哪里;用可以通過調整參數的先后順序來控制光標的移動順序).
8.在類上,輸入/**,按tab鍵即可(亦可以修改為其他鍵)
3.在File -> Settings -> Editor -> Live Templates
這種與上面那種相似.不過使用的是idea里面默認的注釋方法 /*+模板名.
修改Abbreviation為class(可以隨意)
修改Template Text
*
* @author: fate
* @description:
* @date: $date$ $time$
**/
自定義方法注釋
- 創建新的Live Template
- Abbreviation為me
- 應用場景為java的comment就可以了.
- Template text
*
* @description: $describle$ $param$ $return$
*/
- 配置return與param參數
return:
groovyScript("if(\"${_1}\".length() == 2) {return '';} else {def result=''; def returns=\"${_1}\"; if(returns != 'void'){result+='\\n * @return: ' + returns}; return result;}", methodReturnType());
param:
groovyScript("if(\"${_1}\".length() == 2) {return '';} else {def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();for(i = 0; i < params.size(); i++) {if(i<(params.size()-1)){result+='\\n' + ' * @param ' + params[i] + ' : '}else{result+='\\n * @param ' + params[i] + ' : '}}; return result;}", methodParameters());
- 在方法上面輸入/*me,然后按tab鍵即可.
自定方法簡寫
注意的p1是直接引用的param參數的值,所以要把p1放在param下面,勾選上Skip.