java.lang.Object | ||
↳ | sun.tools.java.Scanner | |
↳ | sun.tools.java.Parser |
Known Direct Subclasses |
This class is used to parse Java statements and expressions. The result is a parse tree.
This class implements an operator precedence parser. Errors are reported to the Environment object, if the error can't be resolved immediately, a SyntaxError exception is thrown.
Error recovery is implemented by catching SyntaxError exceptions and discarding input tokens until an input token is reached that is possibly a legal continuation.
The parse tree that is constructed represents the input exactly (no rewrites to simpler forms). This is important if the resulting tree is to be used for code formatting in a programming environment. Currently only documentation comments are retained.
The parsing algorithm does NOT use any type information. Changes in the type system do not affect the structure of the parse tree. This restriction does introduce an ambiguity an expression of the form: (e1) e2 is assumed to be a cast if e2 does not start with an operator. That means that (a) - b is interpreted as subtract b from a and not cast negative b to type a. However, if a is a simple type (byte, int, ...) then it is assumed to be a cast.
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.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
sun.tools.java.Scanner
| |||||||||||
From interface
sun.tools.java.Constants
| |||||||||||
From interface
sun.tools.java.RuntimeConstants
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
argIndex | |||||||||||
scanner | Usually this.scanner == (Scanner)this . |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
sun.tools.java.Scanner
| |||||||||||
From interface
sun.tools.java.Constants
| |||||||||||
From interface
sun.tools.java.RuntimeConstants
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a parser, given a scanner and the semantic callback.
|
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a parser
| |||||||||||
Create a parser, given a scanner.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
No replacement.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
Scan to a matching '}', ']' or ')'.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
Parse an Java file.
| |||||||||||
Scan the next token.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
Use the version with the IdentifierToken arguments.
| |||||||||||
This method is deprecated.
Use the version with the IdentifierToken arguments.
| |||||||||||
This method is deprecated.
Use the version with the IdentifierToken arguments.
| |||||||||||
Expect a token, return its value, scan the next token or
throw an exception.
| |||||||||||
Report the current class under construction.
| |||||||||||
This method is deprecated.
Use the version with the IdentifierToken arguments.
| |||||||||||
This method is deprecated.
Use the version with the IdentifierToken arguments.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
Parse the tail of a type expression, which might be array brackets.
| |||||||||||
Given a left-hand term, parse an operator and right-hand term.
| |||||||||||
Parse a top-level class or interface declaration.
| |||||||||||
Parse the body of a class or interface declaration,
starting at the left brace.
| |||||||||||
Parse declaration, called after the type expression
has been parsed and the current token is IDENT.
| |||||||||||
Parse an expression.
| |||||||||||
Parse a field.
| |||||||||||
@deprecated
| |||||||||||
Parse a block-local class or interface declaration.
| |||||||||||
Parse a method invocation.
| |||||||||||
Parse a possibly-empty sequence of modifier keywords.
| |||||||||||
Parse an identifier.
| |||||||||||
Parse a named class or interface declaration,
starting at "class" or "interface".
| |||||||||||
Parse a new instance expression.
| |||||||||||
Parse a statement.
| |||||||||||
Parse a primary expression.
| |||||||||||
Parse a type expression, this results in a Type.
| |||||||||||
Parse a type expression.
| |||||||||||
Recover after a syntax error in a field.
| |||||||||||
Recover after a syntax error in the file.
| |||||||||||
Recover after a syntax error in a statement.
| |||||||||||
Check if an expression is a legal toplevel expression.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
sun.tools.java.Scanner
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
sun.tools.java.ParserActions
|
Usually this.scanner == (Scanner)this
.
However, a delegate scanner can produce tokens for this parser,
in which case (Scanner)this
is unused,
except for this.token
and this.pos
instance variables which are filled from the real scanner
by this.scan()
and the constructor.
Create a parser, given a scanner and the semantic callback.
IOException |
---|
This method is deprecated.
No replacement.
Define class
This method is deprecated.
No replacement.
Define a field
c | a cookie returned by the corresponding beginClass call |
---|
This method is deprecated.
No replacement.
End class
c | a cookie returned by the corresponding beginClass call |
---|
This method is deprecated.
No replacement.
import class
This method is deprecated.
No replacement.
import package
Scan to a matching '}', ']' or ')'. The current token must be a '{', '[' or '(';
IOException |
---|
This method is deprecated.
No replacement.
package declaration
Parse an Java file.
This method is deprecated.
Use the version with the IdentifierToken arguments.
This method is deprecated.
Use the version with the IdentifierToken arguments.
This method is deprecated.
Use the version with the IdentifierToken arguments.
Expect a token, return its value, scan the next token or throw an exception.
IOException | |
---|---|
SyntaxError |
Report the current class under construction. By default, it's a no-op which returns null. It may only be called before the corresponding endClass().
This method is deprecated.
Use the version with the IdentifierToken arguments.
This method is deprecated.
Use the version with the IdentifierToken arguments.
This method is deprecated.
No replacement.
Parse the tail of a type expression, which might be array brackets. Return the given type, as possibly modified by the suffix.
IOException | |
---|---|
SyntaxError |
Given a left-hand term, parse an operator and right-hand term.
IOException | |
---|---|
SyntaxError |
Parse a top-level class or interface declaration.
IOException | |
---|---|
SyntaxError |
Parse the body of a class or interface declaration, starting at the left brace.
IOException | |
---|---|
SyntaxError |
Parse declaration, called after the type expression has been parsed and the current token is IDENT.
IOException | |
---|---|
SyntaxError |
Parse a block-local class or interface declaration.
IOException | |
---|---|
SyntaxError |
Parse a method invocation. Should be called when the current then is the '(' of the argument list.
IOException | |
---|---|
SyntaxError |
Parse a possibly-empty sequence of modifier keywords. Return the resulting bitmask. Diagnose repeated modifiers, but make no other checks. Only modifiers mentioned in the given bitmask are scanned; an unmatched modifier must be handled by the caller.
IOException |
---|
Parse an identifier. ie: a.b.c returns "a.b.c" If star is true then "a.b.*" is allowed. The return value encodes both the identifier and its location.
IOException | |
---|---|
SyntaxError |
Parse a named class or interface declaration, starting at "class" or "interface".
IOException | |
---|---|
SyntaxError |
Parse a new instance expression. Should be called when the current token is the '(' of the argument list.
IOException | |
---|---|
SyntaxError |
Parse a type expression, this results in a Type. The parse includes trailing array brackets.
IOException | |
---|---|
SyntaxError |
Parse a type expression. Does not parse the []'s.
IOException | |
---|---|
SyntaxError |
Recover after a syntax error in a field. This involves discarding tokens until an EOF or a possible legal continuation is encountered.
IOException | |
---|---|
SyntaxError |
Recover after a syntax error in the file. This involves discarding tokens until an EOF or a possible legal continuation is encountered.
IOException |
---|
Recover after a syntax error in a statement. This involves discarding tokens until EOF or a possible continuation is encountered.
IOException | |
---|---|
SyntaxError |
Check if an expression is a legal toplevel expression. Only method, inc, dec, and new expression are allowed.