Package org.eclipse.jface.text.templates
Class TemplateVariable
- java.lang.Object
-
- org.eclipse.jface.text.templates.TemplateVariable
-
public class TemplateVariable extends Object
ATemplateVariable
represents a set of positions into aTemplateBuffer
with identical content each.TemplateVariableResolver
s can be used to resolve a template variable to a symbol available from theTemplateContext
. A resolved variable may have one or more possiblevalues
which may be presented to the user as choices. If there is no user interaction thedefault value
is chosen as textual representation of the variable.Clients may instantiate and extend this class.
- Since:
- 3.0
- See Also:
TemplateVariableResolver
,TemplateBuffer
-
-
Constructor Summary
Constructors Constructor Description TemplateVariable(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getDefaultValue()
Returns the default value of the variable.int
getInitialLength()
Returns the initial length of the variable.int
getLength()
Returns the length of the variable's default value.String
getName()
Returns the name of the variable.int[]
getOffsets()
Returns the offsets of the variable.String
getType()
Returns the type name of the variable.String[]
getValues()
Returns the possible values for this variable.TemplateVariableType
getVariableType()
Returns the type of the variable.boolean
isResolved()
Returnstrue
if the variable has been resolved,false
otherwise.boolean
isUnambiguous()
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.void
setValue(String value)
Resolves the variable to a single value.void
setValues(String[] values)
Resolves the variable to several possible values for this variable, with the first being the default value.
-
-
-
Constructor Detail
-
TemplateVariable
public TemplateVariable(String type, String defaultValue, int[] offsets)
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
public TemplateVariable(String type, String name, String defaultValue, int[] offsets)
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
public TemplateVariable(TemplateVariableType type, String name, String defaultValue, int[] offsets)
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
public TemplateVariable(String type, String[] values, int[] offsets)
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
public TemplateVariable(String type, String name, String[] values, int[] offsets)
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
public TemplateVariable(String type, String name, String[] values, int[] offsets, int length)
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 Detail
-
getType
public String getType()
Returns the type name of the variable.- Returns:
- the type name of the variable
-
getVariableType
public TemplateVariableType getVariableType()
Returns the type of the variable.- Returns:
- the type of the variable
- Since:
- 3.3
-
getName
public String getName()
Returns the name of the variable.- Returns:
- the name of the variable
-
getDefaultValue
public String 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
public String[] 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
public final void setValue(String value)
Resolves the variable to a single value. This is a shortcut forsetValues(new String[] { value })
.- Parameters:
value
- the new default value
-
setValues
public void setValues(String[] values)
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
-
-