changeset 401:17f445e54028

reject old array syntax
author mali
date Tue, 24 Mar 2009 17:22:12 -0400
parents 8c7056605d9a
children 31ae4d53b775
files src/share/classes/com/sun/tools/javac/parser/JavacParser.java test/tools/javac/typeAnnotations/failures/OldArray.java
diffstat 2 files changed, 47 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Mar 24 17:01:14 2009 -0400
+++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Mar 24 17:22:12 2009 -0400
@@ -905,6 +905,7 @@
     protected JCExpression term3() {
         int pos = S.pos();
         JCExpression t;
+        List<JCAnnotation> annos = null;
         List<JCExpression> typeArgs = typeArgumentsOpt(EXPR);
         switch (S.token()) {
         case QUES:
@@ -1077,14 +1078,17 @@
             t = toP(F.at(S.pos()).Ident(ident()));
             loop: while (true) {
                 pos = S.pos();
+                if (S.token() == Token.MONKEYS_AT)
+                    annos = typeAnnotationsOpt();
                 switch (S.token()) {
                 case LBRACKET:
                     S.nextToken();
 
                     /// JSR 308: handle annotated array levels in an array type
-                    if (S.token() == MONKEYS_AT || S.token() == RBRACKET) {
+                    if (S.token() == RBRACKET) {
                         ListBuffer<List<JCAnnotation>> stack = ListBuffer.lb();
-                        stack.prepend(typeAnnotationsOpt());
+                        stack.prepend(annos);
+                        annos = null;
 
                         S.nextToken();
 
@@ -1092,7 +1096,7 @@
                         t = toP(F.at(pos).TypeArray(t));
 
                         if (!stack.isEmpty() && !stack.first().isEmpty()) {
-                            List<JCAnnotation> annos = stack.next();
+                            annos = stack.next();
                             assert t.getTag() == JCTree.TYPEARRAY;
                             JCArrayTypeTree arr = (JCArrayTypeTree)t;
                             arr.elemtype = toP(F.at(pos).AnnotatedType(annos, arr.elemtype));
@@ -1102,12 +1106,14 @@
                         if ((mode & EXPR) != 0) {
                             mode = EXPR;
                             JCExpression t1 = term();
+                            if (annos != null && !annos.isEmpty()) t = illegal(annos.head.pos);
                             t = to(F.at(pos).Indexed(t, t1));
                         }
                         accept(RBRACKET);
                     }
                     break loop;
                 case LPAREN:
+                    if (annos != null && !annos.isEmpty()) return illegal(annos.head.pos);
                     if ((mode & EXPR) != 0) {
                         mode = EXPR;
                         t = arguments(typeArgs, t);
@@ -1115,6 +1121,7 @@
                     }
                     break loop;
                 case DOT:
+                    if (annos != null && !annos.isEmpty()) return illegal(annos.head.pos);
                     S.nextToken();
                     int oldmode = mode;
                     mode &= ~NOPARAMS;
@@ -1154,7 +1161,10 @@
                     // typeArgs saved for next loop iteration.
                     t = toP(F.at(pos).Select(t, ident()));
                     break;
+                case ELLIPSIS:
+                    break loop;
                 default:
+                    if (annos != null && !annos.isEmpty()) return illegal(annos.head.pos);
                     break loop;
                 }
             }
@@ -1187,7 +1197,6 @@
         while (true) {
             int pos1 = S.pos();
 
-            List<JCAnnotation> annos = null;
             if (S.token() == MONKEYS_AT)
                 annos = typeAnnotationsOpt();
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/typeAnnotations/failures/OldArray.java	Tue Mar 24 17:22:12 2009 -0400
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary test old array syntax
+ * @author Mahmood Ali
+ * @compile/fail OldArray.java
+ */
+class OldArray {
+  String [@A]  s() { return null; }
+}
+
+@interface A { }