Class JavaInput.Tok

java.lang.Object
com.google.googlejavaformat.java.JavaInput.Tok
All Implemented Interfaces:
Input.Tok
Enclosing class:
JavaInput

static final class JavaInput.Tok extends Object implements Input.Tok
A JavaInput is a sequence of JavaInput.Toks that cover the Java input. A JavaInput.Tok is either a token (if isToken()), or a non-token, which is a comment (if isComment()) or a newline (if isNewline()) or a maximal sequence of other whitespace characters (if isSpaces()). Each JavaInput.Tok contains a sequence of characters, an index (sequential starting at 0 for tokens and comments, else -1), and a (0-origin) position in the input. The concatenation of the texts of all the JavaInput.Toks equals the input. Each Input ends with a token EOF JavaInput.Tok, with empty text.

A /* comment possibly contains newlines; a // comment does not contain the terminating newline character, but is followed by a newline JavaInput.Tok.

  • Field Details

    • index

      private final int index
    • originalText

      private final String originalText
    • text

      private final String text
    • position

      private final int position
    • columnI

      private final int columnI
    • isToken

      private final boolean isToken
    • kind

      private final com.sun.tools.javac.parser.Tokens.TokenKind kind
  • Constructor Details

    • Tok

      Tok(int index, String originalText, String text, int position, int columnI, boolean isToken, com.sun.tools.javac.parser.Tokens.TokenKind kind)
      The Tok constructor.
      Parameters:
      index - its index
      originalText - its original text, before removing Unicode escapes
      text - its text after removing Unicode escapes
      position - its 0-origin position in the input
      columnI - its 0-origin column number in the input
      isToken - whether the Tok is a token
      kind - the token kind
  • Method Details

    • getIndex

      public int getIndex()
      Description copied from interface: Input.Tok
      Return the Tok's index.
      Specified by:
      getIndex in interface Input.Tok
      Returns:
      its index
    • getText

      public String getText()
      Description copied from interface: Input.Tok
      The Tok's text.
      Specified by:
      getText in interface Input.Tok
    • getOriginalText

      public String getOriginalText()
      Description copied from interface: Input.Tok
      The Tok's original text (before processing escapes).
      Specified by:
      getOriginalText in interface Input.Tok
    • length

      public int length()
      Description copied from interface: Input.Tok
      The length of the Tok's original text.
      Specified by:
      length in interface Input.Tok
    • getPosition

      public int getPosition()
      Description copied from interface: Input.Tok
      Return the Tok's 0-based position.
      Specified by:
      getPosition in interface Input.Tok
      Returns:
      its position
    • getColumn

      public int getColumn()
      Description copied from interface: Input.Tok
      Return the Tok's 0-based column number.
      Specified by:
      getColumn in interface Input.Tok
      Returns:
      its column number
    • isToken

      boolean isToken()
    • isNewline

      public boolean isNewline()
      Description copied from interface: Input.Tok
      Is the Tok a newline?
      Specified by:
      isNewline in interface Input.Tok
    • isSlashSlashComment

      public boolean isSlashSlashComment()
      Description copied from interface: Input.Tok
      Is the Tok a "//" comment?
      Specified by:
      isSlashSlashComment in interface Input.Tok
    • isSlashStarComment

      public boolean isSlashStarComment()
      Description copied from interface: Input.Tok
      Is the Tok a "/*" comment?
      Specified by:
      isSlashStarComment in interface Input.Tok
    • isJavadocComment

      public boolean isJavadocComment()
      Description copied from interface: Input.Tok
      Is the Tok a javadoc comment?
      Specified by:
      isJavadocComment in interface Input.Tok
    • isComment

      public boolean isComment()
      Description copied from interface: Input.Tok
      Is the Tok a comment?
      Specified by:
      isComment in interface Input.Tok
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • kind

      public com.sun.tools.javac.parser.Tokens.TokenKind kind()