MCPcopy
hub / github.com/tirth8205/code-review-graph / _get_name

Method _get_name

code_review_graph/parser.py:5714–5999  ·  view source on GitHub ↗

Extract the name from a class/function definition node.

(self, node, language: str, kind: str)

Source from the content-addressed store, hash-verified

5712 return f"{file_path}::{name}"
5713
5714 def _get_name(self, node, language: str, kind: str) -> Optional[str]:
5715 """Extract the name from a class/function definition node."""
5716 # Dart: function_signature has a return-type node before the identifier;
5717 # search only for 'identifier' to avoid returning the return type name.
5718 if language == "dart" and node.type == "function_signature":
5719 for child in node.children:
5720 if child.type == "identifier":
5721 return child.text.decode("utf-8", errors="replace")
5722 return None
5723 # Solidity: constructor and receive/fallback have no identifier child
5724 if language == "solidity":
5725 if node.type == "constructor_definition":
5726 return "constructor"
5727 if node.type == "fallback_receive_definition":
5728 for child in node.children:
5729 if child.type in ("receive", "fallback"):
5730 return child.text.decode("utf-8", errors="replace")
5731 # Lua/Luau: function_declaration names may be dot_index_expression or
5732 # method_index_expression (e.g. function Animal.new() / Animal:speak()).
5733 # Return only the method name; the table name is used as parent_name
5734 # in _extract_lua_constructs.
5735 if language in ("lua", "luau") and node.type == "function_declaration":
5736 for child in node.children:
5737 if child.type in ("dot_index_expression", "method_index_expression"):
5738 # Last identifier child is the method name
5739 for sub in reversed(child.children):
5740 if sub.type == "identifier":
5741 return sub.text.decode("utf-8", errors="replace")
5742 return None
5743 # Perl: bareword for subroutine names, package for package names
5744 if language == "perl":
5745 for child in node.children:
5746 if child.type == "bareword":
5747 return child.text.decode("utf-8", errors="replace")
5748 if child.type == "package" and child.text != b"package":
5749 return child.text.decode("utf-8", errors="replace")
5750 # Java: method_declaration has return type_identifier before the method
5751 # identifier — skip straight to the first plain identifier child to
5752 # avoid returning the return type as the function name.
5753 if language == "java" and kind == "function" and node.type in (
5754 "method_declaration", "constructor_declaration",
5755 ):
5756 for child in node.children:
5757 if child.type == "identifier":
5758 return child.text.decode("utf-8", errors="replace")
5759 return None
5760
5761 # For C/C++/Objective-C: function names are inside
5762 # function_declarator / pointer_declarator. Check these first to
5763 # avoid matching the return type_identifier as the function name.
5764 if language in ("c", "cpp", "objc") and kind == "function":
5765 for child in node.children:
5766 if child.type in ("function_declarator", "pointer_declarator"):
5767 # Scoped names like Foo::bar use qualified_identifier; take
5768 # the rightmost identifier/field_identifier after the last ::.
5769 for sub in child.children:
5770 if sub.type == "qualified_identifier":
5771 for qsub in reversed(sub.children):

Callers 3

_extract_classesMethod · 0.95
_extract_functionsMethod · 0.95
_collect_file_scopeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected