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

Function java_process_class_decl

internal/cbm/lsp/java_lsp.c:1653–1725  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1651}
1652
1653static void java_process_class_decl(JavaLSPContext *ctx, TSNode node) {
1654 TSNode name_node = ts_node_child_by_field_name(node, "name", 4);
1655 if (ts_node_is_null(name_node))
1656 return;
1657 char *cname = java_node_text(ctx, name_node);
1658 if (!cname)
1659 return;
1660
1661 /* Class QN. Outer.Inner naming: walk the enclosing-class stack. */
1662 char *class_qn;
1663 if (ctx->enclosing_class_qn) {
1664 class_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->enclosing_class_qn, cname);
1665 } else if (ctx->module_qn && ctx->module_qn[0]) {
1666 class_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->module_qn, cname);
1667 } else {
1668 class_qn = cbm_arena_strdup(ctx->arena, cname);
1669 }
1670
1671 const char *super_qn = class_super_qn(ctx, node);
1672 if (!super_qn)
1673 super_qn = "java.lang.Object";
1674
1675 /* Save context. */
1676 const char *saved_class = ctx->enclosing_class_qn;
1677 const char *saved_super = ctx->enclosing_super_qn;
1678 const char *saved_short = ctx->enclosing_class_short;
1679
1680 push_enclosing_class(ctx, class_qn);
1681 ctx->enclosing_class_qn = class_qn;
1682 ctx->enclosing_super_qn = super_qn;
1683 ctx->enclosing_class_short = cname;
1684
1685 TSNode body = java_type_declaration_body(node);
1686 if (!ts_node_is_null(body)) {
1687 CBMScope *saved_scope = ctx->current_scope;
1688 ctx->current_scope = cbm_scope_push(ctx->arena, saved_scope);
1689
1690 /* First pass: bind fields so methods see them. */
1691 uint32_t n = ts_node_named_child_count(body);
1692 for (uint32_t i = 0; i < n; i++) {
1693 TSNode c = ts_node_named_child(body, i);
1694 const char *k = ts_node_type(c);
1695 if (strcmp(k, "field_declaration") == 0)
1696 process_field_decl(ctx, c);
1697 }
1698 /* Second pass: methods + constructors + nested types. */
1699 for (uint32_t i = 0; i < n; i++) {
1700 TSNode c = ts_node_named_child(body, i);
1701 const char *k = ts_node_type(c);
1702 if (strcmp(k, "method_declaration") == 0) {
1703 process_method_decl(ctx, c, class_qn, super_qn);
1704 } else if (strcmp(k, "constructor_declaration") == 0) {
1705 process_constructor_decl(ctx, c, class_qn, super_qn);
1706 } else if (strcmp(k, "class_declaration") == 0 ||
1707 strcmp(k, "interface_declaration") == 0 ||
1708 strcmp(k, "enum_declaration") == 0 || strcmp(k, "record_declaration") == 0 ||
1709 strcmp(k, "annotation_type_declaration") == 0) {
1710 java_process_class_decl(ctx, c);

Callers 1

java_lsp_process_fileFunction · 0.85

Calls 12

java_node_textFunction · 0.85
class_super_qnFunction · 0.85
push_enclosing_classFunction · 0.85
cbm_scope_pushFunction · 0.85
process_field_declFunction · 0.85
process_method_declFunction · 0.85
process_constructor_declFunction · 0.85
process_blockFunction · 0.85
pop_enclosing_classFunction · 0.85
cbm_arena_sprintfFunction · 0.50
cbm_arena_strdupFunction · 0.50

Tested by

no test coverage detected