langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
changeset 25445 603f0c93d5c9
parent 25274 a06a738fc6be
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed Jul 09 10:49:32 2014 -0400
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Jul 10 13:57:27 2014 -0700
@@ -144,13 +144,6 @@
         this.log = fac.log;
         this.names = fac.names;
         this.source = fac.source;
-        this.allowGenerics = source.allowGenerics();
-        this.allowVarargs = source.allowVarargs();
-        this.allowAsserts = source.allowAsserts();
-        this.allowEnums = source.allowEnums();
-        this.allowForeach = source.allowForeach();
-        this.allowStaticImport = source.allowStaticImport();
-        this.allowAnnotations = source.allowAnnotations();
         this.allowTWR = source.allowTryWithResources();
         this.allowDiamond = source.allowDiamond();
         this.allowMulticatch = source.allowMulticatch();
@@ -179,10 +172,6 @@
         return keepDocComments ? new LazyDocCommentTable(fac) : null;
     }
 
-    /** Switch: Should generics be recognized?
-     */
-    boolean allowGenerics;
-
     /** Switch: Should diamond operator be recognized?
      */
     boolean allowDiamond;
@@ -191,30 +180,6 @@
      */
     boolean allowMulticatch;
 
-    /** Switch: Should varargs be recognized?
-     */
-    boolean allowVarargs;
-
-    /** Switch: should we recognize assert statements, or just give a warning?
-     */
-    boolean allowAsserts;
-
-    /** Switch: should we recognize enums, or just give a warning?
-     */
-    boolean allowEnums;
-
-    /** Switch: should we recognize foreach?
-     */
-    boolean allowForeach;
-
-    /** Switch: should we recognize foreach?
-     */
-    boolean allowStaticImport;
-
-    /** Switch: should we recognize annotations?
-     */
-    boolean allowAnnotations;
-
     /** Switch: should we recognize try-with-resources?
      */
     boolean allowTWR;
@@ -419,8 +384,8 @@
                         return;
                     break;
                 case ASSERT:
-                    if (stopAtStatement && allowAsserts)
-                        return ;
+                    if (stopAtStatement)
+                        return;
                     break;
             }
             nextToken();
@@ -604,27 +569,13 @@
             nextToken();
             return name;
         } else if (token.kind == ASSERT) {
-            if (allowAsserts) {
-                error(token.pos, "assert.as.identifier");
-                nextToken();
-                return names.error;
-            } else {
-                warning(token.pos, "assert.as.identifier");
-                Name name = token.name();
-                nextToken();
-                return name;
-            }
+            error(token.pos, "assert.as.identifier");
+            nextToken();
+            return names.error;
         } else if (token.kind == ENUM) {
-            if (allowEnums) {
-                error(token.pos, "enum.as.identifier");
-                nextToken();
-                return names.error;
-            } else {
-                warning(token.pos, "enum.as.identifier");
-                Name name = token.name();
-                nextToken();
-                return name;
-            }
+            error(token.pos, "enum.as.identifier");
+            nextToken();
+            return names.error;
         } else if (token.kind == THIS) {
             if (allowThisIdent) {
                 // Make sure we're using a supported source version.
@@ -1340,7 +1291,6 @@
                             }
                             accept(GT);
                             t = toP(F.at(pos1).TypeApply(t, args.toList()));
-                            checkGenerics();
                             while (token.kind == DOT) {
                                 nextToken();
                                 mode = TYPE;
@@ -1815,7 +1765,6 @@
             (mode & TYPE) != 0 &&
             (mode & NOPARAMS) == 0) {
             mode = TYPE;
-            checkGenerics();
             return typeArguments(t, false);
         } else {
             return t;
@@ -1827,7 +1776,6 @@
 
     List<JCExpression> typeArgumentsOpt(int useMode) {
         if (token.kind == LT) {
-            checkGenerics();
             if ((mode & useMode) == 0 ||
                 (mode & NOPARAMS) != 0) {
                 illegal();
@@ -2060,7 +2008,6 @@
         boolean diamondFound = false;
         int lastTypeargsPos = -1;
         if (token.kind == LT) {
-            checkGenerics();
             lastTypeargsPos = token.pos;
             t = typeArguments(t, true);
             diamondFound = (mode & DIAMOND) != 0;
@@ -2081,7 +2028,6 @@
 
             if (token.kind == LT) {
                 lastTypeargsPos = token.pos;
-                checkGenerics();
                 t = typeArguments(t, true);
                 diamondFound = (mode & DIAMOND) != 0;
             }
@@ -2153,7 +2099,6 @@
 
         if (token.kind == LT) {
             int oldmode = mode;
-            checkGenerics();
             t = typeArguments(t, true);
             mode = oldmode;
         }
@@ -2357,7 +2302,6 @@
         }
     }
 
-    @SuppressWarnings("fallthrough")
     List<JCStatement> blockStatement() {
         //todo: skip to anchor on error(?)
         int pos = token.pos;
@@ -2374,7 +2318,7 @@
             JCModifiers mods = modifiersOpt();
             if (token.kind == INTERFACE ||
                 token.kind == CLASS ||
-                allowEnums && token.kind == ENUM) {
+                token.kind == ENUM) {
                 return List.of(classOrInterfaceOrEnumDeclaration(mods, dc));
             } else {
                 JCExpression t = parseType();
@@ -2396,15 +2340,11 @@
             Comment dc = token.comment(CommentStyle.JAVADOC);
             return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
         case ENUM:
+            error(token.pos, "local.enum");
+            dc = token.comment(CommentStyle.JAVADOC);
+            return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
         case ASSERT:
-            if (allowEnums && token.kind == ENUM) {
-                error(token.pos, "local.enum");
-                dc = token.comment(CommentStyle.JAVADOC);
-                return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
-            } else if (allowAsserts && token.kind == ASSERT) {
-                return List.of(parseStatement());
-            }
-            /* fall through to default */
+            return List.of(parseStatement());
         default:
             Token prevToken = token;
             JCExpression t = term(EXPR | TYPE);
@@ -2452,7 +2392,6 @@
      *     | ExpressionStatement
      *     | Ident ":" Statement
      */
-    @SuppressWarnings("fallthrough")
     public JCStatement parseStatement() {
         int pos = token.pos;
         switch (token.kind) {
@@ -2477,7 +2416,6 @@
                 inits.head.hasTag(VARDEF) &&
                 ((JCVariableDecl) inits.head).init == null &&
                 token.kind == COLON) {
-                checkForeach();
                 JCVariableDecl var = (JCVariableDecl)inits.head;
                 accept(COLON);
                 JCExpression expr = parseExpression();
@@ -2593,19 +2531,16 @@
         case CATCH:
             return doRecover(token.pos, BasicErrorRecoveryAction.CATCH_CLAUSE, "catch.without.try");
         case ASSERT: {
-            if (allowAsserts && token.kind == ASSERT) {
+            nextToken();
+            JCExpression assertion = parseExpression();
+            JCExpression message = null;
+            if (token.kind == COLON) {
                 nextToken();
-                JCExpression assertion = parseExpression();
-                JCExpression message = null;
-                if (token.kind == COLON) {
-                    nextToken();
-                    message = parseExpression();
-                }
-                accept(SEMI);
-                JCAssert t = toP(F.at(pos).Assert(assertion, message));
-                return t;
+                message = parseExpression();
             }
-            /* else fall through to default case */
+            accept(SEMI);
+            JCAssert t = toP(F.at(pos).Assert(assertion, message));
+            return t;
         }
         case ENUM:
         default:
@@ -2831,7 +2766,6 @@
             lastPos = token.pos;
             nextToken();
             if (flag == Flags.ANNOTATION) {
-                checkAnnotations();
                 if (token.kind != INTERFACE) {
                     JCAnnotation ann = annotation(lastPos, Tag.ANNOTATION);
                     // if first modifier is an annotation, set pos to annotation's.
@@ -2867,7 +2801,6 @@
      */
     JCAnnotation annotation(int pos, Tag kind) {
         // accept(AT); // AT consumed by caller
-        checkAnnotations();
         if (kind == Tag.TYPE_ANNOTATION) {
             checkTypeAnnotations();
         }
@@ -3166,7 +3099,6 @@
         nextToken();
         boolean importStatic = false;
         if (token.kind == STATIC) {
-            checkStaticImports();
             importStatic = true;
             nextToken();
         }
@@ -3209,27 +3141,9 @@
             return classDeclaration(mods, dc);
         } else if (token.kind == INTERFACE) {
             return interfaceDeclaration(mods, dc);
-        } else if (allowEnums) {
-            if (token.kind == ENUM) {
-                return enumDeclaration(mods, dc);
-            } else {
-                int pos = token.pos;
-                List<JCTree> errs;
-                if (LAX_IDENTIFIER.accepts(token.kind)) {
-                    errs = List.<JCTree>of(mods, toP(F.at(pos).Ident(ident())));
-                    setErrorEndPos(token.pos);
-                } else {
-                    errs = List.<JCTree>of(mods);
-                }
-                return toP(F.Exec(syntaxError(pos, errs, "expected3",
-                                              CLASS, INTERFACE, ENUM)));
-            }
+        } else if (token.kind == ENUM) {
+            return enumDeclaration(mods, dc);
         } else {
-            if (token.kind == ENUM) {
-                error(token.pos, "enums.not.supported.in.source", source.name);
-                allowEnums = true;
-                return enumDeclaration(mods, dc);
-            }
             int pos = token.pos;
             List<JCTree> errs;
             if (LAX_IDENTIFIER.accepts(token.kind)) {
@@ -3238,8 +3152,8 @@
             } else {
                 errs = List.<JCTree>of(mods);
             }
-            return toP(F.Exec(syntaxError(pos, errs, "expected2",
-                                          CLASS, INTERFACE)));
+            return toP(F.Exec(syntaxError(pos, errs, "expected3",
+                                          CLASS, INTERFACE, ENUM)));
         }
     }
 
@@ -3315,7 +3229,7 @@
         mods.flags |= Flags.ENUM;
         JCClassDecl result = toP(F.at(pos).
             ClassDef(mods, name, List.<JCTypeParameter>nil(),
-                null, implementing, defs));
+                     null, implementing, defs));
         attach(result, dc);
         return result;
     }
@@ -3465,7 +3379,7 @@
             JCModifiers mods = modifiersOpt();
             if (token.kind == CLASS ||
                 token.kind == INTERFACE ||
-                allowEnums && token.kind == ENUM) {
+                token.kind == ENUM) {
                 return List.<JCTree>of(classOrInterfaceOrEnumDeclaration(mods, dc));
             } else if (token.kind == LBRACE &&
                        (mods.flags & Flags.StandardFlags & ~Flags.STATIC) == 0 &&
@@ -3634,7 +3548,6 @@
      */
     List<JCTypeParameter> typeParametersOpt() {
         if (token.kind == LT) {
-            checkGenerics();
             ListBuffer<JCTypeParameter> typarams = new ListBuffer<>();
             nextToken();
             typarams.append(typeParameter());
@@ -3822,7 +3735,6 @@
         if (token.kind == ELLIPSIS) {
             List<JCAnnotation> varargsAnnos = typeAnnotationsPushedBack;
             typeAnnotationsPushedBack = List.nil();
-            checkVarargs();
             mods.flags |= Flags.VARARGS;
             // insert var arg type annotations
             type = insertAnnotationsToMostInner(type, varargsAnnos, true);
@@ -4009,36 +3921,6 @@
         }
     }
 
-    void checkGenerics() {
-        if (!allowGenerics) {
-            error(token.pos, "generics.not.supported.in.source", source.name);
-            allowGenerics = true;
-        }
-    }
-    void checkVarargs() {
-        if (!allowVarargs) {
-            error(token.pos, "varargs.not.supported.in.source", source.name);
-            allowVarargs = true;
-        }
-    }
-    void checkForeach() {
-        if (!allowForeach) {
-            error(token.pos, "foreach.not.supported.in.source", source.name);
-            allowForeach = true;
-        }
-    }
-    void checkStaticImports() {
-        if (!allowStaticImport) {
-            error(token.pos, "static.import.not.supported.in.source", source.name);
-            allowStaticImport = true;
-        }
-    }
-    void checkAnnotations() {
-        if (!allowAnnotations) {
-            error(token.pos, "annotations.not.supported.in.source", source.name);
-            allowAnnotations = true;
-        }
-    }
     void checkDiamond() {
         if (!allowDiamond) {
             error(token.pos, "diamond.not.supported.in.source", source.name);