diff --git a/src/Language/Java/Assignment.hs b/src/Language/Java/Assignment.hs index fee46956a..0b571722b 100644 --- a/src/Language/Java/Assignment.hs +++ b/src/Language/Java/Assignment.hs @@ -452,16 +452,19 @@ throw :: Assignment Term throw = makeTerm <$> symbol ThrowStatement <*> children (Statement.Throw <$> term expression) try :: Assignment Term -try = symbol TryStatement *> children tryWithResources <|> makeTerm <$> symbol TryStatement <*> children (Statement.Try <$> term expression <*> (append <$> optional catches <*> optional finally)) +try = symbol TryStatement *> children tryWithResources <|> standardTry + +standardTry :: Assignment Term +standardTry = makeTerm <$> symbol TryStatement <*> children (Statement.Try <$> term expression <*> (append <$> optional catches <*> optional finally)) catches :: Assignment [Term] catches = symbol Catches *> children (manyTerm catch) where - catch = makeTerm <$> symbol CatchClause <*> children (Statement.Catch <$> catchFormalParameter <*> term expression) + catch = makeTerm <$> symbol CatchClause <*> children (Statement.Catch <$> catchFormalParameter <*> block) catchFormalParameter = makeTerm <$> symbol CatchFormalParameter <*> children (flip Type.Annotation <$> catchType <* symbol VariableDeclaratorId <*> children identifier) catchType :: Assignment Term -catchType = makeTerm <$> symbol CatchType <*> (Java.Syntax.CatchType <$> many type') +catchType = makeTerm <$> symbol CatchType <*> children (Java.Syntax.CatchType <$> many type') finally :: Assignment Term finally = makeTerm <$> symbol Finally <*> children (Statement.Finally <$> term expression) diff --git a/test/fixtures/java/corpus/try.java b/test/fixtures/java/corpus/try.java new file mode 100644 index 000000000..b3eea2991 --- /dev/null +++ b/test/fixtures/java/corpus/try.java @@ -0,0 +1,9 @@ +public class Bar { + public void foo() { + try { + System.out.println(1/0); + } catch (Exception e) { + e.printStackTrace(System.out); + } + } +} diff --git a/test/fixtures/java/corpus/try_with_resources.java b/test/fixtures/java/corpus/try_with_resources.java new file mode 100644 index 000000000..8d7536b9e --- /dev/null +++ b/test/fixtures/java/corpus/try_with_resources.java @@ -0,0 +1,9 @@ +public class Bar { + public void foo() { + try (BufferedReader br = new BufferedReader()) { + System.out.println(1/0); + } catch (Exception e) { + e.printStackTrace(System.out); + } + } +}