Tame the eclipse code template of IDE

Source: Internet
Author: User

Enter the following main method each time you write a small test class:

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

It is annoying to manually enter dozens of characters. I already know that system. Out. println () can be directly generated by inputting syso and pressing Alt +/(you can try it by yourself, this code template has been set by default)

Now I want to input psvm and press Alt +/to generate the above section. What should I do?

The title of this article has provided a solution. eclipse has a powerful function-code template. How many of us have access to this function? How many people have configured some code templates based on their coding habits?

I didn't have it before, but today I feel it is very necessary to study this stuff, so I have this article.

Speak nonsense and go to the topic.

In eclipse, choose windows> preferences> JAVA> editor> templates to go to the following interface:

Select a line on the right and click the edit button to go To the edit panel page below:

The above is my own "psvm code template" (that is, the main method statement block ).

The editing panel is the core object of attention, because everything is configured here. First, familiarize yourself with the five key items in this panel.

A. Name: name, which is the abbreviation of code that can be used in the future.

B. Context: Template context, specifying where the code template will take effect. For Java, there are at least four: Java type members, Java statements, Java, and Java Doc

Java type members. The code corresponding to the template is a class member. This should be selected strictly for the psvm template.

Java statements, the code corresponding to the template is the statement Block

Java is the most common, as long as it is Java code.

Java Doc, as its name implies

C. template variables: eclipse Has preset some template variables (click Insert varibles to view all preset variables). For example, $ {cursor} indicates the cursor and $ {date} indicates the current date string, $ {time} indicates the current time string,

$ {Line_selection} indicates that the current row is selected, $ {word_selection} indicates that the current word is selected, and $ {cursor} indicates that the cursor is used. Of course, we can also define our own template variables, for example, I define a $ {mytemplatevarible}

The corresponding code displays mytemplatevarible.

D. Pattern: The pattern corresponding to the code template. Enter the pattern one by one based on the desired code format.

Now we can select new in the first interface to create our own code template.

 

Other applications:

For example, when writing Java code, we often need to add similar annotations to the class, such as @ author XXX and @ Version 1.0, which can be easily solved by using code templates.

 

Postscript:

One of the major factors of software engineering is tools, which can greatly save costs. Understanding your tools as much as possible and realizing the maximum potential of them is a goal that cannot be ignored.
This article only gives a brief introduction to Java code templates. In fact, code templates have a greater advantage in compiling HTML code, for example, you can customize a "ul_list_menu" template to generate the following menu code:

 

<ul class="topMenu">   <li class="menuItem menuItemSelected"></li>   <li class="menuItem"></li>    <li class="menuItem"></li></ul>

 

 

Other useful references:

Http://shareal.blog.163.com/blog/static/27659056201193063914196/

Http://www.coderli.com/eclipse-javadoc-template

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.