IDEA添加Java類(lèi)注釋模版的方法
本文介紹了IDEA添加Java類(lèi)注釋模版的方法,分享給大家,具體如下:
IDEA版本:IntelliJ IDEA 2017.2.5 x64
eclipse能在類(lèi)上方輸入/**,回車(chē)添加類(lèi)注釋模版,但idea沒(méi)有默認(rèn)添加這個(gè)功能,需要做一些設(shè)置。下面介紹三種方法實(shí)現(xiàn):
- 創(chuàng)建類(lèi)默認(rèn)添加類(lèi)注釋
- 手動(dòng)添加類(lèi)注釋
- 批量添加JavaDoc注釋
一、設(shè)置新建類(lèi)默認(rèn)添加注釋
依次點(diǎn)擊Setting|Editor|File and code templates,添加如圖配置
例子:
/** *describe: * *@author xxx *@date ${YEAR}/${MONTH}/${DAY} */
支持的變量在描述內(nèi),找到需要配置即可!
二、利用Live Template手動(dòng)添加注釋模版
依次點(diǎn)擊Setting|Editor|Live templates
1、點(diǎn)擊+添加templates group,如My Live Templates
2、點(diǎn)擊+添加live templates,修改abbreviation,再添加模版內(nèi)容,模版變量以$var$
格式定義,如
/** *describe: * *@author xxx *@date $date$ */
3. 點(diǎn)擊define定義模版作用范圍,選擇Java
4. 點(diǎn)擊Edit variables定義變量,表達(dá)式解釋見(jiàn)附件
5. 保存后,在類(lèi)任意位置輸入cc即可添加模版
三、批量添加注釋
安裝JavaDoc插件,alt+insert即可批量添加注釋,包括所有類(lèi)和方法,但是不能定制化,注釋都是固定的。
附件
Item Description annotated("annotation qname") Creates a symbol of type with an annotation that resides at the specified location. For an example, see Live Templates in the iterations group. arrayVariable() Suggests all array variables applicable in the current scope. For an example, see Live Templates in the iterations group. anonymousSuper() Suggests a supertype for a Kotlin object expression. camelCase(String) Returns the string passed as a parameter, converted to camel case. For example, my-text-file/my text file/my_text_file will be converted to myTextFile. capitalize(String) Capitalizes the first letter of the name passed as a parameter. capitalizeAndUnderscore(sCamelCaseName) Capitalizes the all letters of a CamelCase name passed as a parameter, and inserts an underscore between the parts. For example, if the string passed as a parameter is FooBar, then the function returns FOO_BAR. castToLeftSideType() Casts the right-side expression to the left-side expression type. It is used in the iterations group to have a single template for generating both raw-type and Generics Collections. className(sClassName) Returns the name of the current class (the class where the template is expanded). classNameComplete() This expression substitutes for the class name completion at the variable position. clipboard() Returns the contents of the system clipboard. snakeCase(String) Returns CamelCase string out of snake_case string. For example, if the string passed as a parameter is foo_bar, then the function returns fooBar. complete() This expression substitutes for the code completion invocation at the variable position. completeSmart() This expression substitutes for the smart type completion invocation at the variable position. componentTypeOf (<array variable or array type>) Returns component type of an array. For example, see the Live Templates in the iterations group in the other group. currentPackage() Returns the current package name. date(sDate) Returns the current system date in the specified format. By default, the current date is returned in the default system format. However, if you specify date format in double quotes, the date will be presented in this format: decapitalize(sName) Replaces the first letter of the name passed as a parameter with the corresponding lowercase letter. descendantClassEnum(<String>) Shows the children of the class entered as a string parameter. enum(sCompletionString1,sCompletionString2,...) List of comma-delimited strings suggested for completion at the template invocation. escapeString(sEscapeString) Escapes the specified string. expectedType() Returns the type which is expected as a result of the whole template. Makes sense if the template is expanded in the right part of an assignment, after return, etc. fileName(sFileName) Returns file name with extension. fileNameWithoutExtension() Returns file name without extension. firstWord(sFirstWord) Returns the first word of the string passed as a parameter. groovyScript("groovy code") Returns Groovy script with the specified code. You can use groovyScript macro with multiple arguments. The first argument is a script text that is executed or a path to the file that contains a script. The next arguments are bound to _1, _2, _3, ..._nvariables that are available inside your script. Also, _editor variable is available inside the script. This variable is bound to the current editor. guessElementType (<container>) Makes a guess on the type of elements stored in a java.util.Collection. To make a guess, IntelliJ IDEA tries to find the places where the elements were added to or extracted from the container. iterableComponentType(<ArrayOrIterable>) Returns the type of an iterable component, such as an array or a collection. iterableVariable() Returns the name of a variable that can be iterated. lineNumber() Returns the current line number. lowercaseAndDash(String) Returns lower case separated by dashes, of the string passed as a parameter. For example, the string MyExampleName is converted to my-example-name. methodName() Returns the name of the embracing method (where the template is expanded). methodParameters() Returns the list of parameters of the embracing method (where the template is expanded). methodReturnType() Returns the type of the value returned by the current method (the method within which the template is expanded). qualifiedClassName() Returns the fully qualified name of the current class (the class where the template is expanded). Clear the Shorten FQ names check box. rightSideType() Declares the left-side variable with a type of the right-side expression. It is used in theiterations group to have a single template for generating both raw-type and Generics Collections. snakeCase(sCamelCaseText) Returns snake_case string out of CamelCase string passed as a parameter. spaceSeparated(String) Returns string separated with spaces out of CamelCase string passed as a parameter. For example, if the string passed as a parameter is fooBar, then the function returns foo bar. subtypes(sType) Returns the subtypes of the type passed as a parameter. suggestIndexName() Suggests the name of an index variable. Returns i if there is no such variable in scope, otherwise returns j if there is no such variable in scope, etc. suggestVariableName() Suggests the name for a variable based on the variable type and its initializer expression, according to your code style settings that refer to the variable naming rules. For example, if it is a variable that holds an element within iteration, IntelliJ IDEA makes a guess on the most reasonable names, also taking into account the name of the container being iterated. suggestFirstVariableName(sFirstVariableName) Doesn't suggest true, false, this, super. time(sSystemTime) Returns the current system time. typeOfVariable(VAR) Returns the type of the variable passed as a parameter. underscoresToCamelCase(sCamelCaseText) Returns the string passed as a parameter with CamelHump letters substituting for underscores. For example, if the string passed as a parameter is foo_bar, then the function returns fooBar. underscoresToSpaces(sParameterWithSpaces) Returns the string passed as a parameter with spaces substituting for underscores. user() Returns the name of the current user. variableOfType(<type>) Suggests all variables that may be assigned to the type passed as a parameter, for example variableOfType("java.util.Vector"). If you pass an empty string ("") as a parameter, suggests all variables regardless of their types. JsArrayVariable Returns JavaScript array name. jsClassName() Returns the name of the current JavaScript class. jsComponentType Returns the JavaScript component type. jsMethodName() Returns the name of the current JavaScript method. jsQualifiedClassName Returns the complete name of the current JavaScript class. jsSuggestIndexName Returns a suggested name for an index. jsSuggestVariableName Returns a suggested name for a variable.
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java web在高并發(fā)和分布式下實(shí)現(xiàn)訂單號(hào)生成唯一的解決方案
這篇文章主要介紹了java web在高并發(fā)和分布式下實(shí)現(xiàn)訂單號(hào)生成唯一的解決方案,需要的朋友可以參考下2017-11-11Java下載文件時(shí)文件名亂碼問(wèn)題解決辦法
我最近在開(kāi)發(fā)時(shí)遇到了文件另存為時(shí)文件名出現(xiàn)亂碼,在火狐上正常的文件名,在IE中又出現(xiàn)亂碼問(wèn)題,然后好不容易在IE下調(diào)試好了文件名亂碼問(wèn)題,在火狐下又出現(xiàn)亂碼,最后終于感覺(jué)這樣是能解決了。具體如下:2013-04-04Sharding-Proxy分庫(kù)分表和數(shù)據(jù)加密使用場(chǎng)景分析
這篇文章主要介紹了Sharding-Proxy分庫(kù)分表和數(shù)據(jù)加密使用經(jīng)驗(yàn)分享,通過(guò)場(chǎng)景模擬分析結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04java多線程數(shù)據(jù)分頁(yè)處理實(shí)例講解
在本篇內(nèi)容里小編給大家分享了一篇關(guān)于java多線程數(shù)據(jù)分頁(yè)處理實(shí)例講解內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。2021-01-01詳解SpringBoot簡(jiǎn)化配置分析總結(jié)
這篇文章主要介紹了詳解SpringBoot簡(jiǎn)化配置分析總結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10Java下利用Jackson進(jìn)行JSON解析和序列化示例
本篇文章主要介紹了Java下利用Jackson進(jìn)行JSON解析和序列化示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-02-02java日期格式化SimpleDateFormat的使用詳解
這篇文章主要介紹了java SimpleDateFormat使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05Springboot實(shí)現(xiàn)驗(yàn)證碼登錄
這篇文章主要為大家詳細(xì)介紹了Springboot實(shí)現(xiàn)驗(yàn)證碼登錄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07java jdk1.8 使用stream流進(jìn)行l(wèi)ist 分組歸類(lèi)操作
這篇文章主要介紹了java jdk1.8 使用stream流進(jìn)行l(wèi)ist 分組歸類(lèi)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10SpringBoot整合MybatisPlus的基本應(yīng)用指南
MyBatis-Plus ,簡(jiǎn)稱(chēng) MP,是一個(gè) MyBatis的增強(qiáng)工具,在 MyBatis 的基礎(chǔ)上只做增強(qiáng)不做改變,下面小編就來(lái)和大家介紹一下SpringBoot整合MybatisPlus的一些基本應(yīng)用吧2025-03-03