public class

Scanner

extends Object
implements Constants
java.lang.Object
   ↳ sun.tools.java.Scanner
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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.

Summary

Constants
int EOF End of input
long LINEINC The increment for each line.
long OFFSETINC The increment for each character.
[Expand]
Inherited Constants
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Fields
protected int ch The current character
public char charValue
public String docComment
public double doubleValue
public Environment env Where errors are reported
public float floatValue
public Identifier idValue
protected ScannerInputReader in Input reader
public int intValue
public long longValue
public long pos The position of the current token
public long prevPos The position of the previous token
public int radix
public boolean scanComments If true, present all comments as tokens.
public String stringValue
public int token Current token
[Expand]
Inherited Fields
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Public Constructors
Scanner(Environment env, InputStream in)
Create a scanner to scan an input stream.
Protected Constructors
Scanner(Environment env)
Create a scanner to scan an input stream.
Public Methods
long getEndPos()
The ending position of the current token
IdentifierToken getIdToken()
If the current token is IDENT, return the identifier occurrence.
void match(int open, int close)
Scan to a matching '}', ']' or ')'.
long scan()
Scan the next token.
Protected Methods
void useInputStream(InputStream in)
Setup input from the given input stream, and scan the first token from it.
long xscan()
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int EOF

End of input

Constant Value: -1 (0xffffffff)

public static final long LINEINC

The increment for each line.

Constant Value: 4294967296 (0x0000000100000000)

public static final long OFFSETINC

The increment for each character.

Constant Value: 1 (0x0000000000000001)

Fields

protected int ch

The current character

public char charValue

public String docComment

public double doubleValue

public Environment env

Where errors are reported

public float floatValue

public Identifier idValue

protected ScannerInputReader in

Input reader

public int intValue

public long longValue

public long pos

The position of the current token

public long prevPos

The position of the previous token

public int radix

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).

public String stringValue

public int token

Current token

Public Constructors

public Scanner (Environment env, InputStream in)

Create a scanner to scan an input stream.

Throws
IOException

Protected Constructors

protected Scanner (Environment env)

Create a scanner to scan an input stream.

Public Methods

public long getEndPos ()

The ending position of the current token

public IdentifierToken getIdToken ()

If the current token is IDENT, return the identifier occurrence. It will be freshly allocated.

public void match (int open, int close)

Scan to a matching '}', ']' or ')'. The current token must be a '{', '[' or '(';

Throws
IOException

public long scan ()

Scan the next token.

Returns
  • the position of the previous token.
Throws
IOException

Protected Methods

protected void useInputStream (InputStream in)

Setup input from the given input stream, and scan the first token from it.

Throws
IOException

protected long xscan ()

Throws
IOException