最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IDEA配置Java類方法注釋模板實(shí)踐

 更新時(shí)間:2026年03月22日 11:25:10   作者:菜鳥中的拖拉機(jī)  
這篇文章主要介紹了IDEA配置Java類方法注釋模板實(shí)踐,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

一、類注釋模板

File -> Settings -> Editor -> File and Code Templates -> Files

選擇Class , Interface ,Enum 等等,我們都可以看到,在右側(cè)區(qū)域中,在public class 上面,都有一行 #parse(“File Header.java”)

這句代碼是引入了File Header.java文件,作為我們創(chuàng)建的Class Interface ,Enum 等文件的注釋,那么這個(gè)類在哪呢,我們可以看到,在 Files 右側(cè),有一個(gè) Includes 選項(xiàng),

在這里,我們可以定義各種的模板,在需要的地方去引入這個(gè)模板,這里已經(jīng)在類文件中引入了File Header.java 模板,那我們就更改這個(gè)模板成為我們想設(shè)置成的樣子

自定義注釋模板

/**
 * @className: ${NAME}
 * @author: Kevin
 * @date:  ${DATE}
 **/

新建接口文件自動(dòng)生成注釋,效果如下

/**
 * @className: CrowdService
 * @author: Kvein
 * @date: 2022年05月12日 15:33:00
 **/
public interface CrowdService {
}

注釋模板不完全變量參考表

預(yù)定義變量描述信息
${NAME}the name of the current file
${PACKAGE_NAME}name of the package in which the new file is created
${USER}current user system login name
${DATE}current system date
${TIME}current system time
${YEAR}current year
${MONTH}current month
${MONTH_NAME_SHORT}first 3 letters of the current month name. Example: Jan, Feb, etc.
${MONTH_NAME_FULL}full name of the current month. Example: January, February, etc.
${DAY}current day of the month
${DAY_NAME_SHORT}first 3 letters of the current day name. Example: Mon, Tue, etc.
${DAY_NAME_FULL}full name of the current day. Example: Monday, Tuesday, etc.
${HOUR}current hour
${MINUTE}current minute
${PROJECT_NAME}the name of the current project

二、方法注釋模板

File -> Settings -> Editor -> Live Templates

1.在Live Templates 右側(cè)點(diǎn)擊+號(hào)

添加一個(gè)Templates Group,命名為 methodTemplates

2.在剛剛創(chuàng)建的 methodTemplates 下

創(chuàng)建一個(gè) Live Templates ,如下:

1)、在位置1處: 輸入模板的簡(jiǎn)寫碼

  • 在位置2處:輸入模板的描述
  • 在位置3處: 輸入方法注釋模板樣式,可變變量要用 變量名變量名 來表示,如:paramparamparam;
  • 若不設(shè)置成如此的變量名,位置4不可點(diǎn)擊,模板如下:
/**
 * @title $title$
 * @author Kevin $param$
 * @updateTime $date$ $TIME$ $return$
 * @throws $throws$
 */

點(diǎn)擊位置4處:可編輯定義的變量的值,如下:

變量param 為方法的參數(shù)變量,需要根據(jù)方法的參數(shù)多少進(jìn)行變化;變量 return 為返回值類型,也要根據(jù)方法的返回值進(jìn)行變化,所一要自行設(shè)置該方法,設(shè)置的代碼如下,復(fù)制粘貼即可:

  • param :
groovyScript("def result=''; def stop=false; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); if (params.size()==1 && (params[0]==null || params[0]=='null' || params[0]=='')) { stop=true; }; if(!stop) { for(i=0; i < params.size(); i++) {result +=((i==0) ? '\\r\\n' : '') + ((i < params.size() - 1) ? ' * @param: ' + params[i] + '\\r\\n' : ' * @param: ' + params[i] + '')}; }; return result;", methodParameters())
  • return :
groovyScript("def result=''; def data=\"${_1}\"; def stop=false; if(data==null || data=='null' || data=='' || data=='void' ) { stop=true; }; if(!stop) { result += '\\r\\n' + ' * @return: ' + data; }; return result;", methodReturnType())

在位置3下方,點(diǎn)擊選擇該模板應(yīng)用的范圍,可選Everywhere 表示任何位置都可添加該注釋

點(diǎn)擊options 中的 Expand with 可選擇該模板配合使用的快捷鍵,如 Tab鍵,Space 空格鍵 , Enter 回車鍵 等等;

  • 如在這里設(shè)置的模板關(guān)鍵詞為 * ,配合使用快捷鍵為Tab鍵
  • 則在方法中輸入 * ,在按下Tab 鍵,即可按照模板生成注釋。

補(bǔ)充說明

方法注釋模板不可用在,方法外,若用在方法外 @param 獲取不到,注釋為 @param null;

類注釋模板在文件創(chuàng)建時(shí)生成,已創(chuàng)建文件不會(huì)觸發(fā)該模板,會(huì)觸發(fā)方法注釋模板。

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

龙门县| 嘉黎县| 江孜县| 景德镇市| 湾仔区| 玉环县| 方城县| 孝义市| 延寿县| 富宁县| 皋兰县| 商丘市| 上饶市| 唐海县| 商水县| 湘西| 新和县| 谢通门县| 新丰县| 鸡西市| 盐源县| 乌苏市| 成安县| 富阳市| 沅陵县| 仪陇县| 黔南| 会泽县| 永康市| 阜宁县| 师宗县| 卓尼县| 博罗县| 新蔡县| 莒南县| 汝州市| 宁津县| 东海县| 航空| 综艺| 托里县|