7014734: Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources

Mon, 31 Jan 2011 19:06:32 -0800

author
darcy
date
Mon, 31 Jan 2011 19:06:32 -0800
changeset 850
2ab47c4cd618
parent 849
7a75a1803c7a
child 851
cad51b6eb7a6

7014734: Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/parser/JavacParser.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/resources/compiler.properties file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/BadTwrSyntax.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/BadTwrSyntax.out file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/TryResourceTrailingSemi.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Jan 28 16:54:18 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Jan 31 19:06:32 2011 -0800
     1.3 @@ -1639,7 +1639,7 @@
     1.4       *     | WHILE ParExpression Statement
     1.5       *     | DO Statement WHILE ParExpression ";"
     1.6       *     | TRY Block ( Catches | [Catches] FinallyPart )
     1.7 -     *     | TRY "(" ResourceSpecification ")" Block [Catches] [FinallyPart]
     1.8 +     *     | TRY "(" ResourceSpecification ";"opt ")" Block [Catches] [FinallyPart]
     1.9       *     | SWITCH ParExpression "{" SwitchBlockStatementGroups "}"
    1.10       *     | SYNCHRONIZED ParExpression Block
    1.11       *     | RETURN [Expression] ";"
    1.12 @@ -2182,13 +2182,12 @@
    1.13          ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
    1.14          defs.append(resource());
    1.15          while (S.token() == SEMI) {
    1.16 -            // All but last of multiple declarators subsume a semicolon
    1.17 +            // All but last of multiple declarators must subsume a semicolon
    1.18              storeEnd(defs.elems.last(), S.endPos());
    1.19              int semiColonPos = S.pos();
    1.20              S.nextToken();
    1.21 -            if (S.token() == RPAREN) { // Illegal trailing semicolon
    1.22 +            if (S.token() == RPAREN) { // Optional trailing semicolon
    1.23                                         // after last resource
    1.24 -                error(semiColonPos, "try.resource.trailing.semi");
    1.25                  break;
    1.26              }
    1.27              defs.append(resource());
     2.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Jan 28 16:54:18 2011 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Jan 31 19:06:32 2011 -0800
     2.3 @@ -298,9 +298,6 @@
     2.4  compiler.err.try.resource.may.not.be.assigned=\
     2.5      auto-closeable resource {0} may not be assigned
     2.6  
     2.7 -compiler.err.try.resource.trailing.semi=\
     2.8 -    illegal trailing semicolon in resources declaration
     2.9 -
    2.10  # 0: symbol
    2.11  compiler.err.multicatch.parameter.may.not.be.assigned=\
    2.12      multi-catch parameter {0} may not be assigned
     3.1 --- a/test/tools/javac/TryWithResources/BadTwrSyntax.java	Fri Jan 28 16:54:18 2011 -0800
     3.2 +++ b/test/tools/javac/TryWithResources/BadTwrSyntax.java	Mon Jan 31 19:06:32 2011 -0800
     3.3 @@ -4,13 +4,18 @@
     3.4   * @author Joseph D. Darcy
     3.5   * @summary Verify bad TWRs don't compile
     3.6   * @compile/fail -source 6 BadTwrSyntax.java
     3.7 - * @compile/fail/ref=BadTwrSyntax.out  -XDrawDiagnostics BadTwrSyntax.java
     3.8 + * @compile/fail/ref=BadTwrSyntax.out -XDrawDiagnostics BadTwrSyntax.java
     3.9   */
    3.10  
    3.11  import java.io.IOException;
    3.12  public class BadTwrSyntax implements AutoCloseable {
    3.13      public static void main(String... args) throws Exception {
    3.14 -        // illegal semicolon ending resources
    3.15 +        // illegal double semicolon ending resources
    3.16 +        try(BadTwr twrflow = new BadTwr();;) {
    3.17 +            System.out.println(twrflow.toString());
    3.18 +        }
    3.19 +
    3.20 +        // but one semicolon is fine
    3.21          try(BadTwr twrflow = new BadTwr();) {
    3.22              System.out.println(twrflow.toString());
    3.23          }
     4.1 --- a/test/tools/javac/TryWithResources/BadTwrSyntax.out	Fri Jan 28 16:54:18 2011 -0800
     4.2 +++ b/test/tools/javac/TryWithResources/BadTwrSyntax.out	Mon Jan 31 19:06:32 2011 -0800
     4.3 @@ -1,2 +1,7 @@
     4.4 -BadTwrSyntax.java:14:42: compiler.err.try.resource.trailing.semi
     4.5 -1 error
     4.6 +BadTwrSyntax.java:14:43: compiler.err.illegal.start.of.type
     4.7 +BadTwrSyntax.java:14:44: compiler.err.expected: =
     4.8 +BadTwrSyntax.java:14:45: compiler.err.expected: ')'
     4.9 +BadTwrSyntax.java:14:47: compiler.err.expected: '{'
    4.10 +BadTwrSyntax.java:15:19: compiler.err.illegal.start.of.expr
    4.11 +BadTwrSyntax.java:15:23: compiler.err.expected: ';'
    4.12 +6 errors
     5.1 --- a/test/tools/javac/diags/examples/TryResourceTrailingSemi.java	Fri Jan 28 16:54:18 2011 -0800
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,35 +0,0 @@
     5.4 -/*
     5.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     5.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 - *
     5.8 - * This code is free software; you can redistribute it and/or modify it
     5.9 - * under the terms of the GNU General Public License version 2 only, as
    5.10 - * published by the Free Software Foundation.
    5.11 - *
    5.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 - * version 2 for more details (a copy is included in the LICENSE file that
    5.16 - * accompanied this code).
    5.17 - *
    5.18 - * You should have received a copy of the GNU General Public License version
    5.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 - *
    5.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 - * or visit www.oracle.com if you need additional information or have any
    5.24 - * questions.
    5.25 - */
    5.26 -
    5.27 -// key: compiler.err.try.resource.trailing.semi
    5.28 -
    5.29 -class TryResoureTrailingSemi implements AutoCloseable {
    5.30 -    public static void main(String... args) {
    5.31 -        try(TryResoureTrailingSemi r = new TryResoureTrailingSemi();) {
    5.32 -            System.out.println(r.toString());
    5.33 -        }
    5.34 -    }
    5.35 -
    5.36 -    @Override
    5.37 -    public void close() {return;}
    5.38 -}

mercurial