Skip to content

Added class end position, constructor end position (also includes previous PR of method end position) #131

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 6 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
17 changes: 14 additions & 3 deletions javalang/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 8 additions & 5 deletions javalang/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)
Expand Down Expand Up @@ -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")

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down