Support Java 7 "try with resources" and "multi-catch"

This commit is contained in:
Sam Harwell 2013-04-22 17:23:54 -05:00
parent c8701a9434
commit a670d7d2b0
2 changed files with 51 additions and 17 deletions

View File

@ -628,11 +628,8 @@ statement
| 'for' '(' forControl ')' statement | 'for' '(' forControl ')' statement
| 'while' parExpression statement | 'while' parExpression statement
| 'do' statement 'while' parExpression ';' | 'do' statement 'while' parExpression ';'
| 'try' block | 'try' block (catches finallyBlock? | finallyBlock)
( catches 'finally' block | 'try' resourceSpecification block catches? finallyBlock?
| catches
| 'finally' block
)
| 'switch' parExpression '{' switchBlockStatementGroups '}' | 'switch' parExpression '{' switchBlockStatementGroups '}'
| 'synchronized' parExpression block | 'synchronized' parExpression block
| 'return' expression? ';' | 'return' expression? ';'
@ -645,11 +642,31 @@ statement
; ;
catches catches
: catchClause (catchClause)* : catchClause+
; ;
catchClause catchClause
: 'catch' '(' formalParameter ')' block : 'catch' '(' variableModifiers catchType Identifier ')' block
;
catchType
: qualifiedName ('|' qualifiedName)*
;
finallyBlock
: 'finally' block
;
resourceSpecification
: '(' resources ';'? ')'
;
resources
: resource (';' resource)*
;
resource
: variableModifiers classOrInterfaceType variableDeclaratorId '=' expression
; ;
formalParameter formalParameter

View File

@ -625,11 +625,8 @@ statement
| 'for' '(' forControl ')' statement | 'for' '(' forControl ')' statement
| 'while' parExpression statement | 'while' parExpression statement
| 'do' statement 'while' parExpression ';' | 'do' statement 'while' parExpression ';'
| 'try' block | 'try' block (catches finallyBlock? | finallyBlock)
( catches 'finally' block | 'try' resourceSpecification block catches? finallyBlock?
| catches
| 'finally' block
)
| 'switch' parExpression '{' switchBlockStatementGroups '}' | 'switch' parExpression '{' switchBlockStatementGroups '}'
| 'synchronized' parExpression block | 'synchronized' parExpression block
| 'return' expression? ';' | 'return' expression? ';'
@ -642,11 +639,31 @@ statement
; ;
catches catches
: catchClause (catchClause)* : catchClause+
; ;
catchClause catchClause
: 'catch' '(' formalParameter ')' block : 'catch' '(' variableModifiers catchType Identifier ')' block
;
catchType
: qualifiedName ('|' qualifiedName)*
;
finallyBlock
: 'finally' block
;
resourceSpecification
: '(' resources ';'? ')'
;
resources
: resource (';' resource)*
;
resource
: variableModifiers classOrInterfaceType variableDeclaratorId '=' expression
; ;
formalParameter formalParameter