欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

IDEA添加Java类注释模版的方法

程序员文章站 2024-02-23 15:44:16
本文介绍了idea添加java类注释模版的方法,分享给大家,具体如下: idea版本:intellij idea 2017.2.5 x64 eclipse能在类上方输入...

本文介绍了idea添加java类注释模版的方法,分享给大家,具体如下:

idea版本:intellij idea 2017.2.5 x64

eclipse能在类上方输入/**,回车添加类注释模版,但idea没有默认添加这个功能,需要做一些设置。下面介绍三种方法实现:

  1. 创建类默认添加类注释
  2. 手动添加类注释
  3. 批量添加javadoc注释

一、设置新建类默认添加注释

依次点击setting|editor|file and code templates,添加如图配置
IDEA添加Java类注释模版的方法

例子:

/**
*describe: 
*
*@author xxx
*@date ${year}/${month}/${day}
*/

支持的变量在描述内,找到需要配置即可!

二、利用live template手动添加注释模版

依次点击setting|editor|live templates

1、点击+添加templates group,如my live templates

IDEA添加Java类注释模版的方法

2、点击+添加live templates,修改abbreviation,再添加模版内容,模版变量以$var$格式定义,如

/**
*describe: 
*
*@author xxx
*@date $date$
*/

IDEA添加Java类注释模版的方法 

3. 点击define定义模版作用范围,选择java

IDEA添加Java类注释模版的方法 

4. 点击edit variables定义变量,表达式解释见附件

IDEA添加Java类注释模版的方法 

5. 保存后,在类任意位置输入cc即可添加模版

三、批量添加注释

安装javadoc插件,alt+insert即可批量添加注释,包括所有类和方法,但是不能定制化,注释都是固定的。

IDEA添加Java类注释模版的方法

附件

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.

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。