| 1725 | } |
| 1726 | |
| 1727 | void java_lsp_process_file(JavaLSPContext *ctx, TSNode root) { |
| 1728 | if (ts_node_is_null(root)) |
| 1729 | return; |
| 1730 | /* First scan: package_declaration + imports (already pushed via init). */ |
| 1731 | uint32_t n = ts_node_named_child_count(root); |
| 1732 | for (uint32_t i = 0; i < n; i++) { |
| 1733 | TSNode c = ts_node_named_child(root, i); |
| 1734 | const char *k = ts_node_type(c); |
| 1735 | if (strcmp(k, "package_declaration") == 0) { |
| 1736 | uint32_t pn = ts_node_named_child_count(c); |
| 1737 | if (pn > 0) { |
| 1738 | TSNode p = ts_node_named_child(c, 0); |
| 1739 | ctx->package_name = java_node_text(ctx, p); |
| 1740 | } |
| 1741 | } else if (strcmp(k, "import_declaration") == 0) { |
| 1742 | /* Flag `static` and on-demand. */ |
| 1743 | bool is_static = false; |
| 1744 | bool is_on_demand = false; |
| 1745 | const char *path = NULL; |
| 1746 | uint32_t cn = ts_node_child_count(c); |
| 1747 | for (uint32_t j = 0; j < cn; j++) { |
| 1748 | TSNode cc = ts_node_child(c, j); |
| 1749 | if (!ts_node_is_named(cc)) { |
| 1750 | char *t = java_node_text(ctx, cc); |
| 1751 | if (t && strcmp(t, "static") == 0) |
| 1752 | is_static = true; |
| 1753 | if (t && strcmp(t, "*") == 0) |
| 1754 | is_on_demand = true; |
| 1755 | if (t && strcmp(t, "asterisk") == 0) |
| 1756 | is_on_demand = true; |
| 1757 | } else { |
| 1758 | const char *pk = ts_node_type(cc); |
| 1759 | if (strcmp(pk, "asterisk") == 0) |
| 1760 | is_on_demand = true; |
| 1761 | else if (strcmp(pk, "scoped_identifier") == 0 || |
| 1762 | strcmp(pk, "identifier") == 0) { |
| 1763 | path = java_node_text(ctx, cc); |
| 1764 | } |
| 1765 | } |
| 1766 | } |
| 1767 | if (path) { |
| 1768 | if (is_on_demand) { |
| 1769 | int kind = is_static ? CBM_JAVA_IMPORT_STATIC_OD : CBM_JAVA_IMPORT_ON_DEMAND; |
| 1770 | java_lsp_add_import(ctx, "*", path, kind); |
| 1771 | } else if (is_static) { |
| 1772 | /* Static import: target is fully-qualified — last segment |
| 1773 | * is the imported member. */ |
| 1774 | const char *last_dot = strrchr(path, '.'); |
| 1775 | const char *local = last_dot ? last_dot + 1 : path; |
| 1776 | java_lsp_add_import(ctx, local, path, CBM_JAVA_IMPORT_STATIC); |
| 1777 | } else { |
| 1778 | const char *last_dot = strrchr(path, '.'); |
| 1779 | const char *local = last_dot ? last_dot + 1 : path; |
| 1780 | java_lsp_add_import(ctx, local, path, CBM_JAVA_IMPORT_TYPE); |
| 1781 | } |
| 1782 | } |
| 1783 | } |
| 1784 | } |
no test coverage detected