Package org.eclipse.jface.text.templates
Class TemplateVariable
java.lang.Object
org.eclipse.jface.text.templates.TemplateVariable
A
TemplateVariable
represents a set of positions into a
TemplateBuffer
with identical content each. TemplateVariableResolver
s
can be used to resolve a template variable to a symbol available from the
TemplateContext
. A resolved variable may have one or more possible
values
which may be presented to the user as choices. If there is no user
interaction the default value
is chosen as textual representation of
the variable.
Clients may instantiate and extend this class.
- Since:
- 3.0
- See Also:
-
Constructor Summary
ConstructorDescriptionTemplateVariable
(String type, String[] values, int[] offsets) Creates a template variable with multiple possible values.TemplateVariable
(String type, String defaultValue, int[] offsets) Creates a template variable.TemplateVariable
(String type, String name, String[] values, int[] offsets) Creates a template variable with multiple possible values.TemplateVariable
(String type, String name, String[] values, int[] offsets, int length) Creates a template variable with multiple possible values.TemplateVariable
(String type, String name, String defaultValue, int[] offsets) Creates a template variable.TemplateVariable
(TemplateVariableType type, String name, String defaultValue, int[] offsets) Creates a template variable. -
Method Summary
Modifier and TypeMethodDescriptionReturns the default value of the variable.final int
Returns the initial length of the variable.int
Returns the length of the variable's default value.getName()
Returns the name of the variable.int[]
Returns the offsets of the variable.getType()
Returns the type name of the variable.String[]
Returns the possible values for this variable.Returns the type of the variable.boolean
Returnstrue
if the variable has been resolved,false
otherwise.boolean
Returnstrue
if the variable is unambiguously resolved,false
otherwise.void
setOffsets
(int[] offsets) Sets the offsets of the variable.void
setResolved
(boolean resolved) Sets the resolved flag of the variable.void
setUnambiguous
(boolean unambiguous) Sets the isUnambiguous flag of the variable.final void
Resolves the variable to a single value.void
Resolves the variable to several possible values for this variable, with the first being the default value.
-
Constructor Details
-
TemplateVariable
Creates a template variable. The type is used as the name of the variable.- Parameters:
type
- the type of the variabledefaultValue
- the default value of the variableoffsets
- the array of offsets of the variable
-
TemplateVariable
Creates a template variable.- Parameters:
type
- the type of the variablename
- the name of the variabledefaultValue
- the default value of the variableoffsets
- the array of offsets of the variable
-
TemplateVariable
Creates a template variable.- Parameters:
type
- the type of the variablename
- the name of the variabledefaultValue
- the default value of the variableoffsets
- the array of offsets of the variable- Since:
- 3.3
-
TemplateVariable
Creates a template variable with multiple possible values. The type is used as the name of the template.- Parameters:
type
- the type of the template variablevalues
- the values available at this variable, non-emptyoffsets
- the array of offsets of the variable
-
TemplateVariable
Creates a template variable with multiple possible values.- Parameters:
type
- the type of the variablename
- the name of the variablevalues
- the values available at this variable, non-emptyoffsets
- the array of offsets of the variable
-
TemplateVariable
Creates a template variable with multiple possible values.- Parameters:
type
- the type of the variablename
- the name of the variablevalues
- the values available at this variable, non-emptyoffsets
- the array of offsets of the variablelength
- the length of the variable in the template at offset positions- Since:
- 3.11
-
-
Method Details
-
getType
Returns the type name of the variable.- Returns:
- the type name of the variable
-
getVariableType
Returns the type of the variable.- Returns:
- the type of the variable
- Since:
- 3.3
-
getName
Returns the name of the variable.- Returns:
- the name of the variable
-
getDefaultValue
Returns the default value of the variable. Typically, this is the first of the possible values (seegetValues()
.- Returns:
- the default value of the variable
-
getValues
Returns the possible values for this variable. The returned array is owned by this variable and must not be modified. The array is not empty.- Returns:
- the possible values for this variable
-
getLength
public int getLength()Returns the length of the variable's default value.- Returns:
- the length of the variable
-
getInitialLength
public final int getInitialLength()Returns the initial length of the variable. The initial length is the lenght as it occurred in the template pattern and is used when resolving a template to update the pattern with the resolved values of the variable.- Returns:
- the initial length of the variable
- Since:
- 3.11
-
setOffsets
public void setOffsets(int[] offsets) Sets the offsets of the variable.- Parameters:
offsets
- the new offsets of the variable
-
getOffsets
public int[] getOffsets()Returns the offsets of the variable. The returned array is owned by this variable and must not be modified.- Returns:
- the length of the variable
-
setValue
Resolves the variable to a single value. This is a shortcut forsetValues(new String[] { value })
.- Parameters:
value
- the new default value
-
setValues
Resolves the variable to several possible values for this variable, with the first being the default value.- Parameters:
values
- a non-empty array of values
-
setUnambiguous
public void setUnambiguous(boolean unambiguous) Sets the isUnambiguous flag of the variable.- Parameters:
unambiguous
- the new unambiguous state of the variable
-
isUnambiguous
public boolean isUnambiguous()Returnstrue
if the variable is unambiguously resolved,false
otherwise.- Returns:
true
if the variable is unambiguously resolved,false
otherwise
-
setResolved
public void setResolved(boolean resolved) Sets the resolved flag of the variable.- Parameters:
resolved
- the new resolved state- Since:
- 3.3
-
isResolved
public boolean isResolved()Returnstrue
if the variable has been resolved,false
otherwise.- Returns:
true
if the variable has been resolved,false
otherwise- Since:
- 3.3
-