1.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Apr 14 12:23:29 2010 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Apr 14 12:31:55 2010 +0100 1.3 @@ -131,6 +131,7 @@ 1.4 this.allowForeach = source.allowForeach(); 1.5 this.allowStaticImport = source.allowStaticImport(); 1.6 this.allowAnnotations = source.allowAnnotations(); 1.7 + this.allowDiamond = source.allowDiamond(); 1.8 this.allowTypeAnnotations = source.allowTypeAnnotations(); 1.9 this.keepDocComments = keepDocComments; 1.10 if (keepDocComments) 1.11 @@ -148,6 +149,10 @@ 1.12 */ 1.13 boolean allowGenerics; 1.14 1.15 + /** Switch: Should diamond operator be recognized? 1.16 + */ 1.17 + boolean allowDiamond; 1.18 + 1.19 /** Switch: Should varargs be recognized? 1.20 */ 1.21 boolean allowVarargs; 1.22 @@ -190,10 +195,11 @@ 1.23 * mode = NOPARAMS : no parameters allowed for type 1.24 * mode = TYPEARG : type argument 1.25 */ 1.26 - static final int EXPR = 1; 1.27 - static final int TYPE = 2; 1.28 - static final int NOPARAMS = 4; 1.29 - static final int TYPEARG = 8; 1.30 + static final int EXPR = 0x1; 1.31 + static final int TYPE = 0x2; 1.32 + static final int NOPARAMS = 0x4; 1.33 + static final int TYPEARG = 0x8; 1.34 + static final int DIAMOND = 0x10; 1.35 1.36 /** The current mode. 1.37 */ 1.38 @@ -1343,6 +1349,11 @@ 1.39 ListBuffer<JCExpression> args = lb(); 1.40 if (S.token() == LT) { 1.41 S.nextToken(); 1.42 + if (S.token() == GT && (mode & DIAMOND) != 0) { 1.43 + checkDiamond(); 1.44 + S.nextToken(); 1.45 + return List.nil(); 1.46 + } 1.47 args.append(((mode & EXPR) == 0) ? typeArgument() : parseType()); 1.48 while (S.token() == COMMA) { 1.49 S.nextToken(); 1.50 @@ -1516,7 +1527,7 @@ 1.51 t = F.AnnotatedType(newAnnotations, t); 1.52 1.53 int oldmode = mode; 1.54 - mode = TYPE; 1.55 + mode = TYPE | DIAMOND; 1.56 if (S.token() == LT) { 1.57 checkGenerics(); 1.58 t = typeArguments(t); 1.59 @@ -1569,8 +1580,11 @@ 1.60 JCExpression innerCreator(int newpos, List<JCExpression> typeArgs, JCExpression encl) { 1.61 JCExpression t = toP(F.at(S.pos()).Ident(ident())); 1.62 if (S.token() == LT) { 1.63 + int oldmode = mode; 1.64 + mode |= DIAMOND; 1.65 checkGenerics(); 1.66 t = typeArguments(t); 1.67 + mode = oldmode; 1.68 } 1.69 return classCreatorRest(newpos, encl, typeArgs, t); 1.70 } 1.71 @@ -3173,4 +3187,10 @@ 1.72 allowTypeAnnotations = true; 1.73 } 1.74 } 1.75 + void checkDiamond() { 1.76 + if (!allowDiamond) { 1.77 + log.error(S.pos(), "diamond.not.supported.in.source", source.name); 1.78 + allowDiamond = true; 1.79 + } 1.80 + } 1.81 }