| 3539 | extern const TSLanguage *tree_sitter_java(void); |
| 3540 | |
| 3541 | void cbm_run_java_lsp(CBMArena *arena, CBMFileResult *result, const char *source, int source_len, |
| 3542 | TSNode root) { |
| 3543 | if (!arena || !result || !source) |
| 3544 | return; |
| 3545 | |
| 3546 | CBMTypeRegistry reg; |
| 3547 | cbm_registry_init(®, arena); |
| 3548 | |
| 3549 | /* Java stdlib — java.lang/util/io/etc. */ |
| 3550 | cbm_java_stdlib_register(®, arena); |
| 3551 | |
| 3552 | /* Module QN comes from the file result. */ |
| 3553 | const char *module_qn = result->module_qn ? result->module_qn : ""; |
| 3554 | |
| 3555 | JavaLSPContext ctx; |
| 3556 | java_lsp_init(&ctx, arena, source, source_len, ®, NULL, module_qn, &result->resolved_calls); |
| 3557 | |
| 3558 | /* Add imports collected by extract_imports.c — they are stored as |
| 3559 | * (local_name, module_path = full Java path). We translate to the LSP |
| 3560 | * import shape here. |
| 3561 | * |
| 3562 | * Note: extract_imports.c can't tell static / on-demand from the AST in |
| 3563 | * a uniform way, so the LSP re-scans the AST for those distinctions in |
| 3564 | * java_lsp_process_file. We still re-emit TYPE imports here so that |
| 3565 | * resolution works even if process_file's import scan misses |
| 3566 | * pre-grammar-version edge cases. */ |
| 3567 | for (int i = 0; i < result->imports.count; i++) { |
| 3568 | CBMImport *imp = &result->imports.items[i]; |
| 3569 | if (!imp->local_name || !imp->module_path) |
| 3570 | continue; |
| 3571 | java_lsp_add_import(&ctx, imp->local_name, imp->module_path, CBM_JAVA_IMPORT_TYPE); |
| 3572 | } |
| 3573 | |
| 3574 | /* Register file-local defs into the registry. */ |
| 3575 | register_local_func_or_type_from_file(&ctx, ®, result); |
| 3576 | |
| 3577 | /* Populate field metadata from the AST so eval_field_access works on |
| 3578 | * receivers other than `this`. Also patch method signatures with |
| 3579 | * generics-preserving types (extract_defs strips generics from |
| 3580 | * d->param_types via clean_type_name). */ |
| 3581 | uint32_t rn = ts_node_named_child_count(root); |
| 3582 | for (uint32_t i = 0; i < rn; i++) { |
| 3583 | TSNode c = ts_node_named_child(root, i); |
| 3584 | const char *ck = ts_node_type(c); |
| 3585 | if (strcmp(ck, "class_declaration") == 0 || strcmp(ck, "interface_declaration") == 0 || |
| 3586 | strcmp(ck, "enum_declaration") == 0 || strcmp(ck, "record_declaration") == 0) { |
| 3587 | populate_class_fields_from_ast(&ctx, ®, c, NULL); |
| 3588 | patch_method_signatures_from_ast(&ctx, ®, c, NULL); |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | /* Walk the file. */ |
| 3593 | java_lsp_process_file(&ctx, root); |
| 3594 | } |
| 3595 | |
| 3596 | /* ── Cross-file LSP ───────────────────────────────────────────────── */ |
| 3597 |
no test coverage detected