preface
Recently, I wrote in Ali’s Java code specification that all classes must add creator information, so I became familiar with how to add class annotation information, and also learned the steps of method annotation. The detailed steps for both annotation Settings are as follows.
Class notes
Setting up class annotations is relatively simple. First, use the shortcut CTRL + Alt + S to pop up the Settings dialog box. Select File and Code Templates in the Editor and select the File Header option in Includes:
In the edit box on the right, you can customize the comments you want to render. Here I just fill in the author and date:
/**
*
* @author: ${USER}
* @date: ${DATE}
*/
Copy the code
This will automatically show the author and the current date each time you create a new class, although you can add other content here as well.
Methods the annotation
To set method comments, first use the shortcut CTRL + Alt + S again, go to Editor, and select the Live Templates option here:
In the displayed option box, click + and select Template Group to create a new Template Group called CustomTemplate (optionally):
Click OK to see a new CustomTemplate item in the list. Select this item and click + to select Live Template:
Set the Abbreviation to CMT, which is a shortcut to the comment, so that the comment appears when you type CMD above the method. Of course, you can set it to any other character. Then edit the comment Template in Template Text:
Description param return value type return author time time:
/**
*
* @description $desc$
* @param $methodParameters$
* @return $methodReturnType$
* @author $user$
* @time $date$ $time$
*/
Copy the code
Then click onChange
chooseDeclaration
Display when it is set to comment.
Click Edit Variables to start setting the functions of each name. For example, setting the expression for name user to user() will automatically display the author name and date() will automatically display the latest date:
Click OK Apply. Enter CMT on the method in the Java file to bring up the setup template as follows: