服务器之家

服务器之家 > 正文

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

时间:2021-03-01 15:10     来源/作者:shengpli

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

idea版本:intellij idea 2017.2.5 x64

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

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

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

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

例子:

?
1
2
3
4
5
6
/**
*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$格式定义,如

?
1
2
3
4
5
6
/**
*describe:
*
*@author xxx
*@date $date$
*/

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

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

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

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

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

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

三、批量添加注释

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

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

附件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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.

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

原文链接:http://blog.csdn.net/qq_23146763/article/details/78668885

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部