Class JavaInput.Tok

  • All Implemented Interfaces:
    Input.Tok
    Enclosing class:
    JavaInput

    static final class JavaInput.Tok
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private int columnI  
      private int index  
      private boolean isToken  
      private com.sun.tools.javac.parser.Tokens.TokenKind kind  
      private java.lang.String originalText  
      private int position  
      private java.lang.String text  
    • Constructor Summary

      Constructors 
      Constructor Description
      Tok​(int index, java.lang.String originalText, java.lang.String text, int position, int columnI, boolean isToken, com.sun.tools.javac.parser.Tokens.TokenKind kind)
      The Tok constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getColumn()
      Return the Tok's 0-based column number.
      int getIndex()
      Return the Tok's index.
      java.lang.String getOriginalText()
      The Tok's original text (before processing escapes).
      int getPosition()
      Return the Tok's 0-based position.
      java.lang.String getText()
      The Tok's text.
      boolean isComment()
      Is the Tok a comment?
      boolean isJavadocComment()
      Is the Tok a javadoc comment?
      boolean isNewline()
      Is the Tok a newline?
      boolean isSlashSlashComment()
      Is the Tok a "//" comment?
      boolean isSlashStarComment()
      Is the Tok a "/*" comment?
      (package private) boolean isToken()  
      com.sun.tools.javac.parser.Tokens.TokenKind kind()  
      int length()
      The length of the Tok's original text.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • index

        private final int index
      • originalText

        private final java.lang.String originalText
      • text

        private final java.lang.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 Detail

      • Tok

        Tok​(int index,
            java.lang.String originalText,
            java.lang.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 Detail

      • 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 java.lang.String getText()
        Description copied from interface: Input.Tok
        The Tok's text.
        Specified by:
        getText in interface Input.Tok
      • getOriginalText

        public java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • kind

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