Why does Javalang gives error when calling parse.member_declaration method
Opened this issue · 2 comments
Thirunayan22 commented
When I call the parser.parse_member_declaration on a tokenized source code containing import statements Javalang is giving the below error.
Java code
import java.util.*;class Test { public static void main(String[] args){ int x=3; if(x>2){System.out.println('Hola');} } }
What is the cause of this error?
Thirunayan22 commented
c2nes commented
Try parse_compilation_unit()
instead.
Imports statements are only allowed in a "compilation unit" which is what a complete .java
file corresponds to. A "member declaration" is a declaration within a class (e.g. a field, method, or nested type). Since import statements are not allowed within class/interface/enum declarations you are receiving a syntax error.