intellj idea 如何設置類頭註釋和方法註釋

ntellj idea 如何設置類頭註釋和方法註釋html

 

          intellj idea的強大之處就很少說了,相信每一個用過它的人都會體會到,可是咱們也會被他的複雜搞的暈頭轉向,尤爲剛從eclipse轉過來的童鞋,相信剛開始的那段經歷都是不堪回首的,我也是一步步這麼走過來的。程序員

         今天講的一個主題是如何實現相似eclipse的Code Templates那樣的功能,進行文件級別的方法級別註釋的實現。網絡

         一:文件級別的註釋eclipse

         文件級別的註釋網上已經不少介紹了,本文不作多介紹,主要是經過File--》Setting--》File and Code Template中來設置ide

         二:方法級別的註釋函數

         文件級別的註釋網上其實已經有不少了,可是方法級別的註釋講解的卻不多,不少人不知道如何實現。我分享的這種方法也是我的在使用Intellj過程當中本身的一些技巧,若是你有更好的方式,能夠在評論中給予更多的思路。主要就是經過intellj強大的Live Template來作。ui

         下面簡單介紹一下Live Template(下面這段話摘自網絡,點擊這裏進入原文-- 更爲詳細的Live Template的使用介紹和高級進階,請參考文章底部連接 ):編碼

            用慣了Eclipse快捷鍵的人可能會不習慣,sysout、foreach等快捷方式找不到了,main方法也沒法自動補全了,其實這個在IntelliJ中有一個異常強大的模塊Live Template來實現。idea

例如,在class中嘗試psvm+tab,則會發現main方法產生了;輸入iter+tab,則生成了foreach語句。 
live template還有一個surround的用法,選中某個變量,鍵入ctl+alt+j兩次,則會出現自動補全的菜單。spa

此外,還能夠自定義Live Template。Code Snippet技術應用也挺廣泛的,IntelliJ的Live Template優勢是內置了一些智能的變量和函數,能夠作到一些語義級別的分析和運用

    下面爲具體步驟:

         一、點擊File--》Setting--》Live Template,點擊右側的+號,選擇Template Group

         二、輸入MyGroup(你也能夠輸入其餘自定義的名稱),而後點擊OK。

         三、選中MyGroup以後,再次點擊右側的+號,選擇Live Template

其中abbreviation

         四、點擊第四步的Define,選擇EveryWhere

         五、點擊右邊的Edit variables

        六、點擊OK,Apply,退出,大功告成。在方法前面按 Ctrl+J ,而後選擇自定義的方法註解,進行體驗吧

         

個人上面的這個小技巧只是我的在使用Intellj時的一個小技巧而已,Live Template的使用,能夠參考如下連接,建議你們仔細閱讀,對本身的經常使用編碼頗有幫助。

 

IntelliJ下使用Code/Live Template加快編碼速度:程序員的工做不是寫程序,而是寫程序解決問題

IntelliJ Live Template進階使用

Intellj Live Template中的預約義函數列表

備註:

注意點:

 

不知道怎樣能夠帶回參數和返回值等信息,可是我知道爲啥不顯示了。

user()和date()能顯示內容,是由於這兩個方法在其有效的做用域執行。

而關於Method的方法(如methodName()、methodParameters()、methodReturnType())沒有起做用是由於你在方法外執行的mc快捷操做,這些方法的做用域是在方法內。

看下methodName()方法的解釋:Returns the name of the embracing method (where the template is expanded).返回起做用的方法的名稱。

 

This is a built-in template. It contains a code fragment that can be included into file templates (Templates tab) with the help of the #parsedirective.
The template is editable. Along with static text, code and comments, you can also use predefined variables that will then be expanded like macros into the corresponding values.

 

Predefined variables will take the following values:
${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
${HOUR}   current hour
${MINUTE}   current minute
${PROJECT_NAME}   the name of the current project

 

 

 

注意點二:多個參數換行,可使用 groovyScript

 

其中腳本值:

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\\b' : '')}; return result", methodParameters())

 

 

後續有不少開發填坑的文章發佈,若是對你有幫助,請支持和加關注一下

http://e22a.com/h.05ApkG?cv=AAKHZXVo&sm=339944

https://shop119727980.taobao.com/?spm=0.0.0.0 

相關文章
相關標籤/搜索