Eclipse Code Templates

Source: Internet
Author: User

The Eclipse code template uses code templates

Eclipse provides the ability to define and use code templates to improve productivity and code predictability.

We often need to write the main method in the process of developing Java programs:

public static void Main (String[]args) {}

If we write one letter at a letter, it will be a repetitive and meaningless thing, and this is where we can use the Eclipse code template to do this quickly.

We just type main in the class body and then use Eclipse's code hint shortcut (default = alt+/), and when you enter, you can see that eclipse automatically helps us complete the definition of the main function:

If we want to use SYSTEM.OUT.PRINTLN (), we just need to enter SYSO and press alt+/:

Custom code Templates

Eclipse also provides a lot of code templates that we can get through windows->preferences->java->editor->templates (you can enter Templates find in the search box) See a list of all defined code templates.

We select the Sysout template in the pop-up window and click on the right edit to display the following:

The edit panel is the core concern because everything is configured in this area. First, familiarize yourself with what the key five items in this panel are.

    • Name : In fact, it is the code abbreviation that can be used later
    • Context : template contexts, specifying where the code template will take effect, and for Java at least four of these:
      1. Java type members, the template corresponding to the code is a class member, PSVM template Strictly speaking should choose this
      2. Java statements, the code corresponding to the template is a statement block
      3. Java, the most common, as long as the Java code on the line
      4. Java Doc, as the name implies
    • template variables:eclipse has preset some template variables (point insert varibles can see all preset variables), such as:
      1. ${cursor} is a representation of the cursor
      2. ${date} represents the current date string
      3. ${time} represents the current time string
      4. ${line_selection} Let the current row be selected
      5. ${word_selection} Let the current Word be selected
      Of course we can also define our own template variables, such as I define a ${mytemplatevarible}, then the corresponding code shows the mytemplatevarible.
    • Pattern : Patterns for code templates, which you can enter in the format you want the code to be

For more custom code template content you can select Java Editor Template Var by clicking the Help Contents option in the Help menu and typing "Java Editor template Variables" on the search bar of the popup dialog box Iables See the specific document description:

Eclipse Code templates

Related Article

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.