Given a node, return function name and function range (start & end lineno)
(func_node)
| 7 | |
| 8 | |
| 9 | def handle_function(func_node): |
| 10 | """Given a <function> node, |
| 11 | return function name and function range (start & end lineno)""" |
| 12 | |
| 13 | name_node = func_node.find('srcml:name', ns) |
| 14 | func_name, start_line = handle_name(name_node) |
| 15 | if not func_name or not start_line: |
| 16 | print('Function name/start not found!') # very unlikely to happen |
| 17 | return None, None, None |
| 18 | |
| 19 | block_node = func_node.find('srcml:block', ns) |
| 20 | if block_node is None: |
| 21 | try: |
| 22 | block_node = func_node.xpath('./following-sibling::srcml:block', |
| 23 | namespaces=ns)[0] |
| 24 | except: |
| 25 | print("Block node not found (in func {})".format(func_name)) |
| 26 | return func_name, None, None |
| 27 | try: |
| 28 | pos_node = block_node.find('pos:position', ns) |
| 29 | end_line = int(pos_node.attrib[line_attr]) |
| 30 | except: |
| 31 | print("Block node doesn't have position node inside!") |
| 32 | return func_name, None, None |
| 33 | |
| 34 | return func_name, start_line, end_line |
| 35 | |
| 36 | |
| 37 | def handle_name(name_node): |
no test coverage detected