IntelliJ automatically generate Java code comments (Java file comments and method comments)

Source: Internet
Author: User

1 Defining a comment for the Java file header

2 adding comments to methods in the Java class

2.1 First step check Enable Live Templates

2.2 Second step create a new group

2.3 Step three Create a template

2.4 Fourth Step click on the Define button

2.5 Fifth step fill in the comment template

1, define the Java file header comments

Open the Settings panel and fill in the comment template:

File = setting = Editor = file and Code Templates

2. Add comment 2.1 to the methods in the Java class, and the first step is to check enable Live Templates

First, check the Enable Live Templates in the previous section of the diagram.

2.2, the second step to create a new group

Second, open livetemplates and create a new group

Enter the group name you want in the pop-up window, for example, I named Chenjiegroup

Click OK, you have created a new template group named Chenjiegroup

2.3, the third step to create a template

Select the new group, that is, select Chenjiegroup, and create a new livetemplate under this group

When you click Live Template, a new template is created and the cursor is positioned in a box that requires you to enter a shortcut key

I entered CJM meaning that when I entered CJM in a method inside a Java file, IntelliJ would automatically generate a comment for me on the method's head (generated according to the template I defined next).

2.4. Fourth Step click define button

Click the OK button in the top left of the Define

Select the scope in the drop-down box that pops up, select the Java file here

2.5, the fifth step to fill in the comment template

After the fourth step is completed, the contents of the Templatetext box can be edited, and the template text is written inside the templates, for example, the template I typed is:

/**

*@ description

*@ parameter $params $

*@ return value $return $

*@ founder Chenjie

*@ creation Time $date $

*@ modifying people and other information

*/

Note: In this step, the template content you can write yourself, two $ number inside is the parameter name, what parameters you can click Editvariables, and then in the pop-up window to view and select

Click on the edit Variables pop-up box

Pop-up box

, name is the name of the parameter that you can set, and expression is the one you can choose, and the drop-down box appears by clicking the cell in the Expression column.

For example, I set the expression for the three variables of params, return, date in turn

Click OK (click OK on all two windows)

OK, now it's time to verify.

Create a new Utils class

Name Utils

As you can see, the comment on the header of the file already has

Create a new method with the following content:

public static string SayHello (String userName) {return "Hello" +username;}

In the Red box where you enter the shortcut key we just set CMJ you can see the comments IntelliJ add to US

The shortcut keys need to be inside the method, that is, inside the curly braces, as well as in the position of the red box, for example, after the return statement or elsewhere, as long as it is inside the SayHello method. I'm typing cjm and I can get a hint.

OK, after you hit enter, IntelliJ replaced the CJM I entered for the comment of the method (generate comments based on the template that we set up in the previous step)

Note: At this point a bit 2, but also need to cut the annotation to the outside of the method, but it is better than we manually tap the comment. Shortcut keys can be knocked outside the method, you can also generate comments, but the parameters and return values will not be generated for you, because the parameters and return values only within the scope of the function, IntelliJ can be found, so the shortcut key is best to knock inside the method, I just CJM is inside the method of knocking.

IntelliJ automatically generate Java code comments (Java file comments and method comments)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.