add support for try-with-resources syntax in rules
@@ -2819,16 +2819,25 @@ void SynchronizedStatement():
"synchronized" "(" Expression(null) ")" Block(null)
}
-void TryStatement():
-/*
- * Semantic check required here to make sure that at least one
- * finally/catch is present.
- */
+void ResourceDeclaration():
{}
{
- "try" Block(null)
- ( "catch" "(" FormalParameter() ")" Block(null) )*
- [ "finally" Block(null) ]
+ Type() VariableDeclaratorId() "=" Expression(null)
+}
+
+void TryStatement():
+{ boolean empty = true; }
+{
+ "try" ["(" ResourceDeclaration()
+ (LOOKAHEAD(2) ";" ResourceDeclaration())* (";")? ")" { empty = false; }
+ ] Block(null)
+ ( "catch" "(" FormalParameter() ")" Block(null) { empty = false; } )*
+ [ "finally" Block(null) { empty = false; } ]
+
+ {
+ if (empty)
+ throw new ParseException("At least one catch or finally block expected.");
+ }
}
/* We use productions to match >>>, >> and > so that we can keep the
