github / semantic

Parsing, analyzing, and comparing source code across many languages
8.97k stars 452 forks source link

Lack of support of throws syntax in Java #612

Closed hezyin closed 4 years ago

hezyin commented 4 years ago

Hi team, it seems release 0.7.0.0 doesn't support throws syntax in Java. I've tested the minimal example below in tree-sitter's playground and verified it's not an upstream issue. Please let me know if you need any more info on this. Thanks!

Tested in version 0.7.0.0

Minimal Example to Reproduce

Source Code

public class Main {
    static void methodThrowsException() throws Exception {
        doSomething();
    }
}

Error Message (Tested in version 0.7.0.0)

 ~  semantic parse --json example.java                                                                                        
[17:30:50]  WARN {"trees":[{"tree":{"term":"Statements","statements":[{"term":"Class","classBody":{"children":[{"term":"Error","errorActual":"Throws","errorCallStack":[],"errorChildren":[],"errorExpected":[],"sourceRange":[25,108],"sourceSpan":{"start":[3,5],"end":[5,6]}}],"sourceRange":[18,111],"sourceSpan":{"start":[1,19],"end":[7,2]}},"classContext":[{"term":"AccessibilityModifier","contents":"public","sourceRange":[0,6],"sourceSpan":{"start":[1,1],"end":[1,7]}}],"classIdentifier":{"term":"Identifier","name":"Main","sourceRange":[13,17],"sourceSpan":{"start":[1,14],"end":[1,18]}},"classSuperclasses":[],"sourceRange":[0,111],"sourceSpan":{"start":[1,1],"end":[7,2]}}],"sourceRange":[0,112],"sourceSpan":{"start":[1,1],"end":[8,1]}},"path":"mvp.java","language":"Java"}]}
mvp.java:3:5-5:6: error: expected end of input nodes, but got Throws
1: public class Main {
2:
3:     static void methodThrowsException() throws Exception {
       ^...

 task=assign github_request_id=- github_is_public=False path=mvp.java language=Java
patrickt commented 4 years ago

Thanks for your report! The --json command line switch goes through the old a-la-carte syntax; try --json-symbols instead, which goes through the precise syntax. I’ve confirmed that the above works in master as of this writing, so I’m going to close this out, but please leave a comment if --json-symbols doesn’t work for you. (N.B. master has removed the --json switch in favor of --json-symbols, so hopefully few people encounter this going forward.)