Skip to content

Implement end_position for MethodDeclaration() #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions javalang/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,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
Expand All @@ -908,7 +909,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):
Expand Down Expand Up @@ -1086,6 +1088,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
Expand All @@ -1104,7 +1107,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):
Expand Down Expand Up @@ -1533,6 +1537,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
Expand Down Expand Up @@ -1579,7 +1584,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):
Expand Down
7 changes: 4 additions & 3 deletions javalang/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ 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")
Expand Down Expand Up @@ -156,7 +157,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")
Expand All @@ -173,7 +174,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")
Expand Down