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;


2164     }
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             type = bracketsOpt(type);
2173         return toP(F.at(pos).VarDef(mods, name, type, null));
2174     }
2175 
2176     /** Resources = Resource { ";" Resources }
2177      */
2178     List<JCTree> resources() {
2179         ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
2180         defs.append(resource());
2181         while (S.token() == SEMI) {
2182             // All but last of multiple declarators subsume a semicolon
2183             storeEnd(defs.elems.last(), S.endPos());

2184             S.nextToken();





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


2164     }
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             type = bracketsOpt(type);
2173         return toP(F.at(pos).VarDef(mods, name, type, null));
2174     }
2175 
2176     /** Resources = Resource { ";" Resources }
2177      */
2178     List<JCTree> resources() {
2179         ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
2180         defs.append(resource());
2181         while (S.token() == SEMI) {
2182             // All but last of multiple declarators subsume a semicolon
2183             storeEnd(defs.elems.last(), S.endPos());
2184             int semiColonPos = S.pos();
2185             S.nextToken();
2186             if (S.token() == RPAREN) { // Illegal trailing semicolon
2187                                      // after last resource
2188                 error(semiColonPos, "try.resource.trailing.semi");
2189                 break;
2190             }
2191             defs.append(resource());
2192         }
2193         return defs.toList();
2194     }
2195 
2196     /** Resource = VariableModifiers Type VariableDeclaratorId = Expression


2197      */
2198     JCTree resource() {
2199         return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL),
2200                                       parseType(), ident(), true, null);










2201     }
2202 
2203     /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
2204      */
2205     public JCTree.JCCompilationUnit parseCompilationUnit() {
2206         int pos = S.pos();
2207         JCExpression pid = null;
2208         String dc = S.docComment();
2209         JCModifiers mods = null;
2210         List<JCAnnotation> packageAnnotations = List.nil();
2211         if (S.token() == MONKEYS_AT)
2212             mods = modifiersOpt();
2213 
2214         if (S.token() == PACKAGE) {
2215             if (mods != null) {
2216                 checkNoMods(mods.flags);
2217                 packageAnnotations = mods.annotations;
2218                 mods = null;
2219             }
2220             S.nextToken();