Class SimpleToken

java.lang.Object
org.antlr.v4.runtime.CommonToken
com.puppycrawl.tools.checkstyle.grammar.SimpleToken
All Implemented Interfaces:
Serializable, org.antlr.v4.runtime.Token, org.antlr.v4.runtime.WritableToken

public final class SimpleToken extends org.antlr.v4.runtime.CommonToken
A simple wrapper for ANTLR Token that provides a proper equals(Object) and hashCode() implementation based on the token's type and text.

This is useful because ANTLR's default CommonToken does not override equals, It compares references.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final long
     

    Fields inherited from class org.antlr.v4.runtime.CommonToken

    channel, charPositionInLine, EMPTY_SOURCE, index, line, source, start, stop, text, type

    Fields inherited from interface org.antlr.v4.runtime.Token

    DEFAULT_CHANNEL, EOF, EPSILON, HIDDEN_CHANNEL, INVALID_TYPE, MIN_USER_CHANNEL_VALUE, MIN_USER_TOKEN_TYPE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    SimpleToken(org.antlr.v4.runtime.Token token)
    Constructs a new instance from an existing ANTLR Token.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    from(org.antlr.v4.runtime.Token token)
    Creates a new instance from an existing ANTLR Token.
    int
     

    Methods inherited from class org.antlr.v4.runtime.CommonToken

    getChannel, getCharPositionInLine, getInputStream, getLine, getStartIndex, getStopIndex, getText, getTokenIndex, getTokenSource, getType, setChannel, setCharPositionInLine, setLine, setStartIndex, setStopIndex, setText, setTokenIndex, setType, toString, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • SimpleToken

      private SimpleToken(org.antlr.v4.runtime.Token token)
      Constructs a new instance from an existing ANTLR Token.
      Parameters:
      token - the ANTLR token to wrap
  • Method Details

    • from

      public static SimpleToken from(org.antlr.v4.runtime.Token token)
      Creates a new instance from an existing ANTLR Token.
      Parameters:
      token - the ANTLR token to wrap
      Returns:
      a new instance of SimpleToken wrapping the provided token
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object