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