Interface Token<D,T>

Type Parameters:
D - the type of source document identifiers
T - the type of token types; typically (but not necessarily) an enum type
All Known Implementing Classes:
Content, HonnefDemo.Token, LLJavaLexer.Token, Parser.Compile.T, Parser.Test.Token, SignatureParser.Token, SimpleToken

public interface Token<D,T>
Abstract interface of lexical tokens.
  • Method Summary

    Modifier and Type
    Method
    Description
    default @Opt Location<D>
    Returns the source location of this token.
    Returns the text content of this token.
    Returns the type of this token.
    default Token<D,T>
    withType(T type)
    Returns a token that differs from this token only by a change of token type.
  • Method Details

    • getLocation

      @Opt default @Opt Location<D> getLocation()
      Returns the source location of this token.

      The default implementation returns null.

      Returns:
      the source location of this token, or null if not available.
    • getType

      T getType()
      Returns the type of this token.
      Returns:
      the type of this token.
    • getText

      @Opt @Opt String getText()
      Returns the text content of this token.

      The default implementation returns null.

      Returns:
      the text content of this token, or null if not available.
    • withType

      default Token<D,T> withType(T type)
      Returns a token that differs from this token only by a change of token type.

      The default implementation only throws UnsupportedOperationException. Implementing classes may override this method in order to enable the feature.

      Parameters:
      type - the type of the new token
      Returns:
      a token that differs from this token only by having the given token type instead