Home » openjdk-7 » com.sun.tools » javac » parser » [javadoc | source]
com.sun.tools.javac.parser
public class: JavacParser [javadoc | source]
java.lang.Object
   com.sun.tools.javac.parser.JavacParser

All Implemented Interfaces:
    Parser

Direct Known Subclasses:
    EndPosParser

The parser maps a token sequence into an abstract syntax tree. It operates by recursive descent, with code derived systematically from an LL(1) grammar. For efficiency reasons, an operator precedence scheme is used for parsing binary operation expressions.

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.
Field Summary
protected  TreeMaker F    The factory to be used for abstract syntax tree construction. 
 boolean allowGenerics    Switch: Should generics be recognized? 
 boolean allowDiamond    Switch: Should diamond operator be recognized? 
 boolean allowMulticatch    Switch: Should multicatch clause be accepted? 
 boolean allowVarargs    Switch: Should varargs be recognized? 
 boolean allowAsserts    Switch: should we recognize assert statements, or just give a warning? 
 boolean allowEnums    Switch: should we recognize enums, or just give a warning? 
 boolean allowForeach    Switch: should we recognize foreach? 
 boolean allowStaticImport    Switch: should we recognize foreach? 
 boolean allowAnnotations    Switch: should we recognize annotations? 
 boolean allowTWR    Switch: should we recognize try-with-resources? 
 boolean keepDocComments    Switch: should we keep docComments? 
 boolean keepLineMap    Switch: should we keep line table? 
static final  int EXPR    When terms are parsed, the mode determines which is expected: mode = EXPR : an expression mode = TYPE : a type mode = NOPARAMS : no parameters allowed for type mode = TYPEARG : type argument 
static final  int TYPE     
static final  int NOPARAMS     
static final  int TYPEARG     
static final  int DIAMOND     
 Map<JCTree, String> docComments    A hashtable to store all documentation comments indexed by the tree nodes they refer to. defined only if option flag keepDocComment is set. 
 ListBuffer<JCExpression> odStackSupply    optimization: To save allocating a new operand/operator stack for every binary operation, we use supplys. 
 ListBuffer<Token> opStackSupply     
 ListBuffer<int> posStackSupply     
Constructor:
 protected JavacParser(ParserFactory fac,
    Lexer S,
    boolean keepDocComments,
    boolean keepLineMap) 
    Construct a parser from a given scanner, tree factory and log.
Method from com.sun.tools.javac.parser.JavacParser Summary:
accept,   annotation,   annotationFieldValue,   annotationFieldValues,   annotationFieldValuesOpt,   annotationValue,   annotationsOpt,   arguments,   arguments,   argumentsOpt,   arrayCreatorRest,   arrayInitializer,   attach,   basicType,   block,   block,   blockStatements,   bracketsSuffix,   catchClause,   catchTypes,   checkAnnotations,   checkDiamond,   checkExprStat,   checkForeach,   checkGenerics,   checkMulticatch,   checkNoMods,   checkStaticImports,   checkTryWithResources,   checkVarargs,   classCreatorRest,   classDeclaration,   classOrInterfaceBody,   classOrInterfaceBodyDeclaration,   classOrInterfaceOrEnumDeclaration,   creator,   earlier,   enumBody,   enumDeclaration,   enumeratorDeclaration,   error,   foldStrings,   forInit,   forUpdate,   formalParameter,   formalParameters,   getEndPos,   getErrorEndPos,   getStartPos,   ident,   illegal,   illegal,   importDeclaration,   innerCreator,   interfaceDeclaration,   isZero,   literal,   methodDeclaratorRest,   modifiersOpt,   modifiersOpt,   moreStatementExpressions,   optFinal,   optag,   parExpression,   parseCompilationUnit,   parseExpression,   parseStatement,   parseType,   prec,   qualident,   qualidentList,   resource,   resources,   storeEnd,   strval,   superSuffix,   switchBlockStatementGroups,   term,   term,   term1,   term1Rest,   term2,   term2Rest,   term3,   termRest,   to,   toP,   typeArgument,   typeArguments,   typeArguments,   typeArgumentsOpt,   typeArgumentsOpt,   typeArgumentsOpt,   typeDeclaration,   typeList,   typeParameter,   typeParametersOpt,   typetag,   unoptag,   variableDeclarator,   variableDeclaratorId,   variableDeclaratorRest,   variableDeclarators,   variableDeclaratorsRest,   variableInitializer,   warning
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.sun.tools.javac.parser.JavacParser Detail:
 public  void accept(Token token) 
    If next input token matches given token, skip it, otherwise report an error.
 JCAnnotation annotation(int pos) 
    Annotation = "@" Qualident [ "(" AnnotationFieldValues ")" ]
 JCExpression annotationFieldValue() 
    AnnotationFieldValue = AnnotationValue | Identifier "=" AnnotationValue
 List<JCExpression> annotationFieldValues() 
    AnnotationFieldValues = "(" [ AnnotationFieldValue { "," AnnotationFieldValue } ] ")"
 List<JCExpression> annotationFieldValuesOpt() 
 JCExpression annotationValue() 
 List<JCAnnotation> annotationsOpt() 
    AnnotationsOpt = { '@' Annotation }
 List<JCExpression> arguments() 
    Arguments = "(" [Expression { COMMA Expression }] ")"
 JCMethodInvocation arguments(List<JCExpression> typeArgs,
    JCExpression t) 
 JCExpression argumentsOpt(List<JCExpression> typeArgs,
    JCExpression t) 
    ArgumentsOpt = [ Arguments ]
 JCExpression arrayCreatorRest(int newpos,
    JCExpression elemtype) 
    ArrayCreatorRest = "[" ( "]" BracketsOpt ArrayInitializer | Expression "]" {"[" Expression "]"} BracketsOpt )
 JCExpression arrayInitializer(int newpos,
    JCExpression t) 
    ArrayInitializer = "{" [VariableInitializer {"," VariableInitializer}] [","] "}"
  void attach(JCTree tree,
    String dc) 
    Make an entry into docComments hashtable, provided flag keepDocComments is set and given doc comment is non-null.
 JCPrimitiveTypeTree basicType() 
    BasicType = BYTE | SHORT | CHAR | INT | LONG | FLOAT | DOUBLE | BOOLEAN
 public JCBlock block() 
 JCBlock block(int pos,
    long flags) 
    Block = "{" BlockStatements "}"
 List<JCStatement> blockStatements() 
    BlockStatements = { BlockStatement } BlockStatement = LocalVariableDeclarationStatement | ClassOrInterfaceOrEnumDeclaration | [Ident ":"] Statement LocalVariableDeclarationStatement = { FINAL | '@' Annotation } Type VariableDeclarators ";"
 JCExpression bracketsSuffix(JCExpression t) 
    BracketsSuffixExpr = "." CLASS BracketsSuffixType =
 JCCatch catchClause() 
    CatchClause = CATCH "(" FormalParameter ")" Block
 List<JCExpression> catchTypes() 
  void checkAnnotations() 
  void checkDiamond() 
 protected JCExpression checkExprStat(JCExpression t) 
    Check that given tree is a legal expression statement.
  void checkForeach() 
  void checkGenerics() 
  void checkMulticatch() 
  void checkNoMods(long mods) 
    Diagnose a modifier flag from the set, if any.
  void checkStaticImports() 
  void checkTryWithResources() 
  void checkVarargs() 
 JCNewClass classCreatorRest(int newpos,
    JCExpression encl,
    List<JCExpression> typeArgs,
    JCExpression t) 
    ClassCreatorRest = Arguments [ClassBody]
 JCClassDecl classDeclaration(JCModifiers mods,
    String dc) 
    ClassDeclaration = CLASS Ident TypeParametersOpt [EXTENDS Type] [IMPLEMENTS TypeList] ClassBody
 List<JCTree> classOrInterfaceBody(Name className,
    boolean isInterface) 
    ClassBody = "{" {ClassBodyDeclaration} "}" InterfaceBody = "{" {InterfaceBodyDeclaration} "}"
 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 ";" )
 JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods,
    String dc) 
    ClassOrInterfaceOrEnumDeclaration = ModifiersOpt (ClassDeclaration | InterfaceDeclaration | EnumDeclaration)
 JCExpression creator(int newpos,
    List<JCExpression> typeArgs) 
    Creator = Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
 static int earlier(int pos1,
    int pos2) 
    Return the lesser of two positions, making allowance for either one being unset.
 List<JCTree> enumBody(Name enumName) 
    EnumBody = "{" { EnumeratorDeclarationList } [","] [ ";" {ClassBodyDeclaration} ] "}"
 JCClassDecl enumDeclaration(JCModifiers mods,
    String dc) 
    EnumDeclaration = ENUM Ident [IMPLEMENTS TypeList] EnumBody
 JCTree enumeratorDeclaration(Name enumName) 
    EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ]
  void error(int pos,
    String key,
    Object args) 
 protected StringBuffer foldStrings(JCTree tree) 
    If tree is a concatenation of string literals, replace it by a single literal representing the concatenated string.
 List<JCStatement> forInit() 
    ForInit = StatementExpression MoreStatementExpressions | { FINAL | '@' Annotation } Type VariableDeclarators
 List<JCExpressionStatement> forUpdate() 
    ForUpdate = StatementExpression MoreStatementExpressions
 JCVariableDecl formalParameter() 
    FormalParameter = { FINAL | '@' Annotation } Type VariableDeclaratorId LastFormalParameter = { FINAL | '@' Annotation } Type '...' Ident | FormalParameter
 List<JCVariableDecl> formalParameters() 
    FormalParameters = "(" [ FormalParameterList ] ")" FormalParameterList = [ FormalParameterListNovarargs , ] LastFormalParameter FormalParameterListNovarargs = [ FormalParameterListNovarargs , ] FormalParameter
 public int getEndPos(JCTree tree) 
    Get the end position for a tree node. The end position is defined to be the position of the last character of the last token of the node's source text. Returns Position.NOPOS if end positions are not generated or the position is otherwise not found.
 protected int getErrorEndPos() 
 public int getStartPos(JCTree tree) 
    Get the start position for a tree node. The start position is defined to be the position of the first character of the first token of the node's source text.
 Name ident() 
    Ident = IDENTIFIER
 JCExpression illegal() 
    Report an illegal start of expression/type error at current position.
 JCExpression illegal(int pos) 
    Report an illegal start of expression/type error at given position.
 JCTree importDeclaration() 
    ImportDeclaration = IMPORT [ STATIC ] Ident { "." Ident } [ "." "*" ] ";"
 JCExpression innerCreator(int newpos,
    List<JCExpression> typeArgs,
    JCExpression encl) 
    InnerCreator = Ident [TypeArguments] ClassCreatorRest
 JCClassDecl interfaceDeclaration(JCModifiers mods,
    String dc) 
    InterfaceDeclaration = INTERFACE Ident TypeParametersOpt [EXTENDS TypeList] InterfaceBody
 boolean isZero(String s) 
 JCExpression literal(Name prefix) 
    Literal = INTLITERAL | LONGLITERAL | FLOATLITERAL | DOUBLELITERAL | CHARLITERAL | STRINGLITERAL | TRUE | FALSE | NULL
 JCTree methodDeclaratorRest(int pos,
    JCModifiers mods,
    JCExpression type,
    Name name,
    List<JCTypeParameter> typarams,
    boolean isInterface,
    boolean isVoid,
    String 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
 JCModifiers modifiersOpt() 
    ModifiersOpt = { Modifier } Modifier = PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE | "@" | "@" Annotation
 JCModifiers modifiersOpt(JCModifiers partial) 
 T moreStatementExpressions(int pos,
    JCExpression first,
    T stats) 
    MoreStatementExpressions = { COMMA StatementExpression }
 JCModifiers optFinal(long flags) 
 static int optag(Token token) 
    Return operation tag of binary operator represented by token, -1 if token is not a binary operator.
 JCExpression parExpression() 
    ParExpression = "(" Expression ")"
 public JCCompilationUnit parseCompilationUnit() 
    CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
 public JCExpression parseExpression() 
    terms can be either expressions or types.
 public 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
 public JCExpression parseType() 
 static int prec(Token token) 
    Return precedence of operator represented by token, -1 if token is not a binary operator. @see TreeInfo.opPrec
 public JCExpression qualident() 
    Qualident = Ident { DOT Ident }
 List<JCExpression> qualidentList() 
    QualidentList = Qualident {"," Qualident}
 JCTree resource() 
    Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
 List<JCTree> resources() 
    Resources = Resource { ";" Resources }
 protected  void storeEnd(JCTree tree,
    int endpos) 
    Store ending position for a tree.
 String strval(Name prefix) 
 JCExpression superSuffix(List<JCExpression> typeArgs,
    JCExpression t) 
    SuperSuffix = Arguments | "." [TypeArguments] Ident [Arguments]
 List<JCCase> switchBlockStatementGroups() 
    SwitchBlockStatementGroups = { SwitchBlockStatementGroup } SwitchBlockStatementGroup = SwitchLabel BlockStatements SwitchLabel = CASE ConstantExpression ":" | DEFAULT ":"
 JCExpression term() 
    Expression = Expression1 [ExpressionRest] ExpressionRest = [AssignmentOperator Expression1] AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "&=" | "|=" | "^=" | "%=" | "<<=" | ">>=" | ">>>=" Type = Type1 TypeNoParams = TypeNoParams1 StatementExpression = Expression ConstantExpression = Expression
 JCExpression term(int newmode) 
 JCExpression term1() 
    Expression1 = Expression2 [Expression1Rest] Type1 = Type2 TypeNoParams1 = TypeNoParams2
 JCExpression term1Rest(JCExpression t) 
    Expression1Rest = ["?" Expression ":" Expression1]
 JCExpression term2() 
    Expression2 = Expression3 [Expression2Rest] Type2 = Type3 TypeNoParams2 = TypeNoParams3
 JCExpression term2Rest(JCExpression t,
    int minprec) 
 protected JCExpression term3() 
    Expression3 = PrefixOp Expression3 | "(" Expr | TypeNoParams ")" Expression3 | Primary {Selector} {PostfixOp} Primary = "(" Expression ")" | Literal | [TypeArguments] THIS [Arguments] | [TypeArguments] SUPER SuperSuffix | NEW [TypeArguments] Creator | Ident { "." Ident } [ "[" ( "]" 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]
 JCExpression termRest(JCExpression t) 
 protected T to(T t) 
    Store ending position for a tree. The ending position should be the ending position of the current token.
 protected T toP(T t) 
    Store ending position for a tree. The ending position should be greater of the ending position of the previous token and errorEndPos.
 JCExpression typeArgument() 
    TypeArgument = Type | "?" | "?" EXTENDS Type {"&" Type} | "?" SUPER Type
 List<JCExpression> typeArguments(boolean diamondAllowed) 
    TypeArguments = "<" TypeArgument {"," TypeArgument} ">"
 JCTypeApply typeArguments(JCExpression t,
    boolean diamondAllowed) 
 List<JCExpression> typeArgumentsOpt() 
 JCExpression typeArgumentsOpt(JCExpression t) 
    TypeArgumentsOpt = [ TypeArguments ]
 List<JCExpression> typeArgumentsOpt(int useMode) 
 JCTree typeDeclaration(JCModifiers mods) 
    TypeDeclaration = ClassOrInterfaceOrEnumDeclaration | ";"
 List<JCExpression> typeList() 
    TypeList = Type {"," Type}
 JCTypeParameter typeParameter() 
    TypeParameter = TypeVariable [TypeParameterBound] TypeParameterBound = EXTENDS Type {"&" Type} TypeVariable = Ident
 List<JCTypeParameter> typeParametersOpt() 
    TypeParametersOpt = ["<" TypeParameter {"," TypeParameter} ">"]
 static int typetag(Token token) 
    Return type tag of basic type represented by token, -1 if token is not a basic type identifier.
 static int unoptag(Token token) 
    Return operation tag of unary operator represented by token, -1 if token is not a binary operator.
 JCVariableDecl variableDeclarator(JCModifiers mods,
    JCExpression type,
    boolean reqInit,
    String dc) 
    VariableDeclarator = Ident VariableDeclaratorRest ConstantDeclarator = Ident ConstantDeclaratorRest
 JCVariableDecl variableDeclaratorId(JCModifiers mods,
    JCExpression type) 
    VariableDeclaratorId = Ident BracketsOpt
 JCVariableDecl variableDeclaratorRest(int pos,
    JCModifiers mods,
    JCExpression type,
    Name name,
    boolean reqInit,
    String dc) 
    VariableDeclaratorRest = BracketsOpt ["=" VariableInitializer] ConstantDeclaratorRest = BracketsOpt "=" VariableInitializer
 public T variableDeclarators(JCModifiers mods,
    JCExpression type,
    T vdefs) 
    VariableDeclarators = VariableDeclarator { "," VariableDeclarator }
 T variableDeclaratorsRest(int pos,
    JCModifiers mods,
    JCExpression type,
    Name name,
    boolean reqInit,
    String dc,
    T vdefs) 
    VariableDeclaratorsRest = VariableDeclaratorRest { "," VariableDeclarator } ConstantDeclaratorsRest = ConstantDeclaratorRest { "," ConstantDeclarator }
 public JCExpression variableInitializer() 
    VariableInitializer = ArrayInitializer | Expression
  void warning(int pos,
    String key,
    Object args)