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

Print this page




 125     /** Switch: should we recognize assert statements, or just give a warning?
 126      */
 127     boolean allowAsserts;
 128 
 129     /** Switch: should we recognize enums, or just give a warning?
 130      */
 131     boolean allowEnums;
 132 
 133     /** Switch: should we recognize foreach?
 134      */
 135     boolean allowForeach;
 136 
 137     /** Switch: should we recognize foreach?
 138      */
 139     boolean allowStaticImport;
 140 
 141     /** Switch: should we recognize annotations?
 142      */
 143     boolean allowAnnotations;
 144 
 145     /** Switch: should we recognize automatic resource management?
 146      */
 147     boolean allowTWR;
 148 
 149     /** Switch: should we keep docComments?
 150      */
 151     boolean keepDocComments;
 152 
 153     /** Switch: should we keep line table?
 154      */
 155     boolean keepLineMap;
 156 
 157     /** When terms are parsed, the mode determines which is expected:
 158      *     mode = EXPR        : an expression
 159      *     mode = TYPE        : a type
 160      *     mode = NOPARAMS    : no parameters allowed for type
 161      *     mode = TYPEARG     : type argument
 162      */
 163     static final int EXPR = 0x1;
 164     static final int TYPE = 0x2;
 165     static final int NOPARAMS = 0x4;


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             S.nextToken();





2188             defs.append(resource());
2189         }
2190         return defs.toList();
2191     }
2192 
2193     /** Resource =
2194      *    VariableModifiers Type VariableDeclaratorId = Expression
2195      *  | Expression
2196      */
2197     JCTree resource() {
2198         int pos = S.pos();
2199         if (S.token() == FINAL || S.token() == MONKEYS_AT) {
2200             return variableDeclaratorRest(pos, optFinal(0), parseType(),
2201                                           ident(), true, null);
2202         } else {
2203             JCExpression t = term(EXPR | TYPE);
2204             if ((lastmode & TYPE) != 0 && S.token() == IDENTIFIER)
2205                 return variableDeclaratorRest(pos, toP(F.at(pos).Modifiers(Flags.FINAL)), t,
2206                                               ident(), true, null);
2207             else
2208                 return t;
2209         }
2210     }
2211 
2212     /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
2213      */
2214     public JCTree.JCCompilationUnit parseCompilationUnit() {
2215         int pos = S.pos();
2216         JCExpression pid = null;
2217         String dc = S.docComment();
2218         JCModifiers mods = null;
2219         List<JCAnnotation> packageAnnotations = List.nil();
2220         if (S.token() == MONKEYS_AT)
2221             mods = modifiersOpt();
2222 
2223         if (S.token() == PACKAGE) {
2224             if (mods != null) {
2225                 checkNoMods(mods.flags);
2226                 packageAnnotations = mods.annotations;
2227                 mods = null;
2228             }
2229             S.nextToken();




 125     /** Switch: should we recognize assert statements, or just give a warning?
 126      */
 127     boolean allowAsserts;
 128 
 129     /** Switch: should we recognize enums, or just give a warning?
 130      */
 131     boolean allowEnums;
 132 
 133     /** Switch: should we recognize foreach?
 134      */
 135     boolean allowForeach;
 136 
 137     /** Switch: should we recognize foreach?
 138      */
 139     boolean allowStaticImport;
 140 
 141     /** Switch: should we recognize annotations?
 142      */
 143     boolean allowAnnotations;
 144 
 145     /** Switch: should we recognize try-with-resources?
 146      */
 147     boolean allowTWR;
 148 
 149     /** Switch: should we keep docComments?
 150      */
 151     boolean keepDocComments;
 152 
 153     /** Switch: should we keep line table?
 154      */
 155     boolean keepLineMap;
 156 
 157     /** When terms are parsed, the mode determines which is expected:
 158      *     mode = EXPR        : an expression
 159      *     mode = TYPE        : a type
 160      *     mode = NOPARAMS    : no parameters allowed for type
 161      *     mode = TYPEARG     : type argument
 162      */
 163     static final int EXPR = 0x1;
 164     static final int TYPE = 0x2;
 165     static final int NOPARAMS = 0x4;


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();
2212         JCModifiers mods = null;
2213         List<JCAnnotation> packageAnnotations = List.nil();
2214         if (S.token() == MONKEYS_AT)
2215             mods = modifiersOpt();
2216 
2217         if (S.token() == PACKAGE) {
2218             if (mods != null) {
2219                 checkNoMods(mods.flags);
2220                 packageAnnotations = mods.annotations;
2221                 mods = null;
2222             }
2223             S.nextToken();