langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
changeset 5320 e2aaa958b02d
parent 5013 e942b2e52479
child 5321 c8efe769cb3b
equal deleted inserted replaced
5319:63dc7f367a37 5320:e2aaa958b02d
   129         this.allowAsserts = source.allowAsserts();
   129         this.allowAsserts = source.allowAsserts();
   130         this.allowEnums = source.allowEnums();
   130         this.allowEnums = source.allowEnums();
   131         this.allowForeach = source.allowForeach();
   131         this.allowForeach = source.allowForeach();
   132         this.allowStaticImport = source.allowStaticImport();
   132         this.allowStaticImport = source.allowStaticImport();
   133         this.allowAnnotations = source.allowAnnotations();
   133         this.allowAnnotations = source.allowAnnotations();
   134         this.allowDiamond = source.allowDiamond();
       
   135         this.allowTypeAnnotations = source.allowTypeAnnotations();
   134         this.allowTypeAnnotations = source.allowTypeAnnotations();
   136         this.keepDocComments = keepDocComments;
   135         this.keepDocComments = keepDocComments;
   137         if (keepDocComments)
   136         if (keepDocComments)
   138             docComments = new HashMap<JCTree,String>();
   137             docComments = new HashMap<JCTree,String>();
   139         this.keepLineMap = keepLineMap;
   138         this.keepLineMap = keepLineMap;
   147 
   146 
   148     /** Switch: Should generics be recognized?
   147     /** Switch: Should generics be recognized?
   149      */
   148      */
   150     boolean allowGenerics;
   149     boolean allowGenerics;
   151 
   150 
   152     /** Switch: Should diamond operator be recognized?
       
   153      */
       
   154     boolean allowDiamond;
       
   155 
       
   156     /** Switch: Should varargs be recognized?
   151     /** Switch: Should varargs be recognized?
   157      */
   152      */
   158     boolean allowVarargs;
   153     boolean allowVarargs;
   159 
   154 
   160     /** Switch: should we recognize assert statements, or just give a warning?
   155     /** Switch: should we recognize assert statements, or just give a warning?
   197      */
   192      */
   198     static final int EXPR = 1;
   193     static final int EXPR = 1;
   199     static final int TYPE = 2;
   194     static final int TYPE = 2;
   200     static final int NOPARAMS = 4;
   195     static final int NOPARAMS = 4;
   201     static final int TYPEARG = 8;
   196     static final int TYPEARG = 8;
   202     static final int DIAMOND = 16;
       
   203 
   197 
   204     /** The current mode.
   198     /** The current mode.
   205      */
   199      */
   206     private int mode = 0;
   200     private int mode = 0;
   207 
   201 
  1347      */
  1341      */
  1348     List<JCExpression> typeArguments() {
  1342     List<JCExpression> typeArguments() {
  1349         ListBuffer<JCExpression> args = lb();
  1343         ListBuffer<JCExpression> args = lb();
  1350         if (S.token() == LT) {
  1344         if (S.token() == LT) {
  1351             S.nextToken();
  1345             S.nextToken();
  1352             if (S.token() == GT && (mode & DIAMOND) != 0) {
       
  1353                 checkDiamond();
       
  1354                 S.nextToken();
       
  1355                 return List.nil();
       
  1356             }
       
  1357             args.append(((mode & EXPR) == 0) ? typeArgument() : parseType());
  1346             args.append(((mode & EXPR) == 0) ? typeArgument() : parseType());
  1358             while (S.token() == COMMA) {
  1347             while (S.token() == COMMA) {
  1359                 S.nextToken();
  1348                 S.nextToken();
  1360                 args.append(((mode & EXPR) == 0) ? typeArgument() : parseType());
  1349                 args.append(((mode & EXPR) == 0) ? typeArgument() : parseType());
  1361             }
  1350             }
  1525         // handle type annotations for non primitive arrays
  1514         // handle type annotations for non primitive arrays
  1526         if (!newAnnotations.isEmpty())
  1515         if (!newAnnotations.isEmpty())
  1527             t = F.AnnotatedType(newAnnotations, t);
  1516             t = F.AnnotatedType(newAnnotations, t);
  1528 
  1517 
  1529         int oldmode = mode;
  1518         int oldmode = mode;
  1530         mode = TYPE | DIAMOND;
  1519         mode = TYPE;
  1531         if (S.token() == LT) {
  1520         if (S.token() == LT) {
  1532             checkGenerics();
  1521             checkGenerics();
  1533             t = typeArguments(t);
  1522             t = typeArguments(t);
  1534         }
  1523         }
  1535         while (S.token() == DOT) {
  1524         while (S.token() == DOT) {
  1578     /** InnerCreator = Ident [TypeArguments] ClassCreatorRest
  1567     /** InnerCreator = Ident [TypeArguments] ClassCreatorRest
  1579      */
  1568      */
  1580     JCExpression innerCreator(int newpos, List<JCExpression> typeArgs, JCExpression encl) {
  1569     JCExpression innerCreator(int newpos, List<JCExpression> typeArgs, JCExpression encl) {
  1581         JCExpression t = toP(F.at(S.pos()).Ident(ident()));
  1570         JCExpression t = toP(F.at(S.pos()).Ident(ident()));
  1582         if (S.token() == LT) {
  1571         if (S.token() == LT) {
  1583             int oldmode = mode;
       
  1584             mode |= DIAMOND;
       
  1585             checkGenerics();
  1572             checkGenerics();
  1586             t = typeArguments(t);
  1573             t = typeArguments(t);
  1587             mode = oldmode;
       
  1588         }
  1574         }
  1589         return classCreatorRest(newpos, encl, typeArgs, t);
  1575         return classCreatorRest(newpos, encl, typeArgs, t);
  1590     }
  1576     }
  1591 
  1577 
  1592     /** ArrayCreatorRest = [Annotations] "[" ( "]" BracketsOpt ArrayInitializer
  1578     /** ArrayCreatorRest = [Annotations] "[" ( "]" BracketsOpt ArrayInitializer
  3149         default:
  3135         default:
  3150             return -1;
  3136             return -1;
  3151         }
  3137         }
  3152     }
  3138     }
  3153 
  3139 
  3154     void checkDiamond() {
       
  3155         if (!allowDiamond) {
       
  3156             log.error(S.pos(), "diamond.not.supported.in.source", source.name);
       
  3157             allowDiamond = true;
       
  3158         }
       
  3159     }
       
  3160     void checkGenerics() {
  3140     void checkGenerics() {
  3161         if (!allowGenerics) {
  3141         if (!allowGenerics) {
  3162             log.error(S.pos(), "generics.not.supported.in.source", source.name);
  3142             log.error(S.pos(), "generics.not.supported.in.source", source.name);
  3163             allowGenerics = true;
  3143             allowGenerics = true;
  3164         }
  3144         }