Use of File code templates

Source: Internet
Author: User
Tags month name

Introduction to File Code templates

The file code template can be simply understood as: when we create certain types of files in a project, we already preset the code content in the corresponding new files. Because the text expression has a point of weakness, so the following with a Gif dynamic diagram to demonstrate.

As shown in Gif, the IntelliJ idea default class annotation format for new classes is generally not friendly or prescriptive, so we generally need to set ourselves according to the company code specification.

As shown in Gif, this is a class comment that is set according to my own needs, which is more friendly.

According to the demo we should have a good understanding of what the file code template is. For this we can derive a lot of gameplay, such as: Our Project Controller, Service, Dao and other common new objects are to inherit a class, implement some interface or preset some methods, also can be implemented by such a file code template.

Website Description: https://www.jetbrains.com/idea/help/file-and-code-templates.html

Settings for file code templates

  • As shown in callout 1, the types of files supported by the file code template are covered by the basic common file types.
  • As shown in callout 2, this is a new code template for the Java file template, which ${PACKAGE_NAME}、${NAME} is a variable IntelliJ idea preset.
  • As shown in callout 3, IntelliJ Idea's file code template can be Velocity Template Language written using (VTL). 2 #if ... #end and #parse all are VTL's syntax.
  • As shown in callout 4, some information about the current file template, as well as a description of the role of some preset variables.
  • As shown in callout 5, these four buttons are the main action buttons for the file code template, and four operations are:
  • Create TemplateCreate a file code template.
  • Remove TemplateDelete a file code template, the default template shown in callout 1 is not allowed to delete, can only delete the new ones outside the preset.
  • Copy TemplateCopy a file code template.
  • Reset To DefaultFor the modified preset file code template, revert to the default state.

As shown in callout 1, IntelliJ idea also supports other commonly created file types, and basically we don't have to worry about unsupported file types, and the basics are covered.

As shown in callout 1, the file is the one in the File Header preceding Java file code template that was introduced in the statement #parse("File Header.java") .

As the callout arrows show, ${DESCRIPTION} we define our own variables, and there are two ways to customize the variable format: $变量名 或 ${变量名} .

Custom variables must be entered when creating the corresponding file, which is already reflected in the Gif demo at the top of this article.

As Gif shows, when we need to use a custom variable of a fixed value and the variable is referenced in multiple places, we can set it through the VTL syntax #set( $变量名 = "变量值内容" ); .

Because Code the module changes not many people, so put in the last. We are unable to create and delete Code the code template inside.

As shown in callout 1, this template is called automatically when we generate a test method for a class by using a shortcut Code , so we can explain that this Code feature is mainly used when IntelliJ idea automatically helps us generate some code.

Variables for file code template presets

Because the name of the variable is too clear, so there is not much to explain, directly posted on the official website of the English explanation:

    • ${package_name}-The NAME of the target package where the new class or interface would be created.
    • ${project_name}-The NAME of the current PROJECT.
    • ${file_name}-The NAME of the PHP FILE that would be created.
    • ${name}-The NAME of the new file which you specify in the new File dialog box during the file creation.
    • ${user}-The login name of the current USER.
    • ${date}-the current system DATE.
    • ${time}-the current system time.
    • ${year}-the current year.
    • ${month}-the current MONTH.
    • ${day}-the current day of the month.
    • ${hour}-the current HOUR.
    • ${minute}-the current MINUTE.
    • ${product_name}-The NAME of the IDE in which the file would be created.
    • ${month_name_short}-the first 3 letters of the MONTH NAME. Example:jan, Feb, etc.
    • ${month_name_full}-Full NAME of a MONTH. Example:january, February, etc.

PHP file type preset variables more than the above, the specific can check the official website:

  • Official website Variable Description: https://www.jetbrains.com/idea/help/file-template-variables.html

Use of File code templates

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.