src/share/classes/com/sun/tools/javac/parser/JavacParser.java

Print this page




1622             if (S.pos() == lastErrPos)
1623                 return stats.toList();
1624             if (S.pos() <= errorEndPos) {
1625                 skip(false, true, true, true);
1626                 lastErrPos = S.pos();
1627             }
1628 
1629             // ensure no dangling /** @deprecated */ active
1630             S.resetDeprecatedFlag();
1631         }
1632     }
1633 
1634     /** Statement =
1635      *       Block
1636      *     | IF ParExpression Statement [ELSE Statement]
1637      *     | FOR "(" ForInitOpt ";" [Expression] ";" ForUpdateOpt ")" Statement
1638      *     | FOR "(" FormalParameter : Expression ")" Statement
1639      *     | WHILE ParExpression Statement
1640      *     | DO Statement WHILE ParExpression ";"
1641      *     | TRY Block ( Catches | [Catches] FinallyPart )
1642      *     | TRY "(" ResourceSpecification ")" Block [Catches] [FinallyPart]
1643      *     | SWITCH ParExpression "{" SwitchBlockStatementGroups "}"
1644      *     | SYNCHRONIZED ParExpression Block
1645      *     | RETURN [Expression] ";"
1646      *     | THROW Expression ";"
1647      *     | BREAK [Ident] ";"
1648      *     | CONTINUE [Ident] ";"
1649      *     | ASSERT Expression [ ":" Expression ] ";"
1650      *     | ";"
1651      *     | ExpressionStatement
1652      *     | Ident ":" Statement
1653      */
1654     @SuppressWarnings("fallthrough")
1655     public JCStatement parseStatement() {
1656         int pos = S.pos();
1657         switch (S.token()) {
1658         case LBRACE:
1659             return block();
1660         case IF: {
1661             S.nextToken();
1662             JCExpression cond = parExpression();


2165 
2166     /** VariableDeclaratorId = Ident BracketsOpt
2167      */
2168     JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type) {
2169         int pos = S.pos();
2170         Name name = ident();
2171         if ((mods.flags & Flags.VARARGS) != 0 &&
2172                 S.token() == LBRACKET) {
2173             log.error(S.pos(), "varargs.and.old.array.syntax");
2174         }
2175         type = bracketsOpt(type);
2176         return toP(F.at(pos).VarDef(mods, name, type, null));
2177     }
2178 
2179     /** Resources = Resource { ";" Resources }
2180      */
2181     List<JCTree> resources() {
2182         ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
2183         defs.append(resource());
2184         while (S.token() == SEMI) {
2185             // All but last of multiple declarators subsume a semicolon
2186             storeEnd(defs.elems.last(), S.endPos());
2187             int semiColonPos = S.pos();
2188             S.nextToken();
2189             if (S.token() == RPAREN) { // Illegal trailing semicolon
2190                                        // after last resource
2191                 error(semiColonPos, "try.resource.trailing.semi");
2192                 break;
2193             }
2194             defs.append(resource());
2195         }
2196         return defs.toList();
2197     }
2198 
2199     /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
2200      */
2201     JCTree resource() {
2202         return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL),
2203                                       parseType(), ident(), true, null);
2204     }
2205 
2206     /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
2207      */
2208     public JCTree.JCCompilationUnit parseCompilationUnit() {
2209         int pos = S.pos();
2210         JCExpression pid = null;
2211         String dc = S.docComment();




1622             if (S.pos() == lastErrPos)
1623                 return stats.toList();
1624             if (S.pos() <= errorEndPos) {
1625                 skip(false, true, true, true);
1626                 lastErrPos = S.pos();
1627             }
1628 
1629             // ensure no dangling /** @deprecated */ active
1630             S.resetDeprecatedFlag();
1631         }
1632     }
1633 
1634     /** Statement =
1635      *       Block
1636      *     | IF ParExpression Statement [ELSE Statement]
1637      *     | FOR "(" ForInitOpt ";" [Expression] ";" ForUpdateOpt ")" Statement
1638      *     | FOR "(" FormalParameter : Expression ")" Statement
1639      *     | WHILE ParExpression Statement
1640      *     | DO Statement WHILE ParExpression ";"
1641      *     | TRY Block ( Catches | [Catches] FinallyPart )
1642      *     | TRY "(" ResourceSpecification ";"opt ")" Block [Catches] [FinallyPart]
1643      *     | SWITCH ParExpression "{" SwitchBlockStatementGroups "}"
1644      *     | SYNCHRONIZED ParExpression Block
1645      *     | RETURN [Expression] ";"
1646      *     | THROW Expression ";"
1647      *     | BREAK [Ident] ";"
1648      *     | CONTINUE [Ident] ";"
1649      *     | ASSERT Expression [ ":" Expression ] ";"
1650      *     | ";"
1651      *     | ExpressionStatement
1652      *     | Ident ":" Statement
1653      */
1654     @SuppressWarnings("fallthrough")
1655     public JCStatement parseStatement() {
1656         int pos = S.pos();
1657         switch (S.token()) {
1658         case LBRACE:
1659             return block();
1660         case IF: {
1661             S.nextToken();
1662             JCExpression cond = parExpression();


2165 
2166     /** VariableDeclaratorId = Ident BracketsOpt
2167      */
2168     JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type) {
2169         int pos = S.pos();
2170         Name name = ident();
2171         if ((mods.flags & Flags.VARARGS) != 0 &&
2172                 S.token() == LBRACKET) {
2173             log.error(S.pos(), "varargs.and.old.array.syntax");
2174         }
2175         type = bracketsOpt(type);
2176         return toP(F.at(pos).VarDef(mods, name, type, null));
2177     }
2178 
2179     /** Resources = Resource { ";" Resources }
2180      */
2181     List<JCTree> resources() {
2182         ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
2183         defs.append(resource());
2184         while (S.token() == SEMI) {
2185             // All but last of multiple declarators must subsume a semicolon
2186             storeEnd(defs.elems.last(), S.endPos());
2187             int semiColonPos = S.pos();
2188             S.nextToken();
2189             if (S.token() == RPAREN) { // Optional trailing semicolon
2190                                        // after last resource

2191                 break;
2192             }
2193             defs.append(resource());
2194         }
2195         return defs.toList();
2196     }
2197 
2198     /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
2199      */
2200     JCTree resource() {
2201         return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL),
2202                                       parseType(), ident(), true, null);
2203     }
2204 
2205     /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
2206      */
2207     public JCTree.JCCompilationUnit parseCompilationUnit() {
2208         int pos = S.pos();
2209         JCExpression pid = null;
2210         String dc = S.docComment();