| 1633 | } |
| 1634 | |
| 1635 | static void java_process_class_decl(JavaLSPContext *ctx, TSNode node) { |
| 1636 | TSNode name_node = ts_node_child_by_field_name(node, "name", 4); |
| 1637 | if (ts_node_is_null(name_node)) |
| 1638 | return; |
| 1639 | char *cname = java_node_text(ctx, name_node); |
| 1640 | if (!cname) |
| 1641 | return; |
| 1642 | |
| 1643 | /* Class QN. Outer.Inner naming: walk the enclosing-class stack. */ |
| 1644 | char *class_qn; |
| 1645 | if (ctx->enclosing_class_qn) { |
| 1646 | class_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->enclosing_class_qn, cname); |
| 1647 | } else if (ctx->module_qn && ctx->module_qn[0]) { |
| 1648 | class_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->module_qn, cname); |
| 1649 | } else { |
| 1650 | class_qn = cbm_arena_strdup(ctx->arena, cname); |
| 1651 | } |
| 1652 | |
| 1653 | const char *super_qn = class_super_qn(ctx, node); |
| 1654 | if (!super_qn) |
| 1655 | super_qn = "java.lang.Object"; |
| 1656 | |
| 1657 | /* Save context. */ |
| 1658 | const char *saved_class = ctx->enclosing_class_qn; |
| 1659 | const char *saved_super = ctx->enclosing_super_qn; |
| 1660 | const char *saved_short = ctx->enclosing_class_short; |
| 1661 | |
| 1662 | push_enclosing_class(ctx, class_qn); |
| 1663 | ctx->enclosing_class_qn = class_qn; |
| 1664 | ctx->enclosing_super_qn = super_qn; |
| 1665 | ctx->enclosing_class_short = cname; |
| 1666 | |
| 1667 | TSNode body = ts_node_child_by_field_name(node, "body", 4); |
| 1668 | if (!ts_node_is_null(body)) { |
| 1669 | CBMScope *saved_scope = ctx->current_scope; |
| 1670 | ctx->current_scope = cbm_scope_push(ctx->arena, saved_scope); |
| 1671 | |
| 1672 | /* First pass: bind fields so methods see them. */ |
| 1673 | uint32_t n = ts_node_named_child_count(body); |
| 1674 | for (uint32_t i = 0; i < n; i++) { |
| 1675 | TSNode c = ts_node_named_child(body, i); |
| 1676 | const char *k = ts_node_type(c); |
| 1677 | if (strcmp(k, "field_declaration") == 0) |
| 1678 | process_field_decl(ctx, c); |
| 1679 | } |
| 1680 | /* Second pass: methods + constructors + nested types. */ |
| 1681 | for (uint32_t i = 0; i < n; i++) { |
| 1682 | TSNode c = ts_node_named_child(body, i); |
| 1683 | const char *k = ts_node_type(c); |
| 1684 | if (strcmp(k, "method_declaration") == 0) { |
| 1685 | process_method_decl(ctx, c, class_qn, super_qn); |
| 1686 | } else if (strcmp(k, "constructor_declaration") == 0) { |
| 1687 | process_constructor_decl(ctx, c, class_qn, super_qn); |
| 1688 | } else if (strcmp(k, "class_declaration") == 0 || |
| 1689 | strcmp(k, "interface_declaration") == 0 || |
| 1690 | strcmp(k, "enum_declaration") == 0 || strcmp(k, "record_declaration") == 0 || |
| 1691 | strcmp(k, "annotation_type_declaration") == 0) { |
| 1692 | java_process_class_decl(ctx, c); |
no test coverage detected