diff --git a/javalang/parser.py b/javalang/parser.py index fb8623e..9fe8931 100644 --- a/javalang/parser.py +++ b/javalang/parser.py @@ -397,6 +397,7 @@ def parse_normal_class_declaration(self): type_parameters=type_params, extends=extends, implements=implements, + end_position=self.tokens.last().position, body=body) @parse_debug @@ -890,6 +891,7 @@ def parse_method_declarator_rest(self): return tree.MethodDeclaration(parameters=formal_parameters, throws=throws, body=body, + end_position=self.tokens.last().position, return_type=tree.Type(dimensions=additional_dimensions)) @parse_debug @@ -908,7 +910,8 @@ def parse_void_method_declarator_rest(self): return tree.MethodDeclaration(parameters=formal_parameters, throws=throws, - body=body) + body=body, + end_position=self.tokens.last().position) @parse_debug def parse_constructor_declarator_rest(self): @@ -923,6 +926,7 @@ def parse_constructor_declarator_rest(self): return tree.ConstructorDeclaration(parameters=formal_parameters, throws=throws, + end_position=self.tokens.last().position, body=body) @parse_debug @@ -1086,6 +1090,7 @@ def parse_interface_method_declarator_rest(self): return tree.MethodDeclaration(parameters=parameters, throws=throws, body=body, + end_position=self.tokens.last().position, return_type=tree.Type(dimensions=array_dimension)) @parse_debug @@ -1104,7 +1109,8 @@ def parse_void_interface_method_declarator_rest(self): return tree.MethodDeclaration(parameters=parameters, throws=throws, - body=body) + body=body, + end_position=self.tokens.last().position) @parse_debug def parse_interface_generic_method_declarator(self): @@ -1533,6 +1539,7 @@ def parse_statement(self): statement = tree.TryStatement(resources=resource_specification, block=block, catches=catches, + end_position=self.tokens.last().position, finally_block=finally_block) statement._position = token.position return statement @@ -1579,7 +1586,11 @@ def parse_catch_clause(self): self.accept(')') block = self.parse_block() - return tree.CatchClause(parameter=catch_parameter, block=block) + return tree.CatchClause( + parameter=catch_parameter, + block=block, + end_position=self.tokens.last().position, + ) @parse_debug def parse_resource_specification(self): diff --git a/javalang/tree.py b/javalang/tree.py index 77e7a37..5ca8adb 100644 --- a/javalang/tree.py +++ b/javalang/tree.py @@ -34,7 +34,8 @@ class PackageDeclaration(Declaration, Documented): attrs = ("name",) class ClassDeclaration(TypeDeclaration): - attrs = ("type_parameters", "extends", "implements") + attrs = ("type_parameters", "extends", "implements", "end_position") + class EnumDeclaration(TypeDeclaration): attrs = ("implements",) @@ -89,13 +90,15 @@ class Member(Documented): attrs = () class MethodDeclaration(Member, Declaration): - attrs = ("type_parameters", "return_type", "name", "parameters", "throws", "body") + attrs = ("type_parameters", "return_type", "name", "parameters", "throws", "body", + "end_position") class FieldDeclaration(Member, Declaration): attrs = ("type", "declarators") class ConstructorDeclaration(Declaration, Documented): - attrs = ("type_parameters", "name", "parameters", "throws", "body") + attrs = ("type_parameters", "name", "parameters", "throws", "body", + "end_position") # ------------------------------------------------------------------------------ @@ -156,7 +159,7 @@ class SynchronizedStatement(Statement): attrs = ("lock", "block") class TryStatement(Statement): - attrs = ("resources", "block", "catches", "finally_block") + attrs = ("resources", "block", "catches", "finally_block", "end_position") class SwitchStatement(Statement): attrs = ("expression", "cases") @@ -173,7 +176,7 @@ class TryResource(Declaration): attrs = ("type", "name", "value") class CatchClause(Statement): - attrs = ("parameter", "block") + attrs = ("parameter", "block", "end_position") class CatchClauseParameter(Declaration): attrs = ("types", "name")