Try to extract method name from a node, with language-specific fallbacks.
| 4580 | |
| 4581 | // Try to extract method name from a node, with language-specific fallbacks. |
| 4582 | static TSNode resolve_method_name(TSNode child, CBMLanguage lang) { |
| 4583 | TSNode name_node = func_name_node(child); |
| 4584 | if (!ts_node_is_null(name_node)) { |
| 4585 | return name_node; |
| 4586 | } |
| 4587 | |
| 4588 | const char *ck = ts_node_type(child); |
| 4589 | |
| 4590 | if ((lang == CBM_LANG_C || lang == CBM_LANG_CPP || lang == CBM_LANG_CUDA || |
| 4591 | lang == CBM_LANG_GLSL) && |
| 4592 | strcmp(ck, "function_definition") == 0) { |
| 4593 | return cbm_resolve_func_name(child, lang); |
| 4594 | } |
| 4595 | |
| 4596 | if (lang == CBM_LANG_GROOVY && strcmp(ck, "function_definition") == 0) { |
| 4597 | TSNode fn = ts_node_child_by_field_name(child, TS_FIELD("function")); |
| 4598 | if (!ts_node_is_null(fn)) { |
| 4599 | return fn; |
| 4600 | } |
| 4601 | return cbm_find_child_by_kind(child, "identifier"); |
| 4602 | } |
| 4603 | |
| 4604 | if (lang == CBM_LANG_DART) { |
| 4605 | return resolve_dart_method_name(child, ck); |
| 4606 | } |
| 4607 | |
| 4608 | if (lang == CBM_LANG_OBJC && strcmp(ck, "method_definition") == 0) { |
| 4609 | return cbm_find_child_by_kind(child, "identifier"); |
| 4610 | } |
| 4611 | |
| 4612 | // Pony: `fun`/`be`/`new` members are `method`/`constructor`/`ffi_method` |
| 4613 | // nodes with no `name` field; the name is the first plain `identifier` child |
| 4614 | // (mirrors the free-function case in cbm_resolve_func_name). |
| 4615 | if (lang == CBM_LANG_PONY && (strcmp(ck, "method") == 0 || strcmp(ck, "constructor") == 0 || |
| 4616 | strcmp(ck, "ffi_method") == 0)) { |
| 4617 | return cbm_find_child_by_kind(child, "identifier"); |
| 4618 | } |
| 4619 | |
| 4620 | if ((lang == CBM_LANG_SWIFT || lang == CBM_LANG_KOTLIN) && |
| 4621 | strcmp(ck, "function_declaration") == 0) { |
| 4622 | return cbm_find_child_by_kind(child, "simple_identifier"); |
| 4623 | } |
| 4624 | |
| 4625 | // Squirrel: function_declaration's name is a plain `identifier` child. |
| 4626 | if (lang == CBM_LANG_SQUIRREL && strcmp(ck, "function_declaration") == 0) { |
| 4627 | return cbm_find_child_by_kind(child, "identifier"); |
| 4628 | } |
| 4629 | |
| 4630 | // ObjectScript method/classmethod: name under method_definition->method_name. |
| 4631 | if (lang == CBM_LANG_OBJECTSCRIPT_UDL && |
| 4632 | (strcmp(ck, "method") == 0 || strcmp(ck, "classmethod") == 0)) { |
| 4633 | TSNode mdef = cbm_find_child_by_kind(child, "method_definition"); |
| 4634 | if (!ts_node_is_null(mdef)) { |
| 4635 | TSNode mname = cbm_find_child_by_kind(mdef, "method_name"); |
| 4636 | if (!ts_node_is_null(mname) && ts_node_named_child_count(mname) > 0) { |
| 4637 | return ts_node_named_child(mname, 0); |
| 4638 | } |
| 4639 | } |
no test coverage detected