class annotation
Open IDEA's Settings, click Editor->File and Code Templates, click Class under the File tab on the right, and add
/** * @author liu to it
- @date YEAR {YEAR}Y E A R year {MONTH} month ${DAY} day ${TIME}
*/
Configure the interface
Same as above, select Interface configuration
method annotation
Automatically generate @param annotations
based on formal parameters Intelligently generate @Return annotations based on whether the method has a return value
1. First click on Editor->Live Templates in Settings.
Click the + on the far right, first select 2. Template Group… to create a template group
, then select the template group customTemp just created, then click +, select 1. Live Template:
At this point, an empty template will be created, we modify The Abbreviation, Description, and Template text of the template. It should be noted that Abbreviation must be *, and finally check whether the value of Expand with is the Enter key.
/* *
- @author liu
- @date d a t e date date t i m e time time p a r a m param param r e t u r n return return
*/
Click Define and check Java in the pop-up box, which means that the template will be applied to all Java type files.
set applicable contexts
to date dateThe dat e parameters are used for method mapping, so that IDEA can understand the meaning of these parameters . Click the Edit variables button:
set the Expression
It should be noted that the Expressions of date and time use IDEA's built-in functions, you can directly use the drop-down box to select, and the default implementation of the param parameter IDEA is very poor, so we need to implement it manually, the code is as follows:
param
groovyScript(“def result = ‘’;def params = “${_1}”.replaceAll(‘[\\[|\\]|\\s]’, ‘’).split(‘,’).toList(); for(i = 0; i < params.size(); i++) {if(params[i] != ‘’)result+='* @param ’ + params[i] + ’ ’ +((i < params.size() - 1) ? '\r\n ’ : ‘’)}; return result == ‘’ ? null : result”, methodParameters())
return
groovyScript("def returnType = "${_1}"; def result ='';if(returnType=='null'||returnType=='void'){return;}else{result += '* @return' ;cls = returnType.split('<');for(i = 0; i < cls.size(); i++){temp = cls[i].tokenize('.');result += temp[temp. size() - 1] + ((i < cls.size() - 1) ? '<' : '');};return result + ' ';}", methodReturnType());
Don't forget to click " Apply" and "OK" to save the settings.