src/share/classes/com/sun/tools/javac/parser/JavacParser.java
Print this page
*** 140,150 ****
/** Switch: should we recognize annotations?
*/
boolean allowAnnotations;
! /** Switch: should we recognize automatic resource management?
*/
boolean allowTWR;
/** Switch: should we keep docComments?
*/
--- 140,150 ----
/** Switch: should we recognize annotations?
*/
boolean allowAnnotations;
! /** Switch: should we recognize try-with-resources?
*/
boolean allowTWR;
/** Switch: should we keep docComments?
*/
*** 2182,2214 ****
ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
defs.append(resource());
while (S.token() == SEMI) {
// All but last of multiple declarators subsume a semicolon
storeEnd(defs.elems.last(), S.endPos());
S.nextToken();
defs.append(resource());
}
return defs.toList();
}
! /** Resource =
! * VariableModifiers Type VariableDeclaratorId = Expression
! * | Expression
*/
JCTree resource() {
! int pos = S.pos();
! if (S.token() == FINAL || S.token() == MONKEYS_AT) {
! return variableDeclaratorRest(pos, optFinal(0), parseType(),
! ident(), true, null);
! } else {
! JCExpression t = term(EXPR | TYPE);
! if ((lastmode & TYPE) != 0 && S.token() == IDENTIFIER)
! return variableDeclaratorRest(pos, toP(F.at(pos).Modifiers(Flags.FINAL)), t,
! ident(), true, null);
! else
! return t;
! }
}
/** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
*/
public JCTree.JCCompilationUnit parseCompilationUnit() {
--- 2182,2208 ----
ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
defs.append(resource());
while (S.token() == SEMI) {
// All but last of multiple declarators subsume a semicolon
storeEnd(defs.elems.last(), S.endPos());
+ int semiColonPos = S.pos();
S.nextToken();
+ if (S.token() == RPAREN) { // Illegal trailing semicolon
+ // after last resource
+ error(semiColonPos, "try.resource.trailing.semi");
+ break;
+ }
defs.append(resource());
}
return defs.toList();
}
! /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
*/
JCTree resource() {
! return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL),
! parseType(), ident(), true, null);
}
/** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
*/
public JCTree.JCCompilationUnit parseCompilationUnit() {