c2nes / javalang

Pure Python Java parser and tools
MIT License
736 stars 161 forks source link

Javalang can not parse interfaces with a body. #30

Closed roipoussiere closed 8 years ago

roipoussiere commented 8 years ago

For these simple Java8 codes:

    public interface Test{ default int foo() {return 0;} }

and

    public interface Test{ default void foo() {} }

Javalang throws a Syntax error:

import javalang
javalang.parse.parse("public interface Test{ default int foo() {return 0;} }")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/javalang/parse.py", line 53, in parse
    return parser.parse()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 110, in parse
    return self.parse_compilation_unit()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 296, in parse_compilation_unit
    type_declaration = self.parse_type_declaration()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 341, in parse_type_declaration
    return self.parse_class_or_interface_declaration()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 354, in parse_class_or_interface_declaration
    type_declaration = self.parse_normal_interface_declaration()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 429, in parse_normal_interface_declaration
    body = self.parse_interface_body()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 945, in parse_interface_body
    declaration = self.parse_interface_body_declaration()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 960, in parse_interface_body_declaration
    declaration = self.parse_interface_member_declaration()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 986, in parse_interface_member_declaration
    declaration = self.parse_interface_method_or_field_declaration()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 994, in parse_interface_method_or_field_declaration
    member = self.parse_interface_method_or_field_rest()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 1011, in parse_interface_method_or_field_rest
    rest = self.parse_interface_method_declarator_rest()
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 1056, in parse_interface_method_declarator_rest
    self.accept(';')
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 131, in accept
    self.illegal("Expected '%s'" % (accept,))
  File "/usr/local/lib/python3.5/dist-packages/javalang/parser.py", line 119, in illegal
    raise JavaSyntaxError(description, at)
javalang.parser.JavaSyntaxError

Related to #29.