IntelliJ IDEA detailed tutorial - theme, font, class and method annotation settings

IDEA is one of the favorite development tools for Java developers. It is high-end, intelligent, and personalized. Every developer likes to set their favorite themes and fonts to create their own IDE. This introduction is in IDEA. How to set the theme, font and other styles, and add classes, method annotations,

  • Windows users directly click the menu bar, File -> Setting, and open the settings.

  • Mac users click IntelliJ IDEA -> Preferences to open the preferences. You can see the following settings:

1. Theme style settings

1. Modification through the built-in theme (the system comes with 4 models, and I personally prefer the default Darcula)

2. Download the theme plugin from the official website

If there is no one that comes with the system that you like, you can go to the theme area of ​​the official website to choose what you like.

Theme plugin download address: https://plugins.jetbrains.com/search?tags=Theme

There are paid and free themes, you can check which theme you like, directly copy the theme name, go to the IDEA plugin to search, or you can download it directly and import it into IDEA (the follow-up article will demonstrate how to import the plugin locally).

For example, if I want to use the theme "One Dark Theme", I can search and install it in IDEA. After the installation is complete, click Apply to apply, Ok.

2. Font size modification

Open the settings window, and Windows users can select File -> Settings -> Editor -> Font to set the font and line height of our program source code. You can set it according to your own habits.

3. Class and method annotation settings

Class annotation settings: Open the settings, select Editor -> File And Code Templates -> Files, select Class, and set the class annotation template.

If you don't know which one to choose, you can see what variable information IDEA provides in the red circle of Description in the lower right corner. Similarly, you can also set annotation information such as Inteface, HTML File, CSS File, etc. After setting, check Enable Live Templates, click Apply, Ok.

The following information can be set for common types:

(1) @BelongsProject: the name of the current project

(2) @BelongsPackage: the name of the current package

(3) @Author: author's name (can be written to death, write your name)

(4) @CreateTime: the time when the class was created

(5) @Description: a description of the class (the function of the class)

(6) @Version: Set the version number. Generally, all newly created classes are version 1.0, so you can write it dead here

  1. /**

  2. *@BelongsProject: ${PROJECT_NAME}  

  3. *@BelongsPackage: ${PACKAGE_NAME}

  4. *@Author: yanhongwei

  5. *@CreateTime: ${YEAR}-${MONTH}-${DAY}  ${HOUR}:${MINUTE}

  6. *@Description: TODO

  7. *@Version: 1.0

  8. */

In addition, if you want to unify the annotation format of classes, interfaces, CSS, etc., you can set Includes, set File Header, write annotation format, check Enable Live Templates, click Apply, Ok.

Method annotation settings: Open the settings, select Editor -> File Templates, click the "+" button on the right, select 2, Template Group..., create a new group, and name it: "MyMonthTemp". as follows:

Select the template "MyMonthTemp" just created, click the "+" button on the right again, and select 1, "Live Template". to start editing. as follows:

Abbreviation: Add shortcut operation "*", combined with the default tab key

Description: template description

Template text: Annotation template content

  1. /**

  2. * Description:$description$

  3. * @Author:Lx

  4. * @Date:$date$ $time$

  5. * @Version 1.0.0

  6. $params$

  7. * @return $return$

  8. */

Click the button "Edit variables" on the right to dynamically set the parameter comments.

Date and time can be selected from the drop-down list in the Expression column.

Params and return can be dynamically returned by adding scripts.

  • Fill in the params content as:

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

  • Fill in the return content as:

  1. groovyScript("def result='';  def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split('<').toList(); for(i = 0; i < params.size(); i++) {if(i!=0){result+='<';};  def p1=params[i].split(',').toList();  for(i2 = 0; i2 < p1.size(); i2++)  { def p2=p1[i2].split('\\\\.').toList();  result+=p2[p2.size()-1]; if(i2!=p1.size()-1){result+=','}  } ; };  return result", methodReturnType())

  • The "description" in the kip if defined column is not checked, so that when typing the shortcut key to generate a method comment, you can focus the mouse on the new line, which is convenient for adding description information of the comment method;

  • Click "OK" to return to the previous setting page, and select the object to apply this template (the operation position is in the middle and lower parts), as shown in the figure below:

After adding the template, where the settings will take effect, return to the previous page, click Define,

Before setting:

After setting: Only Java-related method annotation templates are set here.

Finally, the test results are as follows:

Note: When generating comments above, you need to input "*" first, and then press the "Tab" key, so when setting the template, the first line is set to a *, in order to combine with the input characters to generate a complete and standardized comment information;

My personal setting is "/*", combined with the "Enter" key to quickly generate method comments. You can set it according to your own habits.

Well, everyone can try it, and if you have any questions, you can leave me a message.

Guess you like

Origin blog.csdn.net/best_luxi/article/details/128499182