Intellj idea how to set class header comments and method annotations

Source: Internet
Author: User
Tags month name custom name

INTELLJ idea how to set class header comments and method annotationsSource: Https://my.oschina.net/baishi/blog/617478#navbar-header

Intellj idea of the strength of not much to say, I believe that everyone who has used it will appreciate, but we will also be his complex confused, especially just from eclipse turned over the children's shoes, I believe that the beginning of the experience is not to be seen, I also step by step so came.

One of today's topics is how to implement a feature like Eclipse code templates that implements file-level annotation at the method level.

One: file-level comments

File-level comments online has been a lot of introduction, this article does not introduce, mainly through the file--"setting--" in the file and Code template to set

Two: Comment at the method level

There are a lot of file-level comments on the web, but the method-level annotations are rarely explained and many people don't know how to do it. This method I share is also a personal skill in using the INTELLJ process, and if you have a better way, you can give more ideas in the comments. The main thing is to do it through INTELLJ's powerful live template.

The following is a brief introduction to Live template (the following excerpt from the network, click here to enter the original text-more detailed use of live template and advanced, please refer to the article at the bottom of the link):

Using the Eclipse shortcut key people may not be accustomed to, Sysout, foreach and other shortcuts can not be found, the main method can not be automatically complete, in fact, this in IntelliJ has an exceptionally powerful module live template to achieve.

For example, if you try to psvm+tab in class, you will see that the main method is generated, and input iter+tab, and a foreach statement is generated.
The live template also has a surround usage, select a variable, type Ctl+alt+j two times, and an auto-complete menu appears.

In addition, you can customize the live Template. Code Snippet Technology application is also very common, IntelliJ Live template advantage is built-in some intelligent variables and functions, can do some semantic level analysis and application

Here are the steps:

1, click file--"setting--" Live Template, click on the right of the + sign, select Template Group

2. Enter MyGroup (you can also enter a different custom name), then click OK.

3. After selecting MyGroup, click the + sign on the right again to select Live Template

where abbreviation

4, click the Fourth step define, select everywhere

5, click on the right of the edit variables

6, click Ok,apply, quit, done. In front of the method, press ctrl+j , and then select a custom method annotation to experience it.

My above this little trick is just a personal in the use of INTELLJ when the use of Live template, you can refer to the following links, suggest that you read carefully, to their common code is very helpful.

Speed up encoding with code/live template under IntelliJ: The programmer's job is not to write programs, but to write programs to solve problems.

IntelliJ Live Template Advanced Use

List of predefined functions in INTELLJ Live template

Note:

Note the point:

I don't know how to bring back information such as parameters and return values, but I know why I don't show them.

User () and date () can display content because the two methods are executed in their valid scopes.

The methods of method (such as MethodName (), Methodparameters (), Methodreturntype ()) do not work because of the MC shortcut that you perform outside of the method, and the scope of these methods is within the method.

Look at the explanation of the MethodName () method: Returns The name of the embracing method (where the template is expanded). Returns the name of the methods that are working.

This is a built-in template. It contains a code fragment that can is included into file templates (Templates tab) with the help of the #pa RSEdirective.
The template is editable. Along with static text, code and comments, you can also use predefined variables that'll then be expanded like macros in to the corresponding values.

Predefined variables'll take the following values:
${package_name} Name of the which the new file is created
${user} Current User System Login name
${date} Current system date
${time} Current system time
${year} Current year
${month} Current month
${month_name_short} First 3 letters of the current month name. Example:jan, Feb, etc.
${month_name_full} Full name of the current month. Example:january, February, etc.
${day} Current day of the month
${hour} Current Hour
${minute} Current minute
${project_name} The name of the current project

Note two: Multiple parameter wrapping, you can use Groovyscript

Where the script value:

Groovyscript ("Def result="; def params=\ "${_1}\". ReplaceAll (' [\\\\[|\\\\]|\\\\s] ', '). Split (', '). ToList (); for (i = 0; i < params.size (); i++) {result+= ' * @param ' + params[i] + ((I < Params.size ()-1)? ' \\n\\b ': ')}; return result ", Methodparameters ())

  

Intellj idea how to set class header 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.