public class JavacParser extends Object implements Parser
This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
Modifier and Type | Class and Description |
---|---|
protected static class |
JavacParser.AbstractEndPosTable |
protected static class |
JavacParser.EmptyEndPosTable |
protected static class |
JavacParser.SimpleEndPosTable |
Modifier and Type | Field and Description |
---|---|
protected TreeMaker |
F
The factory to be used for abstract syntax tree construction.
|
protected Lexer |
S
The scanner used for lexical analysis.
|
protected Tokens.Token |
token |
Modifier | Constructor and Description |
---|---|
protected |
JavacParser(ParserFactory fac,
Lexer S,
boolean keepDocComments,
boolean keepLineMap,
boolean keepEndPositions)
Construct a parser from a given scanner, tree factory and log.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(Tokens.TokenKind tk)
If next input token matches given token, skip it, otherwise report
an error.
|
JCTree.JCBlock |
block() |
protected JCTree.JCCatch |
catchClause()
CatchClause = CATCH "(" FormalParameter ")" Block
TODO: the "FormalParameter" is not correct, it uses the special "catchTypes" rule below.
|
protected JCTree.JCExpression |
checkExprStat(JCTree.JCExpression t)
Check that given tree is a legal expression statement.
|
protected JCTree.JCClassDecl |
classDeclaration(JCTree.JCModifiers mods,
Tokens.Comment dc)
ClassDeclaration = CLASS Ident TypeParametersOpt [EXTENDS Type]
[IMPLEMENTS TypeList] ClassBody
|
protected List<JCTree> |
classOrInterfaceBodyDeclaration(Name className,
boolean isInterface)
ClassBodyDeclaration =
";"
| [STATIC] Block
| ModifiersOpt
( Type Ident
( VariableDeclaratorsRest ";" | MethodDeclaratorRest )
| VOID Ident MethodDeclaratorRest
| TypeParameters (Type | VOID) Ident MethodDeclaratorRest
| Ident ConstructorDeclaratorRest
| TypeParameters Ident ConstructorDeclaratorRest
| ClassOrInterfaceOrEnumDeclaration
)
InterfaceBodyDeclaration =
";"
| ModifiersOpt Type Ident
( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" )
|
protected JCTree.JCClassDecl |
enumDeclaration(JCTree.JCModifiers mods,
Tokens.Comment dc)
EnumDeclaration = ENUM Ident [IMPLEMENTS TypeList] EnumBody
|
protected StringBuilder |
foldStrings(JCTree tree)
If tree is a concatenation of string literals, replace it
by a single literal representing the concatenated string.
|
protected JCTree.JCVariableDecl |
formalParameter()
FormalParameter = { FINAL | '@' Annotation } Type VariableDeclaratorId
LastFormalParameter = { FINAL | '@' Annotation } Type '...' Ident | FormalParameter
|
protected JCTree.JCVariableDecl |
formalParameter(boolean lambdaParameter) |
int |
getEndPos(JCTree tree)
Get the end position for a tree node.
|
int |
getStartPos(JCTree tree)
Get the start position for a tree node.
|
protected JCTree.JCVariableDecl |
implicitParameter() |
protected JCTree.JCClassDecl |
interfaceDeclaration(JCTree.JCModifiers mods,
Tokens.Comment dc)
InterfaceDeclaration = INTERFACE Ident TypeParametersOpt
[EXTENDS TypeList] InterfaceBody
|
protected JCTree |
methodDeclaratorRest(int pos,
JCTree.JCModifiers mods,
JCTree.JCExpression type,
Name name,
List<JCTree.JCTypeParameter> typarams,
boolean isInterface,
boolean isVoid,
Tokens.Comment dc)
MethodDeclaratorRest =
FormalParameters BracketsOpt [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";")
VoidMethodDeclaratorRest =
FormalParameters [Throws TypeList] ( MethodBody | ";")
InterfaceMethodDeclaratorRest =
FormalParameters BracketsOpt [THROWS TypeList] ";"
VoidInterfaceMethodDeclaratorRest =
FormalParameters [THROWS TypeList] ";"
ConstructorDeclaratorRest =
"(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody
|
protected JCTree.JCModifiers |
modifiersOpt(JCTree.JCModifiers partial) |
protected DocCommentTable |
newDocCommentTable(boolean keepDocComments,
ParserFactory fac) |
protected JavacParser.AbstractEndPosTable |
newEndPosTable(boolean keepEndPositions) |
void |
nextToken() |
JCTree.JCCompilationUnit |
parseCompilationUnit()
CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
|
JCTree.JCExpression |
parseExpression()
terms can be either expressions or types.
|
JCTree.JCStatement |
parseStatement()
Statement =
Block
| IF ParExpression Statement [ELSE Statement]
| FOR "(" ForInitOpt ";" [Expression] ";" ForUpdateOpt ")" Statement
| FOR "(" FormalParameter : Expression ")" Statement
| WHILE ParExpression Statement
| DO Statement WHILE ParExpression ";"
| TRY Block ( Catches | [Catches] FinallyPart )
| TRY "(" ResourceSpecification ";"opt ")" Block [Catches] [FinallyPart]
| SWITCH ParExpression "{" SwitchBlockStatementGroups "}"
| SYNCHRONIZED ParExpression Block
| RETURN [Expression] ";"
| THROW Expression ";"
| BREAK [Ident] ";"
| CONTINUE [Ident] ";"
| ASSERT Expression [ ":" Expression ] ";"
| ";"
| ExpressionStatement
| Ident ":" Statement
|
JCTree.JCExpression |
parseType()
parses (optional) type annotations followed by a type.
|
JCTree.JCExpression |
parseType(List<JCTree.JCAnnotation> annotations) |
protected boolean |
peekToken(Filter<Tokens.TokenKind>... kinds) |
protected boolean |
peekToken(Filter<Tokens.TokenKind> tk) |
protected boolean |
peekToken(Filter<Tokens.TokenKind> tk1,
Filter<Tokens.TokenKind> tk2) |
protected boolean |
peekToken(Filter<Tokens.TokenKind> tk1,
Filter<Tokens.TokenKind> tk2,
Filter<Tokens.TokenKind> tk3) |
protected boolean |
peekToken(int lookahead,
Filter<Tokens.TokenKind>... kinds) |
protected boolean |
peekToken(int lookahead,
Filter<Tokens.TokenKind> tk) |
protected boolean |
peekToken(int lookahead,
Filter<Tokens.TokenKind> tk1,
Filter<Tokens.TokenKind> tk2) |
protected boolean |
peekToken(int lookahead,
Filter<Tokens.TokenKind> tk1,
Filter<Tokens.TokenKind> tk2,
Filter<Tokens.TokenKind> tk3) |
JCTree.JCExpression |
qualident(boolean allowAnnos)
Qualident = Ident { DOT [Annotations] Ident }
|
protected JCTree |
resource()
Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
|
protected JCTree.JCCase |
switchBlockStatementGroup() |
protected JCTree.JCExpression |
term3()
Expression3 = PrefixOp Expression3
| "(" Expr | TypeNoParams ")" Expression3
| Primary {Selector} {PostfixOp}
Primary = "(" Expression ")"
| Literal
| [TypeArguments] THIS [Arguments]
| [TypeArguments] SUPER SuperSuffix
| NEW [TypeArguments] Creator
| "(" Arguments ")" "->" ( Expression | Block )
| Ident "->" ( Expression | Block )
| [Annotations] Ident { "." [Annotations] Ident }
| Expression3 MemberReferenceSuffix
[ [Annotations] "[" ( "]" BracketsOpt "." CLASS | Expression "]" )
| Arguments
| "." ( CLASS | THIS | [TypeArguments] SUPER Arguments | NEW [TypeArguments] InnerCreator )
]
| BasicType BracketsOpt "." CLASS
PrefixOp = "++" | "--" | "!" | "~" | "+" | "-"
PostfixOp = "++" | "--"
Type3 = Ident { "." Ident } [TypeArguments] {TypeSelector} BracketsOpt
| BasicType
TypeNoParams3 = Ident { "." Ident } BracketsOpt
Selector = "." [TypeArguments] Ident [Arguments]
| "." THIS
| "." [TypeArguments] SUPER SuperSuffix
| "." NEW [TypeArguments] InnerCreator
| "[" Expression "]"
TypeSelector = "." Ident [TypeArguments]
SuperSuffix = Arguments | "." Ident [Arguments]
|
Tokens.Token |
token() |
JCTree.JCExpression |
unannotatedType() |
<T extends ListBuffer<? super JCTree.JCVariableDecl>> |
variableDeclarators(JCTree.JCModifiers mods,
JCTree.JCExpression type,
T vdefs)
VariableDeclarators = VariableDeclarator { "," VariableDeclarator }
|
JCTree.JCExpression |
variableInitializer()
VariableInitializer = ArrayInitializer | Expression
|
protected Lexer S
protected TreeMaker F
protected Tokens.Token token
protected JavacParser(ParserFactory fac, Lexer S, boolean keepDocComments, boolean keepLineMap, boolean keepEndPositions)
protected JavacParser.AbstractEndPosTable newEndPosTable(boolean keepEndPositions)
protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac)
public Tokens.Token token()
public void nextToken()
protected boolean peekToken(Filter<Tokens.TokenKind> tk)
protected boolean peekToken(int lookahead, Filter<Tokens.TokenKind> tk)
protected boolean peekToken(Filter<Tokens.TokenKind> tk1, Filter<Tokens.TokenKind> tk2)
protected boolean peekToken(int lookahead, Filter<Tokens.TokenKind> tk1, Filter<Tokens.TokenKind> tk2)
protected boolean peekToken(Filter<Tokens.TokenKind> tk1, Filter<Tokens.TokenKind> tk2, Filter<Tokens.TokenKind> tk3)
protected boolean peekToken(int lookahead, Filter<Tokens.TokenKind> tk1, Filter<Tokens.TokenKind> tk2, Filter<Tokens.TokenKind> tk3)
protected boolean peekToken(Filter<Tokens.TokenKind>... kinds)
protected boolean peekToken(int lookahead, Filter<Tokens.TokenKind>... kinds)
public void accept(Tokens.TokenKind tk)
public int getStartPos(JCTree tree)
tree
- The tree nodepublic int getEndPos(JCTree tree)
tree
- The tree nodepublic JCTree.JCExpression qualident(boolean allowAnnos)
public JCTree.JCExpression parseExpression()
parseExpression
in interface Parser
public JCTree.JCExpression parseType()
JCTree.JCAnnotatedType
consisting of
these annotations and the underlying type. Otherwise, it returns the
underlying type.
Note that this method sets mode
to TYPE
first, before
parsing annotations.
public JCTree.JCExpression parseType(List<JCTree.JCAnnotation> annotations)
public JCTree.JCExpression unannotatedType()
protected StringBuilder foldStrings(JCTree tree)
protected JCTree.JCExpression term3()
public JCTree.JCExpression variableInitializer()
public JCTree.JCBlock block()
public JCTree.JCStatement parseStatement()
parseStatement
in interface Parser
protected JCTree.JCCatch catchClause()
protected JCTree.JCCase switchBlockStatementGroup()
protected JCTree.JCModifiers modifiersOpt(JCTree.JCModifiers partial)
public <T extends ListBuffer<? super JCTree.JCVariableDecl>> T variableDeclarators(JCTree.JCModifiers mods, JCTree.JCExpression type, T vdefs)
protected JCTree resource()
public JCTree.JCCompilationUnit parseCompilationUnit()
parseCompilationUnit
in interface Parser
protected JCTree.JCClassDecl classDeclaration(JCTree.JCModifiers mods, Tokens.Comment dc)
mods
- The modifiers starting the class declarationdc
- The documentation comment for the class, or null.protected JCTree.JCClassDecl interfaceDeclaration(JCTree.JCModifiers mods, Tokens.Comment dc)
mods
- The modifiers starting the interface declarationdc
- The documentation comment for the interface, or null.protected JCTree.JCClassDecl enumDeclaration(JCTree.JCModifiers mods, Tokens.Comment dc)
mods
- The modifiers starting the enum declarationdc
- The documentation comment for the enum, or null.protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface)
protected JCTree methodDeclaratorRest(int pos, JCTree.JCModifiers mods, JCTree.JCExpression type, Name name, List<JCTree.JCTypeParameter> typarams, boolean isInterface, boolean isVoid, Tokens.Comment dc)
protected JCTree.JCVariableDecl formalParameter()
protected JCTree.JCVariableDecl formalParameter(boolean lambdaParameter)
protected JCTree.JCVariableDecl implicitParameter()
protected JCTree.JCExpression checkExprStat(JCTree.JCExpression t)
Copyright © 2015. All rights reserved.