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;


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;


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 = VariableModifiers Type VariableDeclaratorId = Expression


2191      */
2192     JCTree resource() {
2193         int pos = S.pos();
2194         return variableDeclaratorRest(pos,
2195                                       optFinal(Flags.FINAL),
2196                                       parseType(), ident(), true, null);








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