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

Function patch_one_method

internal/cbm/lsp/java_lsp.c:3423–3510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3421 TSNode class_node, const char *enclosing_class_qn);
3422
3423static void patch_one_method(JavaLSPContext *ctx, CBMTypeRegistry *reg, TSNode method_node,
3424 const char *class_qn, bool is_constructor) {
3425 TSNode name_node = ts_node_child_by_field_name(method_node, "name", 4);
3426 if (ts_node_is_null(name_node))
3427 return;
3428 char *mname = java_node_text(ctx, name_node);
3429 if (!mname)
3430 return;
3431 char *method_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", class_qn, mname);
3432
3433 /* Re-extract param types from the AST. */
3434 TSNode params = ts_node_child_by_field_name(method_node, "parameters", 10);
3435 if (ts_node_is_null(params))
3436 return;
3437 uint32_t pn = ts_node_named_child_count(params);
3438 const CBMType **ptypes = NULL;
3439 if (pn > 0) {
3440 ptypes = (const CBMType **)cbm_arena_alloc(ctx->arena, (size_t)(pn + 1) * sizeof(*ptypes));
3441 if (!ptypes)
3442 return;
3443 }
3444 int idx = 0;
3445 for (uint32_t i = 0; i < pn; i++) {
3446 TSNode p = ts_node_named_child(params, i);
3447 const char *pk = ts_node_type(p);
3448 if (strcmp(pk, "formal_parameter") != 0 && strcmp(pk, "spread_parameter") != 0) {
3449 continue;
3450 }
3451 TSNode ptype = ts_node_child_by_field_name(p, "type", 4);
3452 const CBMType *pt = cbm_type_unknown();
3453 if (!ts_node_is_null(ptype))
3454 pt = java_parse_type_node(ctx, ptype);
3455 if (strcmp(pk, "spread_parameter") == 0 && pt) {
3456 pt = cbm_type_slice(ctx->arena, pt);
3457 }
3458 ptypes[idx++] = pt;
3459 }
3460 if (ptypes)
3461 ptypes[idx] = NULL;
3462
3463 /* Java overloads share a graph QN. Select the registry slot whose counted
3464 * signature has the same arity as this AST declaration; falling back to the
3465 * first QN match keeps the legacy no-signature path best-effort. */
3466 CBMRegisteredFunc *slot = NULL;
3467 CBMRegisteredFunc *first_qn_match = NULL;
3468 for (int fi = 0; fi < reg->func_count; fi++) {
3469 CBMRegisteredFunc *candidate = &reg->funcs[fi];
3470 if (!candidate->qualified_name || strcmp(candidate->qualified_name, method_qn) != 0)
3471 continue;
3472 if (!first_qn_match)
3473 first_qn_match = candidate;
3474 if (!candidate->signature || candidate->signature->kind != CBM_TYPE_FUNC)
3475 continue;
3476 int candidate_arity = 0;
3477 const CBMType *const *candidate_params = candidate->signature->data.func.param_types;
3478 if (candidate_params) {
3479 while (candidate_params[candidate_arity])
3480 candidate_arity++;

Callers 1

Calls 8

java_node_textFunction · 0.85
cbm_type_unknownFunction · 0.85
java_parse_type_nodeFunction · 0.85
cbm_type_sliceFunction · 0.85
cbm_type_namedFunction · 0.85
cbm_type_funcFunction · 0.85
cbm_arena_sprintfFunction · 0.50
cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected