Class annotation template and method annotation template in idea

Time:2022-6-2

1. when creating a class, the class annotation is provided.

Class annotation template and method annotation template in idea

The setting steps in idea are as follows

Write the contents in 3 places.

/**

* TODO

*

* @author ${USER}

* @since ${DATE}

*/

The results are as follows:

Class annotation template and method annotation template in idea

Create a class annotation that comes with the class

2. define two sets of method templates, one for class and one for method.

Custom Java method comments:

In part 2, create a group called hozhamethod.

Step 3: create a template under group.

Step 4 is to set the character that triggers the comment.

In step 5, add an explanation and description. You can see its role later. It is to distinguish the two templates you have created.

Class annotation template and method annotation template in idea

Java method annotation template in step 6:

*

* $END$

* $param$ $return$

*/

Step 7: set the value of the variable used in the annotation. Two scripts are involved here:

Class annotation template and method annotation template in idea

param:

groovyScript( “def result=”; def params=\”${_1}\”.replaceAll(‘[\\\\[|\\\\]|\\\\s]’, ”).split(‘,’).toList(); if(\”${_1}\” != ‘[]’) { result= ‘\\n ‘; for(i = 0; i < params.size(); i++) { result+=’* @param ‘ + params[i] + ‘ ‘ + ((i < params.size() – 1) ? ‘\\n ‘: ”) }; }; return result”, methodParameters())

return:

groovyScript(“def result=\”${_1}\”; if(result == \”void\”){return \”\”;}else{return \”\\n * @return {@link \”+result+\”}\”;}”, methodReturnType())

The param script can automatically generate all method parameters and separate them.

Return parameter can be used to determine the method return value. If it is void, delete it in another line. Otherwise, the method reference

Step 8 set the shortcut key. Here I am used to using enter.

Step 9: if it has not been set, it should be define. Click it and check Java under everything.

Custom Java class comments (this is created to add comments to the newly created classes that have not been annotated):

The creation steps are as follows: replace the template in step 6 with the annotation template of the class. In addition, in step 5, pay attention to updating the description “class Annotation”, and then the following test results will be produced.

Class annotation template and method annotation template in idea

Press and hold the Enter key to display two template options

My idea version 2021.2.2 paid version.