java.lang.Object
org.glassfish.rmic.tools.java.Scanner
All Implemented Interfaces:
Constants, RuntimeConstants
Direct Known Subclasses:
Parser

public class Scanner extends Object implements Constants
A Scanner for Java tokens. Errors are reported to the environment object.

The scanner keeps track of the current token, the value of the current token (if any), and the start position of the current token.

The scan() method advances the scanner to the next token in the input.

The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counter part. This is useful during error recovery.

An position consists of: ((linenr << WHEREOFFSETBITS) | offset) this means that both the line number and the exact offset into the file are encoded in each position value.

The compiler treats either "\n", "\r" or "\r\n" as the end of a line.

WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.

Author:
Arthur van Hoff
  • Field Details

    • OFFSETINC

      public static final long OFFSETINC
      The increment for each character.
      See Also:
    • LINEINC

      public static final long LINEINC
      The increment for each line.
      See Also:
    • EOF

      public static final int EOF
      End of input
      See Also:
    • env

      public Environment env
      Where errors are reported
    • in

      protected ScannerInputReader in
      Input reader
    • scanComments

      public boolean scanComments
      If true, present all comments as tokens. Contents are not saved, but positions are recorded accurately, so the comment can be recovered from the text. Line terminations are also returned as comment tokens, and may be distinguished by their start and end positions, which are equal (meaning, these tokens contain no chars).
    • token

      public int token
      Current token
    • pos

      public long pos
      The position of the current token
    • prevPos

      public long prevPos
      The position of the previous token
    • ch

      protected int ch
      The current character
    • charValue

      public char charValue
    • intValue

      public int intValue
    • longValue

      public long longValue
    • floatValue

      public float floatValue
    • doubleValue

      public double doubleValue
    • stringValue

      public String stringValue
    • idValue

      public Identifier idValue
    • radix

      public int radix
    • docComment

      public String docComment
  • Constructor Details

  • Method Details

    • useInputStream

      protected void useInputStream(InputStream in) throws IOException
      Setup input from the given input stream, and scan the first token from it.
      Throws:
      IOException
    • getEndPos

      public long getEndPos()
      The ending position of the current token
    • getIdToken

      public IdentifierToken getIdToken()
      If the current token is IDENT, return the identifier occurrence. It will be freshly allocated.
    • scan

      public long scan() throws IOException
      Scan the next token.
      Returns:
      the position of the previous token.
      Throws:
      IOException
    • xscan

      protected long xscan() throws IOException
      Throws:
      IOException
    • match

      public void match(int open, int close) throws IOException
      Scan to a matching '}', ']' or ')'. The current token must be a '{', '[' or '(';
      Throws:
      IOException