Package org.eclipse.jface.text.templates
Class TemplateTranslator
- java.lang.Object
-
- org.eclipse.jface.text.templates.TemplateTranslator
-
public class TemplateTranslator extends Object
The template translator translates a string into a template buffer. Regions marked as variables are translated intoTemplateVariables.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
createVariablemethod of this class.- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description TemplateTranslator()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected TemplateVariablecreateVariable(String type, String name, int[] offsets)Deprecated.as of 3.3 usecreateVariable(TemplateVariableType, String, int[])insteadprotected TemplateVariablecreateVariable(TemplateVariableType type, String name, int[] offsets)Hook method to create new variables.StringgetErrorMessage()Returns an error message if an error occurred for the last translation,nullotherwise.TemplateBuffertranslate(String string)Translates a template string toTemplateBuffer.TemplateBuffertranslate(Template template)Translates a template to aTemplateBuffer.
-
-
-
Method Detail
-
getErrorMessage
public String getErrorMessage()
Returns an error message if an error occurred for the last translation,nullotherwise.- Returns:
- the error message if an error occurred during the most recent translation,
nullotherwise
-
translate
public TemplateBuffer translate(Template template) throws TemplateException
Translates a template to aTemplateBuffer.nullis 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:
getErrorMessage()
-
translate
public TemplateBuffer translate(String string) throws TemplateException
Translates a template string toTemplateBuffer.nullis 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:
getErrorMessage()
-
createVariable
@Deprecated protected TemplateVariable createVariable(String type, String name, int[] offsets)
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
protected TemplateVariable createVariable(TemplateVariableType type, String name, int[] offsets)
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
-
-