Template
Template (template) can be used to quickly add a fixed form of code, in the middle can also insert parameters. For the Java editor, you can find the corresponding property page in the Eclipse settings, the path is general->java->editor->templates. This property page is the Eclipse Standard Template property page, because it's done fairly well, so you don't usually need to write one yourself.
Explore this property page carefully, try to edit the template, you may find a lot of concepts do not understand, I will explain the following
Template Properties
The template contains some basic properties:
Name: The name of the template must be unique
Context: Contexts refer to where or when the template can appear, which is equivalent to a rough classification of the template. This property makes it easy for you to hide the templates that you don't need to display at some point.
Description (description): A section detailing the template function of the text, but also remember the content hint can be displayed through the Iinformationcontrol some help information? This property is suitable for display there.
Auto Insert: Automatically inserts the template into the editor when the user's input is only possible to locate a template. or prompts the user to select a template insert, even if only one template.
The definition of a template
Templates can be defined by extension, which is org.eclipse.ui.editors.templates, or can be added manually through property pages, or programmatically. The template added through the extension point can be considered a "static template", that is, the default is there, the latter two ways to be more flexible, but a little bit of trouble.
The storage of templates
The template needs to be persisted, and it will eventually be stored in an XML file. We don't need to know where the XML file is, what the format is, these things are encapsulated by templatestore, and we can just use it. In the process of loading the template, it is necessary to load the template defined through the extension point, but also to load the user manually added template, Templatestore can only load through the extension point definition of the template, so generally use templatestore subclass Contributiontemplatestore, it provides the ability to load user-defined templates.
Stencil parameters
Templates can be embedded in the parameters, that is, we see the form of ${arg}. JTF The default definition of some parameters, programmers can also define their own parameters. Parameters can be roughly divided into two types: automatic parsing and input. The parameters that are automatically parsed are time,date, etc., which are automatically replaced with the corresponding time, date, and so on when inserting the template into the editor. The input parameter is equivalent to a placeholder, and the user replaces the parameter content with the keyboard input. The following examples do not demonstrate custom parameters, and interested readers can look at Templatevariable,globaltemplatevariables and templatevariableresolver these classes.
Implement template Features
Below I will implement the template function, then can let the template in the content hint to appear.