Eclipse code templates
Using Code Templates
Eclipse provided by defining and using code templates to improve the efficiency and predictability of the code capability.
We often need to write Java programs in the development process, main methods:
public static void main(String[]args) { }
If we are to write a letter a letter, but will be a repeat meaningless things, which we can use Eclipse code templates to quickly accomplish these tasks.
We just type in the main body of the class, and then use the Eclipse code prompt shortcut (default Alt + /), press Enter, and you can see Eclipse automatically help us to complete the full definition of the main function:
If we want to use System.out.println (), we only need to enter syso then press Alt + / to:
Custom code templates
Eclipse also provides a lot of code template, we can Windows-> Preferences-> Java-> Editor-> Templates (Templates you can find in the search box) to see the list of all the code template defined.
We select the playing window sysout template and click on the right Edit, appears as follows:
Edit panel is the core concern, because everything in this configuration inside. Let's familiar with this panel key five are what.
- Name: The name, in fact, it can later be used by the code abbreviations
- Context: template context, specify the code template where to take effect, so for Java contains at least four:
- Java type members, the corresponding code template is a class member, psvm strictly speaking, you should choose the template
- Java statements, the corresponding template code is a block of statements
- Java, the most common, as long as the Java code on the line
- Java doc, as the name suggests the
- Template variables: eclipse has a number of preset template variables (point Insert Varibles can see all the preset variables), such as:
- $ {Cursor} is a cursor
- $ {Date} represents the current date string
- $ {Time} string representing the current time
- $ {Line_selection} so that the current row is selected
- $ {Word_selection} let the current word is selected
- Pattern: code templates corresponding mode, as you want to format the code to enter one by one
More custom code template content you can click Help menu Help Contents option in the search field pop-up dialog box, enter "Java Editor Template Variables" select Java Editor Template Variables view specific documents describe: