MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / resolve_method_name

Function resolve_method_name

internal/cbm/extract_defs.c:8289–8360  ·  view source on GitHub ↗

Try to extract method name from a node, with language-specific fallbacks.

Source from the content-addressed store, hash-verified

8287
8288// Try to extract method name from a node, with language-specific fallbacks.
8289static TSNode resolve_method_name(TSNode child, CBMLanguage lang) {
8290 TSNode name_node = func_name_node(child);
8291 if (!ts_node_is_null(name_node)) {
8292 return name_node;
8293 }
8294
8295 const char *ck = ts_node_type(child);
8296
8297 if ((lang == CBM_LANG_C || lang == CBM_LANG_CPP || lang == CBM_LANG_CUDA ||
8298 lang == CBM_LANG_GLSL) &&
8299 strcmp(ck, "function_definition") == 0) {
8300 return cbm_resolve_func_name(child, lang);
8301 }
8302
8303 if (lang == CBM_LANG_GROOVY && strcmp(ck, "function_definition") == 0) {
8304 TSNode fn = ts_node_child_by_field_name(child, TS_FIELD("function"));
8305 if (!ts_node_is_null(fn)) {
8306 return fn;
8307 }
8308 return cbm_find_child_by_kind(child, "identifier");
8309 }
8310
8311 if (lang == CBM_LANG_DART) {
8312 return resolve_dart_method_name(child, ck);
8313 }
8314
8315 if (lang == CBM_LANG_OBJC && strcmp(ck, "method_definition") == 0) {
8316 return cbm_find_child_by_kind(child, "identifier");
8317 }
8318
8319 // Pony: `fun`/`be`/`new` members are `method`/`constructor`/`ffi_method`
8320 // nodes with no `name` field; the name is the first plain `identifier` child
8321 // (mirrors the free-function case in cbm_resolve_func_name).
8322 if (lang == CBM_LANG_PONY && (strcmp(ck, "method") == 0 || strcmp(ck, "constructor") == 0 ||
8323 strcmp(ck, "ffi_method") == 0)) {
8324 return cbm_find_child_by_kind(child, "identifier");
8325 }
8326
8327 if ((lang == CBM_LANG_SWIFT || lang == CBM_LANG_KOTLIN) &&
8328 (strcmp(ck, "function_declaration") == 0 ||
8329 strcmp(ck, "protocol_function_declaration") == 0)) {
8330 return cbm_find_child_by_kind(child, "simple_identifier");
8331 }
8332
8333 // Squirrel: function_declaration's name is a plain `identifier` child.
8334 if (lang == CBM_LANG_SQUIRREL && strcmp(ck, "function_declaration") == 0) {
8335 return cbm_find_child_by_kind(child, "identifier");
8336 }
8337
8338 // ObjectScript method/classmethod: name under method_definition->method_name.
8339 if (lang == CBM_LANG_OBJECTSCRIPT_UDL &&
8340 (strcmp(ck, "method") == 0 || strcmp(ck, "classmethod") == 0)) {
8341 TSNode mdef = cbm_find_child_by_kind(child, "method_definition");
8342 if (!ts_node_is_null(mdef)) {
8343 TSNode mname = cbm_find_child_by_kind(mdef, "method_name");
8344 if (!ts_node_is_null(mname) && ts_node_named_child_count(mname) > 0) {
8345 return ts_node_named_child(mname, 0);
8346 }

Callers 2

extract_class_methodsFunction · 0.85

Calls 5

func_name_nodeFunction · 0.85
cbm_resolve_func_nameFunction · 0.85
cbm_find_child_by_kindFunction · 0.85
resolve_dart_method_nameFunction · 0.85
resolve_arrow_func_nameFunction · 0.85

Tested by

no test coverage detected