Package org.eclipse.jface.text.templates
Class TemplateTranslator
java.lang.Object
org.eclipse.jface.text.templates.TemplateTranslator
The template translator translates a string into a template buffer. Regions marked as variables
are translated into
TemplateVariable
s.
The EBNF grammar of a valid string is as follows:
template := (text | escape)*. text := character - dollar. escape := dollar ('{' variable '}' | dollar). dollar := '$'. variable := identifier | identifier ':' type. type := qualifiedname | qualifiedname '(' arguments ')'. arguments := (argument ',')* argument. argument := qualifiedname | argumenttext. qualifiedname := (identifier '.')* identifier. argumenttext := "'" (character - "'" | "'" "'")* "'". identifier := javaidentifierpart - "$".
Clients may only replace the createVariable
method of this class.
- Since:
- 3.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected TemplateVariable
createVariable
(String type, String name, int[] offsets) Deprecated.protected TemplateVariable
createVariable
(TemplateVariableType type, String name, int[] offsets) Hook method to create new variables.Returns an error message if an error occurred for the last translation,null
otherwise.Translates a template string toTemplateBuffer
.Translates a template to aTemplateBuffer
.
-
Constructor Details
-
TemplateTranslator
public TemplateTranslator()
-
-
Method Details
-
getErrorMessage
Returns an error message if an error occurred for the last translation,null
otherwise.- Returns:
- the error message if an error occurred during the most recent translation,
null
otherwise
-
translate
Translates a template to aTemplateBuffer
.null
is returned if there was an error.getErrorMessage()
retrieves the associated error message.- Parameters:
template
- the template to translate.- Returns:
- returns the template buffer corresponding to the string
- Throws:
TemplateException
- if translation failed- See Also:
-
translate
Translates a template string toTemplateBuffer
.null
is returned if there was an error.getErrorMessage()
retrieves the associated error message.- Parameters:
string
- the string to translate.- Returns:
- returns the template buffer corresponding to the string
- Throws:
TemplateException
- if translation failed- See Also:
-
createVariable
Deprecated.as of 3.3 usecreateVariable(TemplateVariableType, String, int[])
insteadHook method to create new variables. Subclasses may override to supply their custom variable type.Clients may replace this method.
- Parameters:
type
- the type of the new variable.name
- the name of the new variable.offsets
- the offsets where the variable occurs in the template- Returns:
- a new instance of
TemplateVariable
-
createVariable
Hook method to create new variables. Subclasses may override to supply their custom variable type.Clients may replace this method.
- Parameters:
type
- the type of the new variable.name
- the name of the new variable.offsets
- the offsets where the variable occurs in the template- Returns:
- a new instance of
TemplateVariable
- Since:
- 3.3
-
createVariable(TemplateVariableType, String, int[])
instead