Create your own code template in IntelliJ idea

Source: Internet
Author: User
In IDE settings (ctrl+alt+s), choose to open the Live Templates page, expand the template group you want to view, select an existing template to click "Edit" to modify it, or click "Add" to create a new template; on Edit Live Template dialog box, you can modify the abbreviation (abbreviation) of the template, and in the Template text area, you can edit the template body, including normal text and variables, and the variables at the beginning and end of the dollar ' $ ' (such as $type$), and if you need to modify the variable, click " Edit Variables button; In the options area, we can specify that the template should be expanded or reformatted; In the context area, we can describe the language of the template and the abbreviations in which editors need to identify the template, and then click the "OK" button when the modification is complete;

At the same time, we can generate the template directly from the text fragment being edited, as follows: In the editor, select the text fragment to create the template, and in the main menu, select Tools | Save as Live Template, the Edit Live Template dialog box appears, the abbreviation for the new template is entered in the abbreviation area, the input template body, the variable, the template group, and the corresponding options; Click OK when the modification is complete;

When editing a template variable, in the Edit Template Variables dialog box after clicking "Edit Variables", you can see that there are four properties for modifying the variable, named (name), expression (Expression), Default value and if the variable has been defined whether or not skipped (skip if defined); Name (name), the name of the variable in the template body, excluding the $ symbol at the beginning and end, the expression (Expression), the expression that specifies the variable, It automatically calculates the corresponding template input field; You can either enter directly or select a predefined function in the Drop-down list, the number and type (if any) of the function arguments are also described in the Drop-down list, and the default value, which indicates a string as the default value for the variable, If in the expanded template, the expression does not give any results after the calculation, the template uses this default value, which is used only when an expression has been specified for the variable, if the variable has been defined to skip (skip if defined), and if this option is selected, when the template is expanded , the variable already has a value or a default value that is evaluated after the expression evaluates, then skips directly to the next input field for editing; the dialog box has two buttons to the right, "Move Up" and "Move Down" to adjust the order of the variables , and the order of the variables in the upper and lower order determines the sequence in which the editor switches between the corresponding input fields after the template is expanded;

IntelliJ idea provides us with some very useful functions to twos: Capitalize (<name>), capitalizing the first letter of the incoming parameter, ClassName (), the name of the class where the template expands, date (), current date; Iterablevariable (), the name of the variable that can be iterated, complete (), the call of the code completion at the position of the variable;

IntelliJ idea provides more than 30 functions that you can use to refer to the online Help document or the predefined templates in IntelliJ idea.

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.