Class Token


  • public final class Token
    extends java.lang.Object
    Immutable representation of a Java token.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      TokenType type
      The type of this token.
      java.lang.String value
      The text of the token exactly as it appears in the source code.
    • Constructor Summary

      Constructors 
      Constructor Description
      Token​(java.lang.String fileName, int lineNumber, int columnNumber, TokenType type, java.lang.String value)  
      Token​(Location location, TokenType type, java.lang.String value)  
    • Field Detail

      • type

        public final TokenType type
        The type of this token.

        Strictly speaking, this field is redundant, because the token type can always be deduced from the token value, e.g. iff the value begins with "'", then the type is TokenType.CHARACTER_LITERAL.

      • value

        public final java.lang.String value
        The text of the token exactly as it appears in the source code.

        Iff this token represents a keyword, true, false, null or an operator, then this string is interned, so that it can be reference-compared with other interned strings.

    • Constructor Detail

      • Token

        public Token​(@Nullable
                     java.lang.String fileName,
                     int lineNumber,
                     int columnNumber,
                     TokenType type,
                     java.lang.String value)
      • Token

        public Token​(Location location,
                     TokenType type,
                     java.lang.String value)
    • Method Detail

      • getLocation

        public Location getLocation()
        Returns:
        The location of the first character of this token
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object