Package: org.codehaus.groovy.syntax

## [Java] Class Token

- org.codehaus.groovy.syntax.Token

-     public class Token
      extends CSTNode

  A `CSTNode` produced by the `Lexer`.

  See Also:
    Reduction
    Types

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static Token` | `EOF` |
    `static Token` | `NULL` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `Token(int type, String text, int startLine, int startColumn)` Initializes the Token with the specified information.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Reduction` | `asReduction()` Creates a `Reduction` from this token.
    `` | `public Reduction` | `asReduction(CSTNode second)` Creates a `Reduction` from this token, adding the supplied node as the second element.
    `` | `public Reduction` | `asReduction(CSTNode second, CSTNode third)` Creates a `Reduction` from this token, adding the supplied nodes as the second and third element, respectively.
    `` | `public Reduction` | `asReduction(CSTNode second, CSTNode third, CSTNode fourth)` Creates a `Reduction` from this token, adding the supplied nodes as the second, third, and fourth element, respectively.
    `` | `public Token` | `dup()` Returns a copy of this Token.
    `` | `public CSTNode` | `get(int index)` Returns the specified element, or null.
    `` | `public int` | `getMeaning()` Returns the meaning of this node.
    `` | `public Token` | `getRoot()` Returns the root of the node.
    `` | `public String` | `getRootText()` Returns the text of the root node.
    `` | `public int` | `getStartColumn()` Returns the starting column of the node.
    `` | `public int` | `getStartLine()` Returns the starting line of the node.
    `` | `public String` | `getText()` Returns the text of the token.
    `` | `public int` | `getType()` Returns the actual type of the node.
    `` | `public static Token` | `newDecimal(String text, int startLine, int startColumn)` Creates a token that represents a decimal number.
    `` | `public static Token` | `newIdentifier(String text, int startLine, int startColumn)` Creates a token that represents an identifier.
    `` | `public static Token` | `newInteger(String text, int startLine, int startColumn)` Creates a token that represents an integer.
    `` | `public static Token` | `newKeyword(String text, int startLine, int startColumn)` Creates a token that represents a keyword.
    `` | `public static Token` | `newPlaceholder(int type)` Creates a token with the specified meaning.
    `` | `public static Token` | `newString(String text, int startLine, int startColumn)` Creates a token that represents a double-quoted string.
    `` | `public static Token` | `newSymbol(int type, int startLine, int startColumn)` Creates a token that represents a symbol, using a library for the text.
    `` | `public static Token` | `newSymbol(String type, int startLine, int startColumn)` Creates a token that represents a symbol, using a library for the type.
    `` | `public CSTNode` | `setMeaning(int meaning)` Sets the meaning for this node (and its root Token).
    `` | `public void` | `setText(String text)` Not advisable, but if you need to adjust the token's text, this will do it.
    `` | `public int` | `size()` Returns the number of elements in the node (including root).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class CSTNode` | `add, addChildrenOf, asReduction, canMean, children, get, get, getDescription, getMeaning, getMeaningAs, getRoot, getRoot, getRootText, getStartColumn, getStartLine, getType, hasChildren, isA, isAllOf, isAnExpression, isEmpty, isOneOf, markAsExpression, set, setMeaning, size, toString, write, write`

- - ### Field Detail

    - #### public static final Token EOF

    - #### public static final Token NULL

  - ### Constructor Detail

    - #### public Token(int type, String text, int startLine, int startColumn)

      Initializes the Token with the specified information.

  - ### Method Detail

    - #### @Override
      public Reduction asReduction()

      Creates a `Reduction` from this token. Returns self if the node is already a `Reduction`.

    - #### public Reduction asReduction(CSTNode second)

      Creates a `Reduction` from this token, adding the supplied node as the second element.

    - #### public Reduction asReduction(CSTNode second, CSTNode third)

      Creates a `Reduction` from this token, adding the supplied nodes as the second and third element, respectively.

    - #### public Reduction asReduction(CSTNode second, CSTNode third, CSTNode fourth)

      Creates a `Reduction` from this token, adding the supplied nodes as the second, third, and fourth element, respectively.

    - #### public Token dup()

      Returns a copy of this Token.

    - #### @Override
      public CSTNode get(int index)

      Returns the specified element, or null.

    - #### @Override
      public int getMeaning()

      Returns the meaning of this node. If the node isEmpty(), returns the type of Token.NULL.

    - #### @Override
      public Token getRoot()

      Returns the root of the node. By convention, all nodes have a Token as the first element (or root), which indicates the type of the node. May return null if the node `isEmpty()`.

    - #### @Override
      public String getRootText()

      Returns the text of the root node. Uses `getRoot(true)` to get the root, so you will only receive null in return if the root token returns it.

    - #### @Override
      public int getStartColumn()

      Returns the starting column of the node. Returns -1 if not known.

    - #### @Override
      public int getStartLine()

      Returns the starting line of the node. Returns -1 if not known.

    - #### public String getText()

      Returns the text of the token. Equivalent to `getRootText()` when called directly.

    - #### @Override
      public int getType()

      Returns the actual type of the node. If the node isEmpty(), returns the type of Token.NULL.

    - #### public static Token newDecimal(String text, int startLine, int startColumn)

      Creates a token that represents a decimal number.

    - #### public static Token newIdentifier(String text, int startLine, int startColumn)

      Creates a token that represents an identifier.

    - #### public static Token newInteger(String text, int startLine, int startColumn)

      Creates a token that represents an integer.

    - #### public static Token newKeyword(String text, int startLine, int startColumn)

      Creates a token that represents a keyword. Returns null if the specified text isn't a keyword.

    - #### public static Token newPlaceholder(int type)

      Creates a token with the specified meaning.

    - #### public static Token newString(String text, int startLine, int startColumn)

      Creates a token that represents a double-quoted string.

    - #### public static Token newSymbol(int type, int startLine, int startColumn)

      Creates a token that represents a symbol, using a library for the text.

    - #### public static Token newSymbol(String type, int startLine, int startColumn)

      Creates a token that represents a symbol, using a library for the type.

    - #### @Override
      public CSTNode setMeaning(int meaning)

      Sets the meaning for this node (and its root Token). Not valid if the node isEmpty(). Returns this token, for convenience.

    - #### public void setText(String text)

      Not advisable, but if you need to adjust the token's text, this will do it.

    - #### @Override
      public int size()

      Returns the number of elements in the node (including root).