Class TokenImpl

  • All Implemented Interfaces:
    Token, TokenTypes

    class TokenImpl
    extends java.lang.Object
    implements Token
    Implementation of a token in a Java source file.
    Version:
    1.0
    • Field Detail

      • type

        private int type
      • lexeme

        private java.lang.String lexeme
        The token's text.
      • line

        private int line
        The line the token is on.
      • column

        private int column
        The column the token is on.
      • offset

        private int offset
        The absolute offset into the source of the token.
      • invalid

        private boolean invalid
        Whether the token is invalid (e.g. an invalid char of String).
    • Constructor Detail

      • TokenImpl

        TokenImpl​(int type,
                  java.lang.String lexeme,
                  int line,
                  int column,
                  int offs)
      • TokenImpl

        TokenImpl​(int type,
                  java.lang.String lexeme,
                  int line,
                  int column,
                  int offs,
                  boolean invalid)
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getColumn

        public int getColumn()
        Description copied from interface: Token
        Returns the column (offset into the line) of this token.
        Specified by:
        getColumn in interface Token
        Returns:
        The column of the token.
        See Also:
        Token.getLine()
      • getLength

        public int getLength()
        Description copied from interface: Token
        Returns the length of this token.
        Specified by:
        getLength in interface Token
        Returns:
        The token's length.
      • getLexeme

        public java.lang.String getLexeme()
        Description copied from interface: Token
        Returns the text of this token.
        Specified by:
        getLexeme in interface Token
        Returns:
        This token's textual value.
      • getLine

        public int getLine()
        Description copied from interface: Token
        Returns the line this token is on.
        Specified by:
        getLine in interface Token
        Returns:
        The token's line number.
        See Also:
        Token.getColumn()
      • getType

        public int getType()
        Description copied from interface: Token
        Returns the type of this token.
        Specified by:
        getType in interface Token
        Returns:
        The type of this token.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • isBasicType

        public boolean isBasicType()
        Description copied from interface: Token
        Returns whether this token is a primitive data type (int, float, string, etc.).
        Specified by:
        isBasicType in interface Token
        Returns:
        Whether this token is a primitive data type.
      • isIdentifier

        public boolean isIdentifier()
        Description copied from interface: Token
        Returns whether this token is an identifier.
        Specified by:
        isIdentifier in interface Token
        Returns:
        Whether this token is an identifier.
      • isInvalid

        public boolean isInvalid()
        Description copied from interface: Token
        Returns whether this token is invalid.
        Specified by:
        isInvalid in interface Token
        Returns:
        Whether this token is invalid.
      • isOperator

        public boolean isOperator()
        Description copied from interface: Token
        Returns whether this token is an operator.
        Specified by:
        isOperator in interface Token
        Returns:
        Whether this token is an operator.
      • isType

        public boolean isType​(int type)
        Description copied from interface: Token
        Returns whether this token is of the specified type.
        Specified by:
        isType in interface Token
        Parameters:
        type - The type to check.
        Returns:
        Whether this token is of the specified type.
      • toString

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