Package org.eclipse.jface.text.templates

## Class TemplateVariable

- java.lang.Object
- - org.eclipse.jface.text.templates.TemplateVariable

    public class TemplateVariable
    extends Object

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:
  `TemplateVariableResolver`, `TemplateBuffer`

### Constructor Summary

Constructors
`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 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
`String` `getDefaultValue()` Returns the default value 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()` Returns `true` if the variable has been resolved, `false` otherwise.
`boolean` `isUnambiguous()` Returns `true` 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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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 variable
  `defaultValue` - the default value of the variable
  `offsets` - 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 variable
  `name` - the name of the variable
  `defaultValue` - the default value of the variable
  `offsets` - 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 variable
  `name` - the name of the variable
  `defaultValue` - the default value of the variable
  `offsets` - 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 variable
  `values` - the values available at this variable, non-empty
  `offsets` - 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 variable
  `name` - the name of the variable
  `values` - the values available at this variable, non-empty
  `offsets` - the array of offsets of the variable

### 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 (see `getValues()`.

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

#### 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 for `setValues(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()

Returns `true` 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()

Returns `true` if the variable has been resolved, `false` otherwise.

Returns:
  `true` if the variable has been resolved, `false` otherwise
Since:
  3.3