mirror of
https://github.com/github/semantic.git
synced 2025-01-08 08:30:27 +03:00
Merge pull request #238 from github/fix-try-catch-error
Assignment error in Java try/catch blocks (#235)
This commit is contained in:
commit
a9365c667c
@ -452,16 +452,19 @@ throw :: Assignment Term
|
|||||||
throw = makeTerm <$> symbol ThrowStatement <*> children (Statement.Throw <$> term expression)
|
throw = makeTerm <$> symbol ThrowStatement <*> children (Statement.Throw <$> term expression)
|
||||||
|
|
||||||
try :: Assignment Term
|
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 :: Assignment [Term]
|
||||||
catches = symbol Catches *> children (manyTerm catch)
|
catches = symbol Catches *> children (manyTerm catch)
|
||||||
where
|
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)
|
catchFormalParameter = makeTerm <$> symbol CatchFormalParameter <*> children (flip Type.Annotation <$> catchType <* symbol VariableDeclaratorId <*> children identifier)
|
||||||
|
|
||||||
catchType :: Assignment Term
|
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 :: Assignment Term
|
||||||
finally = makeTerm <$> symbol Finally <*> children (Statement.Finally <$> term expression)
|
finally = makeTerm <$> symbol Finally <*> children (Statement.Finally <$> term expression)
|
||||||
|
9
test/fixtures/java/corpus/try.java
vendored
Normal file
9
test/fixtures/java/corpus/try.java
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
public class Bar {
|
||||||
|
public void foo() {
|
||||||
|
try {
|
||||||
|
System.out.println(1/0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
test/fixtures/java/corpus/try_with_resources.java
vendored
Normal file
9
test/fixtures/java/corpus/try_with_resources.java
vendored
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user