Namespace/using/alias-aware C# simple-name resolution. Factored out of ``_resolve_csharp_type_references`` so the member-call pass (``_resolve_csharp_member_calls`` in ``graphify/extract.py``) can type a receiver with the same scoping rules the type-reference side already applies (t
| 304 | |
| 305 | |
| 306 | class CsharpNameResolver: |
| 307 | """Namespace/using/alias-aware C# simple-name resolution. |
| 308 | |
| 309 | Factored out of ``_resolve_csharp_type_references`` so the member-call pass |
| 310 | (``_resolve_csharp_member_calls`` in ``graphify/extract.py``) can type a |
| 311 | receiver with the same scoping rules the type-reference side already applies |
| 312 | (the core of #1620), instead of bailing on any corpus-wide bare-name clash. |
| 313 | |
| 314 | Built from graph-stamped facts only: the ``(namespace, name)`` type-definition |
| 315 | index plus the per-file ``using``/alias import edges (each carrying its lexical |
| 316 | scope — ``("file", None)`` applies file-wide; ``("namespace", scope_id)`` |
| 317 | applies only where ``scope_id`` is in the referencing node's ``scope_chain``). |
| 318 | """ |
| 319 | |
| 320 | def __init__(self, all_nodes: list[dict], all_edges: list[dict]) -> None: |
| 321 | self.node_by_id: dict[str, dict] = { |
| 322 | node["id"]: node |
| 323 | for node in all_nodes |
| 324 | if isinstance(node.get("id"), str) and node.get("id") |
| 325 | } |
| 326 | self.type_def_index = _build_csharp_type_def_index(all_nodes, all_edges) |
| 327 | self.known_namespaces = { |
| 328 | node.get("label") |
| 329 | for node in all_nodes |
| 330 | if node.get("type") == "namespace" and isinstance(node.get("label"), str) |
| 331 | } |
| 332 | # Every namespace a C# file declares, with its enclosing namespaces: |
| 333 | # `namespace A.B.C` declares `A` and `A.B` too. |
| 334 | self.declared_namespaces: set[str] = set() |
| 335 | for node in all_nodes: |
| 336 | label = node.get("label") |
| 337 | if ( |
| 338 | node.get("type") == "namespace" |
| 339 | and isinstance(label, str) |
| 340 | and label |
| 341 | and _is_cs_file(node.get("source_file")) |
| 342 | ): |
| 343 | parts = label.split(".") |
| 344 | for i in range(1, len(parts) + 1): |
| 345 | self.declared_namespaces.add(".".join(parts[:i])) |
| 346 | |
| 347 | self.namespace_usings_by_file: dict[str, list[tuple[str, str, str | None]]] = {} |
| 348 | self.aliases_by_file: dict[str, dict[str, list[tuple[str, str, str | None]]]] = {} |
| 349 | self.static_usings_by_file: dict[str, list[tuple[str, str, str | None]]] = {} |
| 350 | self.nested_types_by_holder: dict[str, dict[str, str]] = {} |
| 351 | self.base_types_by_holder: dict[str, list[str]] = {} |
| 352 | # Lexical nesting, for simple-name lookup in enclosing types (C# 7.6.1): |
| 353 | # nested type -> the type that declares it, and member -> its owning type. |
| 354 | self.holder_of_type: dict[str, str] = {} |
| 355 | self.owner_of_member: dict[str, str] = {} |
| 356 | self._holder_nid_cache: dict[str, str | None] = {} |
| 357 | |
| 358 | for edge in all_edges: |
| 359 | if edge.get("relation") != "imports": |
| 360 | continue |
| 361 | source_node = self.node_by_id.get(edge.get("source")) |
| 362 | if not ( |
| 363 | source_node |
no outgoing calls