1
头图

[Learning Record] IDEA Editor - Class and Method Template Configuration

introduction

This article is used as a personal IDEA editor class, method template configuration operation learning record, which is convenient for upgrading IDEA or developing to a new environment for quick configuration.

Of course, there are a lot of IDEA configurations on the Internet. I have read a lot of blog configurations and there are always problems with this problem. I simply record it myself to avoid wasting time.

Zero, environmental description

  • Operating system: Mac (only represents my environment, in fact, it is the same, mainly depends on the IDEA version)
  • IDEA version: any version of IDEA, the IDEA 2022.1 version is recorded here

The only thing to note is that the old version of IDEA may have some descriptions that are a bit different when configuring, but most of the content should not have changed much.

1. FileHead template

Introduction: File Header refers to what is automatically added at the top when creating a JAVA file.

The configuration content corresponding to the screenshot:

 /**
 * @Package : ${PACKAGE_NAME}
 * @Description : TODO
 * @Create on : ${DATE} ${HOUR}:${MINUTE}
 * @author 自己的姓名或者昵称
 * @version v1.0.0
 **/

2. Quick command template configuration

Introduction: The command template is to generate the template we want by specifying the key when writing special "keywords".

First, let's take a look at the configuration completion rendering, including a group, a class command template and a method command template:

method template

How to use

It's very simple and only takes two steps to complete.

  1. Type a /** on the code that needs to add method comments.

  1. Then press Tab and the following effect will appear.

accomplish

Enter the Setting page, without looking at the configuration of IDEA, we create a new command group of our own, which is convenient for our own search and subsequent management. After the new group is created, first select the newly created group , and then continue to follow the screenshots on the newly created group, but This time we add specific template commands to our group.

It is conceivable to configure the operation of the parent-child menu by yourself. I believe that readers who read this article can understand it.

First, we add a method template. Description is to add a note to our command template. Abbreviation is the "keyword" that triggers the command. Note that there is a "Tab" option at the top of the screenshot below, which means that after we write the keyword, we need to press "Tab" triggers.

The template content is as follows:

 ** 
 * @description $description$ 
 * @param $params$ 
 * @return $returns$ 
 * @author $USER$
 * @date $date$ $time$
 */

Note: Look carefully at the "keyword", there is no need for / in front of the template content , you can add a / for the specific reason and then try to use it at the beginning to understand.

Next, we first configure "everywhere" for our template, which means that it can be used anywhere. Of course, if you are afraid of making mistakes, you can find JAVA-related files to specify and add them. If you are lazy, you can directly "everywhere".

Then click edit variables , we solve the formatting content of the function placeholder, and configure the default value of the parameters after generating the template. At this point, you need to cheer up, because it is easier to reproduce the problem.

Contents like $ description $ are function placeholders, and the specific functions are explained below.

Corresponding to the content you want to fill in, you can configure it by referring to the screenshot:

  • description: TODO
  • params : (This piece is easier to copy and have problems, and it only takes one line to paste on IDEA, multi-validation)

     groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+='' + params[i] + ((i < params.size() - 1) ? ' \\n ' + '* @param: ' : '')};return result", methodParameters())
  • returns: methodReturnType()
  • user: user()
  • date: date()
  • time: time()

The effect diagram of all configuration is as follows:

Finally, try it yourself according to the usage method :

 /**   
* @description    
* @param xxx   
* @param: xxx   
* @param: xxx   
* @return com.xxx 
* @author xxx  
 * @date 2022/5/25 20:05  
 */

class template

The class template configuration is much simpler than the method, so I will briefly explain it here.

How to use

Similar to "Method Template", except that you type an asterisk and then press "Tab".

accomplish

As usual, click the "+" sign in the upper right corner in live template to create a new group. After the creation is complete, create a new command template in the custom group. If these are done, ignore this paragraph.

If there is no problem with the method template configuration provided above and it can be used normally, this part of the content can be used quickly. I will not explain more here and just look at the specific operation.

Abbreviation: * (note that / is not required before)
Des: class template (write whatever you want)

Template template content:

 **
 * @description: TODO
 * @author $user$
 * @date $date$ $time$
 * @version 1.0
 */

If no command is fired, check if "everywhere" is set.

Click edit variables , you can configure the default value of the parameters after generating the template

  • user: user()
  • date: date()
  • time: time()

The final effect is as follows, and the places to be rewritten are framed:

The final reference renderings are as follows:

Finally, just like the method template, find a class to verify it yourself:

 /**  
 * @description: TODO  
 * @author xxx  
 * @date 2022/5/25 19:50  
 * @version 1.0  
 */

All of the above content will be handy after several operations. It is worth noting that the content of the script should not be copied wrongly.

Finish work.


Xander
201 声望53 粉丝

引用和评论

0 条评论