Push a single method definition
| 4086 | |
| 4087 | // Push a single method definition |
| 4088 | static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node, |
| 4089 | const char *class_qn, const CBMLangSpec *spec, TSNode name_node) { |
| 4090 | CBMArena *a = ctx->arena; |
| 4091 | |
| 4092 | char *name = cbm_func_name_node_text(a, name_node, ctx->source); |
| 4093 | if (!name || !name[0]) { |
| 4094 | return; |
| 4095 | } |
| 4096 | |
| 4097 | const char *method_qn = cbm_arena_sprintf(a, "%s.%s", class_qn, name); |
| 4098 | |
| 4099 | CBMDefinition def; |
| 4100 | memset(&def, 0, sizeof(def)); |
| 4101 | def.name = name; |
| 4102 | def.qualified_name = method_qn; |
| 4103 | def.label = "Method"; |
| 4104 | def.file_path = ctx->rel_path; |
| 4105 | def.parent_class = class_qn; |
| 4106 | def.start_line = ts_node_start_point(child).row + TS_LINE_OFFSET; |
| 4107 | def.end_line = ts_node_end_point(child).row + TS_LINE_OFFSET; |
| 4108 | def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET); |
| 4109 | def.is_exported = cbm_is_exported(name, ctx->language); |
| 4110 | |
| 4111 | TSNode params = ts_node_child_by_field_name(child, TS_FIELD("parameters")); |
| 4112 | if (!ts_node_is_null(params)) { |
| 4113 | def.signature = cbm_node_text(a, params, ctx->source); |
| 4114 | def.param_types = extract_param_types(a, params, ctx->source, ctx->language); |
| 4115 | } |
| 4116 | |
| 4117 | // Return type (same fields as extract_func_def) |
| 4118 | { |
| 4119 | static const char *rt_fields[] = {"result", "return_type", "type", NULL}; |
| 4120 | for (const char **f = rt_fields; *f; f++) { |
| 4121 | TSNode rt = ts_node_child_by_field_name(child, *f, (uint32_t)strlen(*f)); |
| 4122 | if (!ts_node_is_null(rt)) { |
| 4123 | def.return_type = cbm_node_text(a, rt, ctx->source); |
| 4124 | break; |
| 4125 | } |
| 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | // C++: trailing return type (auto method() -> Type) |
| 4130 | if (def.return_type && strcmp(def.return_type, "auto") == 0 && |
| 4131 | (ctx->language == CBM_LANG_CPP || ctx->language == CBM_LANG_CUDA)) { |
| 4132 | resolve_cpp_trailing_return(a, child, ctx->source, &def); |
| 4133 | } |
| 4134 | |
| 4135 | def.decorators = extract_decorators(a, child, ctx->source, ctx->language, spec); |
| 4136 | extract_route_from_decorators(a, child, ctx->source, spec, &def.route_path, &def.route_method); |
| 4137 | if (def.route_path && (ctx->language == CBM_LANG_JAVA || ctx->language == CBM_LANG_KOTLIN)) { |
| 4138 | const char *prefix = spring_class_route_prefix(a, class_node, ctx->source, spec); |
| 4139 | def.route_path = join_route_paths(a, prefix, def.route_path); |
| 4140 | } |
| 4141 | def.docstring = extract_docstring(a, child, ctx->source, ctx->language); |
| 4142 | |
| 4143 | if (spec->branching_node_types && spec->branching_node_types[0]) { |
| 4144 | set_def_complexity(&def, child, spec); |
| 4145 | } |
no test coverage detected