Skip to content

Commit b6a5973

Browse files
authored
Merge pull request #1 from FSoft-AI4Code/feature/return_type
Feature/return type
2 parents 5cfa947 + 2f87bd6 commit b6a5973

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/codetext/parser/c_sharp_parser.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,13 @@ def get_class_list(node):
105105
return res
106106

107107
@staticmethod
108-
def get_function_metadata(function_node, blob: str=None) -> Dict[str, Any]:
108+
def get_function_metadata(function_node, blob: str = None) -> Dict[str, Any]:
109109
"""
110110
Function metadata contains:
111111
- identifier (str): function name
112112
- parameters (Dict[str, str]): parameter's name and their type (e.g: {'param_a': 'int'})
113113
- type (str): type
114114
"""
115-
if blob:
116-
logger.info('From version `0.0.6` this function will update argument in the API')
117115
metadata = {
118116
'identifier': '',
119117
'parameters': {},
@@ -122,10 +120,13 @@ def get_function_metadata(function_node, blob: str=None) -> Dict[str, Any]:
122120
assert type(function_node) == tree_sitter.Node
123121

124122
for child in function_node.children:
125-
if child.type == 'predefined_type':
123+
if child.type in ['predefined_type', 'generic_name']:
126124
metadata['return_type'] = get_node_text(child)
127125
elif child.type == 'identifier':
128-
metadata['identifier'] = get_node_text(child)
126+
if child.next_named_sibling.type != 'parameter_list':
127+
metadata['return_type'] = get_node_text(child)
128+
else:
129+
metadata['identifier'] = get_node_text(child)
129130
elif child.type == 'parameter_list':
130131
for param_node in child.children:
131132
param_nodes = get_node_by_kind(param_node, ['parameter'])

src/codetext/parser/java_parser.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,26 @@ def get_class_metadata(class_node, blob: str=None) -> Dict[str, str]:
103103
return metadata
104104

105105
@staticmethod
106-
def get_function_metadata(function_node, blob: str=None) -> Dict[str, str]:
107-
if blob:
108-
logger.info('From version `0.0.6` this function will update argument in the API')
106+
def get_function_metadata(function_node, blob: str = None) -> Dict[str, str]:
109107
metadata = {
110108
'identifier': '',
111109
'parameters': {},
112110
'return_type': None
113111
}
114112

113+
return_kinds = ["void_type",
114+
"integral_type",
115+
"floating_point_type",
116+
"boolean_type",
117+
"type_identifier",
118+
"scoped_type_identifier",
119+
"generic_type"]
120+
121+
115122
for child in function_node.children:
116123
if child.type == 'identifier':
117-
metadata['identifier'] = get_node_text(child)
118-
elif child.type == 'type_identifier':
124+
metadata['identifier'] = get_node_text(child)
125+
elif child.type in return_kinds:
119126
metadata['return_type'] = get_node_text(child)
120127
elif child.type == 'formal_parameters':
121128
param_list = get_node_by_kind(child, ['formal_parameter']) # speed_parameter
@@ -124,4 +131,5 @@ def get_function_metadata(function_node, blob: str=None) -> Dict[str, str]:
124131
identifier = get_node_text(param.child_by_field_name('name'))
125132
metadata['parameters'][identifier] = param_type
126133

127-
return metadata
134+
135+
return metadata

0 commit comments

Comments
 (0)