src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
changeset 48054 702043a4cdeb
parent 47936 3b1ef48862cf
child 48551 9cf44c40aa35
equal deleted inserted replaced
48053:6dcbdc9f99fc 48054:702043a4cdeb
    24  */
    24  */
    25 
    25 
    26 package com.sun.tools.javac.parser;
    26 package com.sun.tools.javac.parser;
    27 
    27 
    28 import java.util.*;
    28 import java.util.*;
       
    29 import java.util.function.Function;
       
    30 import java.util.function.Predicate;
    29 import java.util.stream.Collectors;
    31 import java.util.stream.Collectors;
    30 
    32 
    31 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
    33 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
    32 import com.sun.source.tree.ModuleTree.ModuleKind;
    34 import com.sun.source.tree.ModuleTree.ModuleKind;
    33 
    35 
    34 import com.sun.tools.javac.code.*;
    36 import com.sun.tools.javac.code.*;
       
    37 import com.sun.tools.javac.code.Source.Feature;
    35 import com.sun.tools.javac.parser.Tokens.*;
    38 import com.sun.tools.javac.parser.Tokens.*;
    36 import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
    39 import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
    37 import com.sun.tools.javac.resources.CompilerProperties;
    40 import com.sun.tools.javac.resources.CompilerProperties;
    38 import com.sun.tools.javac.resources.CompilerProperties.Errors;
    41 import com.sun.tools.javac.resources.CompilerProperties.Errors;
    39 import com.sun.tools.javac.tree.*;
    42 import com.sun.tools.javac.tree.*;
    40 import com.sun.tools.javac.tree.JCTree.*;
    43 import com.sun.tools.javac.tree.JCTree.*;
    41 import com.sun.tools.javac.util.*;
    44 import com.sun.tools.javac.util.*;
    42 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
    45 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
    43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    46 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
       
    47 import com.sun.tools.javac.util.JCDiagnostic.Error;
    44 import com.sun.tools.javac.util.List;
    48 import com.sun.tools.javac.util.List;
    45 
    49 
    46 import static com.sun.tools.javac.parser.Tokens.TokenKind.*;
    50 import static com.sun.tools.javac.parser.Tokens.TokenKind.*;
    47 import static com.sun.tools.javac.parser.Tokens.TokenKind.ASSERT;
    51 import static com.sun.tools.javac.parser.Tokens.TokenKind.ASSERT;
    48 import static com.sun.tools.javac.parser.Tokens.TokenKind.CASE;
    52 import static com.sun.tools.javac.parser.Tokens.TokenKind.CASE;
   161         nextToken(); // prime the pump
   165         nextToken(); // prime the pump
   162         this.F = fac.F;
   166         this.F = fac.F;
   163         this.log = fac.log;
   167         this.log = fac.log;
   164         this.names = fac.names;
   168         this.names = fac.names;
   165         this.source = fac.source;
   169         this.source = fac.source;
   166         this.allowTWR = source.allowTryWithResources();
       
   167         this.allowEffectivelyFinalVariablesInTWR =
       
   168                 source.allowEffectivelyFinalVariablesInTryWithResources();
       
   169         this.allowDiamond = source.allowDiamond();
       
   170         this.allowMulticatch = source.allowMulticatch();
       
   171         this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
   170         this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
   172         this.allowLambda = source.allowLambda();
       
   173         this.allowMethodReferences = source.allowMethodReferences();
       
   174         this.allowDefaultMethods = source.allowDefaultMethods();
       
   175         this.allowStaticInterfaceMethods = source.allowStaticInterfaceMethods();
       
   176         this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
       
   177         this.allowTypeAnnotations = source.allowTypeAnnotations();
       
   178         this.allowModules = source.allowModules();
       
   179         this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams();
       
   180         this.allowUnderscoreIdentifier = source.allowUnderscoreIdentifier();
       
   181         this.allowPrivateInterfaceMethods = source.allowPrivateInterfaceMethods();
       
   182         this.allowLocalVariableTypeInference = source.allowLocalVariableTypeInference();
       
   183         this.keepDocComments = keepDocComments;
   171         this.keepDocComments = keepDocComments;
   184         this.parseModuleInfo = parseModuleInfo;
   172         this.parseModuleInfo = parseModuleInfo;
   185         docComments = newDocCommentTable(keepDocComments, fac);
   173         docComments = newDocCommentTable(keepDocComments, fac);
   186         this.keepLineMap = keepLineMap;
   174         this.keepLineMap = keepLineMap;
   187         this.errorTree = F.Erroneous();
   175         this.errorTree = F.Erroneous();
   196 
   184 
   197     protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) {
   185     protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) {
   198         return keepDocComments ? new LazyDocCommentTable(fac) : null;
   186         return keepDocComments ? new LazyDocCommentTable(fac) : null;
   199     }
   187     }
   200 
   188 
   201     /** Switch: Should diamond operator be recognized?
       
   202      */
       
   203     boolean allowDiamond;
       
   204 
       
   205     /** Switch: Should multicatch clause be accepted?
       
   206      */
       
   207     boolean allowMulticatch;
       
   208 
       
   209     /** Switch: should we recognize try-with-resources?
       
   210      */
       
   211     boolean allowTWR;
       
   212 
       
   213     /** Switch: should we allow (effectively) final variables as resources in try-with-resources?
       
   214      */
       
   215     boolean allowEffectivelyFinalVariablesInTWR;
       
   216 
       
   217     /** Switch: should we fold strings?
   189     /** Switch: should we fold strings?
   218      */
   190      */
   219     boolean allowStringFolding;
   191     boolean allowStringFolding;
   220 
   192 
   221     /** Switch: should we recognize lambda expressions?
       
   222      */
       
   223     boolean allowLambda;
       
   224 
       
   225     /** Switch: should we allow method/constructor references?
       
   226      */
       
   227     boolean allowMethodReferences;
       
   228 
       
   229     /** Switch: should we recognize modules?
       
   230      */
       
   231     boolean allowModules;
       
   232 
       
   233     /** Switch: should we allow default methods in interfaces?
       
   234      */
       
   235     boolean allowDefaultMethods;
       
   236 
       
   237     /** Switch: should we allow static methods in interfaces?
       
   238      */
       
   239     boolean allowStaticInterfaceMethods;
       
   240 
       
   241     /** Switch: should we allow private (instance) methods in interfaces?
       
   242      */
       
   243     boolean allowPrivateInterfaceMethods;
       
   244 
       
   245     /** Switch: should we allow intersection types in cast?
       
   246      */
       
   247     boolean allowIntersectionTypesInCast;
       
   248 
       
   249     /** Switch: should we keep docComments?
   193     /** Switch: should we keep docComments?
   250      */
   194      */
   251     boolean keepDocComments;
   195     boolean keepDocComments;
   252 
   196 
   253     /** Switch: should we keep line table?
   197     /** Switch: should we keep line table?
   254      */
   198      */
   255     boolean keepLineMap;
   199     boolean keepLineMap;
   256 
       
   257     /** Switch: should we recognize type annotations?
       
   258      */
       
   259     boolean allowTypeAnnotations;
       
   260 
       
   261     /** Switch: should we allow annotations after the method type parameters?
       
   262      */
       
   263     boolean allowAnnotationsAfterTypeParams;
       
   264 
       
   265     /** Switch: should we allow '_' as an identifier?
       
   266      */
       
   267     boolean allowUnderscoreIdentifier;
       
   268 
   200 
   269     /** Switch: is "this" allowed as an identifier?
   201     /** Switch: is "this" allowed as an identifier?
   270      * This is needed to parse receiver types.
   202      * This is needed to parse receiver types.
   271      */
   203      */
   272     boolean allowThisIdent;
   204     boolean allowThisIdent;
   273 
       
   274     /** Switch: is local variable inference allowed?
       
   275      */
       
   276     boolean allowLocalVariableTypeInference;
       
   277 
   205 
   278     /** The type of the method receiver, as specified by a first "this" parameter.
   206     /** The type of the method receiver, as specified by a first "this" parameter.
   279      */
   207      */
   280     JCVariableDecl receiverParam;
   208     JCVariableDecl receiverParam;
   281 
   209 
   626             nextToken();
   554             nextToken();
   627             return names.error;
   555             return names.error;
   628         } else if (token.kind == THIS) {
   556         } else if (token.kind == THIS) {
   629             if (allowThisIdent) {
   557             if (allowThisIdent) {
   630                 // Make sure we're using a supported source version.
   558                 // Make sure we're using a supported source version.
   631                 checkTypeAnnotations();
   559                 checkSourceLevel(Feature.TYPE_ANNOTATIONS);
   632                 Name name = token.name();
   560                 Name name = token.name();
   633                 nextToken();
   561                 nextToken();
   634                 return name;
   562                 return name;
   635             } else {
   563             } else {
   636                 error(token.pos, "this.as.identifier");
   564                 error(token.pos, "this.as.identifier");
   637                 nextToken();
   565                 nextToken();
   638                 return names.error;
   566                 return names.error;
   639             }
   567             }
   640         } else if (token.kind == UNDERSCORE) {
   568         } else if (token.kind == UNDERSCORE) {
   641             if (allowUnderscoreIdentifier) {
   569             if (Feature.UNDERSCORE_IDENTIFIER.allowedInSource(source)) {
   642                 warning(token.pos, "underscore.as.identifier");
   570                 warning(token.pos, "underscore.as.identifier");
   643             } else {
   571             } else {
   644                 error(token.pos, "underscore.as.identifier");
   572                 error(token.pos, "underscore.as.identifier");
   645             }
   573             }
   646             Name name = token.name();
   574             Name name = token.name();
  1168                        accept(LPAREN);
  1096                        accept(LPAREN);
  1169                        mode = TYPE;
  1097                        mode = TYPE;
  1170                        int pos1 = pos;
  1098                        int pos1 = pos;
  1171                        List<JCExpression> targets = List.of(t = parseType());
  1099                        List<JCExpression> targets = List.of(t = parseType());
  1172                        while (token.kind == AMP) {
  1100                        while (token.kind == AMP) {
  1173                            checkIntersectionTypesInCast();
  1101                            checkSourceLevel(Feature.INTERSECTION_TYPES_IN_CAST);
  1174                            accept(AMP);
  1102                            accept(AMP);
  1175                            targets = targets.prepend(parseType());
  1103                            targets = targets.prepend(parseType());
  1176                        }
  1104                        }
  1177                        if (targets.length() > 1) {
  1105                        if (targets.length() > 1) {
  1178                            t = toP(F.at(pos1).TypeIntersection(targets.reverse()));
  1106                            t = toP(F.at(pos1).TypeIntersection(targets.reverse()));
  1769 
  1697 
  1770         return lambdaExpressionOrStatementRest(params, pos);
  1698         return lambdaExpressionOrStatementRest(params, pos);
  1771     }
  1699     }
  1772 
  1700 
  1773     JCExpression lambdaExpressionOrStatementRest(List<JCVariableDecl> args, int pos) {
  1701     JCExpression lambdaExpressionOrStatementRest(List<JCVariableDecl> args, int pos) {
  1774         checkLambda();
  1702         checkSourceLevel(Feature.LAMBDA);
  1775         accept(ARROW);
  1703         accept(ARROW);
  1776 
  1704 
  1777         return token.kind == LBRACE ?
  1705         return token.kind == LBRACE ?
  1778             lambdaStatement(args, pos, token.pos) :
  1706             lambdaStatement(args, pos, token.pos) :
  1779             lambdaExpression(args, pos);
  1707             lambdaExpression(args, pos);
  1888      */
  1816      */
  1889     List<JCExpression> typeArguments(boolean diamondAllowed) {
  1817     List<JCExpression> typeArguments(boolean diamondAllowed) {
  1890         if (token.kind == LT) {
  1818         if (token.kind == LT) {
  1891             nextToken();
  1819             nextToken();
  1892             if (token.kind == GT && diamondAllowed) {
  1820             if (token.kind == GT && diamondAllowed) {
  1893                 checkDiamond();
  1821                 checkSourceLevel(Feature.DIAMOND);
  1894                 mode |= DIAMOND;
  1822                 mode |= DIAMOND;
  1895                 nextToken();
  1823                 nextToken();
  1896                 return List.nil();
  1824                 return List.nil();
  1897             } else {
  1825             } else {
  1898                 ListBuffer<JCExpression> args = new ListBuffer<>();
  1826                 ListBuffer<JCExpression> args = new ListBuffer<>();
  2063         accept(COLCOL);
  1991         accept(COLCOL);
  2064         return memberReferenceSuffix(pos1, t);
  1992         return memberReferenceSuffix(pos1, t);
  2065     }
  1993     }
  2066 
  1994 
  2067     JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
  1995     JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
  2068         checkMethodReferences();
  1996         checkSourceLevel(Feature.METHOD_REFERENCES);
  2069         mode = EXPR;
  1997         mode = EXPR;
  2070         List<JCExpression> typeArgs = null;
  1998         List<JCExpression> typeArgs = null;
  2071         if (token.kind == LT) {
  1999         if (token.kind == LT) {
  2072             typeArgs = typeArguments(false);
  2000             typeArgs = typeArguments(false);
  2073         }
  2001         }
  2566         }
  2494         }
  2567         case TRY: {
  2495         case TRY: {
  2568             nextToken();
  2496             nextToken();
  2569             List<JCTree> resources = List.nil();
  2497             List<JCTree> resources = List.nil();
  2570             if (token.kind == LPAREN) {
  2498             if (token.kind == LPAREN) {
  2571                 checkTryWithResources();
  2499                 checkSourceLevel(Feature.TRY_WITH_RESOURCES);
  2572                 nextToken();
  2500                 nextToken();
  2573                 resources = resources();
  2501                 resources = resources();
  2574                 accept(RPAREN);
  2502                 accept(RPAREN);
  2575             }
  2503             }
  2576             JCBlock body = block();
  2504             JCBlock body = block();
  2582                     nextToken();
  2510                     nextToken();
  2583                     finalizer = block();
  2511                     finalizer = block();
  2584                 }
  2512                 }
  2585             } else {
  2513             } else {
  2586                 if (resources.isEmpty()) {
  2514                 if (resources.isEmpty()) {
  2587                     if (allowTWR) {
  2515                     if (Feature.TRY_WITH_RESOURCES.allowedInSource(source)) {
  2588                         error(pos, "try.without.catch.finally.or.resource.decls");
  2516                         error(pos, "try.without.catch.finally.or.resource.decls");
  2589                     } else {
  2517                     } else {
  2590                         error(pos, "try.without.catch.or.finally");
  2518                         error(pos, "try.without.catch.or.finally");
  2591                     }
  2519                     }
  2592                 }
  2520                 }
  2699 
  2627 
  2700     List<JCExpression> catchTypes() {
  2628     List<JCExpression> catchTypes() {
  2701         ListBuffer<JCExpression> catchTypes = new ListBuffer<>();
  2629         ListBuffer<JCExpression> catchTypes = new ListBuffer<>();
  2702         catchTypes.add(parseType());
  2630         catchTypes.add(parseType());
  2703         while (token.kind == BAR) {
  2631         while (token.kind == BAR) {
  2704             checkMulticatch();
  2632             checkSourceLevel(Feature.MULTICATCH);
  2705             nextToken();
  2633             nextToken();
  2706             // Instead of qualident this is now parseType.
  2634             // Instead of qualident this is now parseType.
  2707             // But would that allow too much, e.g. arrays or generics?
  2635             // But would that allow too much, e.g. arrays or generics?
  2708             catchTypes.add(parseType());
  2636             catchTypes.add(parseType());
  2709         }
  2637         }
  2868             case NATIVE      : flag = Flags.NATIVE; break;
  2796             case NATIVE      : flag = Flags.NATIVE; break;
  2869             case VOLATILE    : flag = Flags.VOLATILE; break;
  2797             case VOLATILE    : flag = Flags.VOLATILE; break;
  2870             case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break;
  2798             case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break;
  2871             case STRICTFP    : flag = Flags.STRICTFP; break;
  2799             case STRICTFP    : flag = Flags.STRICTFP; break;
  2872             case MONKEYS_AT  : flag = Flags.ANNOTATION; break;
  2800             case MONKEYS_AT  : flag = Flags.ANNOTATION; break;
  2873             case DEFAULT     : checkDefaultMethods(); flag = Flags.DEFAULT; break;
  2801             case DEFAULT     : checkSourceLevel(Feature.DEFAULT_METHODS); flag = Flags.DEFAULT; break;
  2874             case ERROR       : flag = 0; nextToken(); break;
  2802             case ERROR       : flag = 0; nextToken(); break;
  2875             default: break loop;
  2803             default: break loop;
  2876             }
  2804             }
  2877             if ((flags & flag) != 0) error(token.pos, "repeated.modifier");
  2805             if ((flags & flag) != 0) error(token.pos, "repeated.modifier");
  2878             lastPos = token.pos;
  2806             lastPos = token.pos;
  2912      * @param kind Whether to parse an ANNOTATION or TYPE_ANNOTATION
  2840      * @param kind Whether to parse an ANNOTATION or TYPE_ANNOTATION
  2913      */
  2841      */
  2914     JCAnnotation annotation(int pos, Tag kind) {
  2842     JCAnnotation annotation(int pos, Tag kind) {
  2915         // accept(AT); // AT consumed by caller
  2843         // accept(AT); // AT consumed by caller
  2916         if (kind == Tag.TYPE_ANNOTATION) {
  2844         if (kind == Tag.TYPE_ANNOTATION) {
  2917             checkTypeAnnotations();
  2845             checkSourceLevel(Feature.TYPE_ANNOTATIONS);
  2918         }
  2846         }
  2919         JCTree ident = qualident(false);
  2847         JCTree ident = qualident(false);
  2920         List<JCExpression> fieldValues = annotationFieldValuesOpt();
  2848         List<JCExpression> fieldValues = annotationFieldValuesOpt();
  2921         JCAnnotation ann;
  2849         JCAnnotation ann;
  2922         if (kind == Tag.ANNOTATION) {
  2850         if (kind == Tag.ANNOTATION) {
  3026                                                                      Comment dc,
  2954                                                                      Comment dc,
  3027                                                                      T vdefs,
  2955                                                                      T vdefs,
  3028                                                                      boolean localDecl)
  2956                                                                      boolean localDecl)
  3029     {
  2957     {
  3030         JCVariableDecl head = variableDeclaratorRest(pos, mods, type, name, reqInit, dc, localDecl);
  2958         JCVariableDecl head = variableDeclaratorRest(pos, mods, type, name, reqInit, dc, localDecl);
  3031         boolean implicit = allowLocalVariableTypeInference && head.vartype == null;
  2959         boolean implicit = Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source) && head.vartype == null;
  3032         vdefs.append(head);
  2960         vdefs.append(head);
  3033         while (token.kind == COMMA) {
  2961         while (token.kind == COMMA) {
  3034             if (implicit) {
  2962             if (implicit) {
  3035                 reportSyntaxError(pos, "var.not.allowed.compound");
  2963                 reportSyntaxError(pos, "var.not.allowed.compound");
  3036             }
  2964             }
  3064             init = variableInitializer();
  2992             init = variableInitializer();
  3065         }
  2993         }
  3066         else if (reqInit) syntaxError(token.pos, "expected", EQ);
  2994         else if (reqInit) syntaxError(token.pos, "expected", EQ);
  3067         JCTree elemType = TreeInfo.innermostType(type, true);
  2995         JCTree elemType = TreeInfo.innermostType(type, true);
  3068         int startPos = Position.NOPOS;
  2996         int startPos = Position.NOPOS;
  3069         if (allowLocalVariableTypeInference && elemType.hasTag(IDENT)) {
  2997         if (Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source) && elemType.hasTag(IDENT)) {
  3070             Name typeName = ((JCIdent)elemType).name;
  2998             Name typeName = ((JCIdent)elemType).name;
  3071             if (isRestrictedLocalVarTypeName(typeName)) {
  2999             if (isRestrictedLocalVarTypeName(typeName)) {
  3072                 if (type.hasTag(TYPEARRAY)) {
  3000                 if (type.hasTag(TYPEARRAY)) {
  3073                     //error - 'var' and arrays
  3001                     //error - 'var' and arrays
  3074                     reportSyntaxError(pos, "var.not.allowed.array");
  3002                     reportSyntaxError(pos, "var.not.allowed.array");
  3098                 return false;
  3026                 return false;
  3099         }
  3027         }
  3100     }
  3028     }
  3101 
  3029 
  3102     boolean isRestrictedLocalVarTypeName(Name name) {
  3030     boolean isRestrictedLocalVarTypeName(Name name) {
  3103         return allowLocalVariableTypeInference && name == names.var;
  3031         return Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source) && name == names.var;
  3104     }
  3032     }
  3105 
  3033 
  3106     /** VariableDeclaratorId = Ident BracketsOpt
  3034     /** VariableDeclaratorId = Ident BracketsOpt
  3107      */
  3035      */
  3108     JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type) {
  3036     JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type) {
  3174         JCExpression t = term(EXPR | TYPE);
  3102         JCExpression t = term(EXPR | TYPE);
  3175         if ((lastmode & TYPE) != 0 && LAX_IDENTIFIER.accepts(token.kind)) {
  3103         if ((lastmode & TYPE) != 0 && LAX_IDENTIFIER.accepts(token.kind)) {
  3176             JCModifiers mods = toP(F.at(startPos).Modifiers(Flags.FINAL));
  3104             JCModifiers mods = toP(F.at(startPos).Modifiers(Flags.FINAL));
  3177             return variableDeclaratorRest(token.pos, mods, t, ident(), true, null, true);
  3105             return variableDeclaratorRest(token.pos, mods, t, ident(), true, null, true);
  3178         } else {
  3106         } else {
  3179             checkVariableInTryWithResources(startPos);
  3107             checkSourceLevel(Feature.EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES);
  3180             if (!t.hasTag(IDENT) && !t.hasTag(SELECT)) {
  3108             if (!t.hasTag(IDENT) && !t.hasTag(SELECT)) {
  3181                 log.error(t.pos(), Errors.TryWithResourcesExprNeedsVar);
  3109                 log.error(t.pos(), Errors.TryWithResourcesExprNeedsVar);
  3182             }
  3110             }
  3183 
  3111 
  3184             return t;
  3112             return t;
  3276         return toplevel;
  3204         return toplevel;
  3277     }
  3205     }
  3278 
  3206 
  3279     JCModuleDecl moduleDecl(JCModifiers mods, ModuleKind kind, Comment dc) {
  3207     JCModuleDecl moduleDecl(JCModifiers mods, ModuleKind kind, Comment dc) {
  3280         int pos = token.pos;
  3208         int pos = token.pos;
  3281         if (!allowModules) {
  3209         checkSourceLevel(Feature.MODULES);
  3282             log.error(pos, Errors.ModulesNotSupportedInSource(source.name));
       
  3283             allowModules = true;
       
  3284         }
       
  3285 
  3210 
  3286         nextToken();
  3211         nextToken();
  3287         JCExpression name = qualident(false);
  3212         JCExpression name = qualident(false);
  3288         List<JCDirective> directives = null;
  3213         List<JCDirective> directives = null;
  3289 
  3214 
  3698                     storeEnd(mods, pos);
  3623                     storeEnd(mods, pos);
  3699                 }
  3624                 }
  3700                 List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
  3625                 List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
  3701 
  3626 
  3702                 if (annosAfterParams.nonEmpty()) {
  3627                 if (annosAfterParams.nonEmpty()) {
  3703                     checkAnnotationsAfterTypeParams(annosAfterParams.head.pos);
  3628                     checkSourceLevel(annosAfterParams.head.pos, Feature.ANNOTATIONS_AFTER_TYPE_PARAMS);
  3704                     mods.annotations = mods.annotations.appendList(annosAfterParams);
  3629                     mods.annotations = mods.annotations.appendList(annosAfterParams);
  3705                     if (mods.pos == Position.NOPOS)
  3630                     if (mods.pos == Position.NOPOS)
  3706                         mods.pos = mods.annotations.head.pos;
  3631                         mods.pos = mods.annotations.head.pos;
  3707                 }
  3632                 }
  3708 
  3633 
  3766                               List<JCTypeParameter> typarams,
  3691                               List<JCTypeParameter> typarams,
  3767                               boolean isInterface, boolean isVoid,
  3692                               boolean isInterface, boolean isVoid,
  3768                               Comment dc) {
  3693                               Comment dc) {
  3769         if (isInterface) {
  3694         if (isInterface) {
  3770             if ((mods.flags & Flags.STATIC) != 0) {
  3695             if ((mods.flags & Flags.STATIC) != 0) {
  3771                 checkStaticInterfaceMethods();
  3696                 checkSourceLevel(Feature.STATIC_INTERFACE_METHODS);
  3772             }
  3697             }
  3773             if ((mods.flags & Flags.PRIVATE) != 0) {
  3698             if ((mods.flags & Flags.PRIVATE) != 0) {
  3774                 checkPrivateInterfaceMethods();
  3699                 checkSourceLevel(Feature.PRIVATE_INTERFACE_METHODS);
  3775             }
  3700             }
  3776         }
  3701         }
  3777         JCVariableDecl prevReceiverParam = this.receiverParam;
  3702         JCVariableDecl prevReceiverParam = this.receiverParam;
  3778         try {
  3703         try {
  3779             this.receiverParam = null;
  3704             this.receiverParam = null;
  4224         default:
  4149         default:
  4225             return TypeTag.NONE;
  4150             return TypeTag.NONE;
  4226         }
  4151         }
  4227     }
  4152     }
  4228 
  4153 
  4229     void checkDiamond() {
  4154     void checkSourceLevel(Feature feature) {
  4230         if (!allowDiamond) {
  4155         checkSourceLevel(token.pos, feature);
  4231             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.DiamondNotSupportedInSource(source.name));
  4156     }
  4232         }
  4157 
  4233     }
  4158     protected void checkSourceLevel(int pos, Feature feature) {
  4234     void checkMulticatch() {
  4159         if (!feature.allowedInSource(source)) {
  4235         if (!allowMulticatch) {
  4160             log.error(DiagnosticFlag.SOURCE_LEVEL, pos, feature.error(source.name));
  4236             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.MulticatchNotSupportedInSource(source.name));
       
  4237         }
       
  4238     }
       
  4239     void checkTryWithResources() {
       
  4240         if (!allowTWR) {
       
  4241             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.TryWithResourcesNotSupportedInSource(source.name));
       
  4242         }
       
  4243     }
       
  4244     void checkVariableInTryWithResources(int startPos) {
       
  4245         if (!allowEffectivelyFinalVariablesInTWR) {
       
  4246             log.error(DiagnosticFlag.SOURCE_LEVEL, startPos, Errors.VarInTryWithResourcesNotSupportedInSource(source.name));
       
  4247         }
       
  4248     }
       
  4249     void checkLambda() {
       
  4250         if (!allowLambda) {
       
  4251             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.LambdaNotSupportedInSource(source.name));
       
  4252         }
       
  4253     }
       
  4254     void checkMethodReferences() {
       
  4255         if (!allowMethodReferences) {
       
  4256             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.MethodReferencesNotSupportedInSource(source.name));
       
  4257         }
       
  4258     }
       
  4259     void checkDefaultMethods() {
       
  4260         if (!allowDefaultMethods) {
       
  4261             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.DefaultMethodsNotSupportedInSource(source.name));
       
  4262         }
       
  4263     }
       
  4264     void checkIntersectionTypesInCast() {
       
  4265         if (!allowIntersectionTypesInCast) {
       
  4266             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.IntersectionTypesInCastNotSupportedInSource(source.name));
       
  4267         }
       
  4268     }
       
  4269     void checkStaticInterfaceMethods() {
       
  4270         if (!allowStaticInterfaceMethods) {
       
  4271             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.StaticIntfMethodsNotSupportedInSource(source.name));
       
  4272         }
       
  4273     }
       
  4274     void checkTypeAnnotations() {
       
  4275         if (!allowTypeAnnotations) {
       
  4276             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.TypeAnnotationsNotSupportedInSource(source.name));
       
  4277         }
       
  4278     }
       
  4279     void checkPrivateInterfaceMethods() {
       
  4280         if (!allowPrivateInterfaceMethods) {
       
  4281             log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, CompilerProperties.Errors.PrivateIntfMethodsNotSupportedInSource(source.name));
       
  4282         }
       
  4283     }
       
  4284     protected void checkAnnotationsAfterTypeParams(int pos) {
       
  4285         if (!allowAnnotationsAfterTypeParams) {
       
  4286             log.error(DiagnosticFlag.SOURCE_LEVEL, pos, Errors.AnnotationsAfterTypeParamsNotSupportedInSource(source.name));
       
  4287         }
  4161         }
  4288     }
  4162     }
  4289 
  4163 
  4290     /*
  4164     /*
  4291      * a functional source tree and end position mappings
  4165      * a functional source tree and end position mappings