Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(graph): type Java call chains, inherited fields, super and cast receivers (#3623)
Swati Ahuja8ff7630165d4
diff --git a/packages/core/src/repowise/core/ingestion/call_language_strategies.py b/packages/core/src/repowise/core/ingestion/call_language_strategies.pyindex 63a4922d3..2e17675e1 100644--- a/packages/core/src/repowise/core/ingestion/call_language_strategies.py+++ b/packages/core/src/repowise/core/ingestion/call_language_strategies.py@@ -22,11 +22,18 @@ class _LanguageCallStrategies:after all of them, so a strategy there only ever sees a call nothing elseclaimed and can only add an edge. All three stop at the first hit.Strategies are named rather than bound so a probe can substitute one.++ ``member_bare_fallback`` lets a member or chained call nothing claimed fall+ back to the bare-name tiers. ``inherited_typed_receiver`` lets a typed+ receiver whose type lacks the method answer with the one ancestor that+ declares it."""free: tuple[str, ...] = ()member: tuple[str, ...] = ()member_fallback: tuple[str, ...] = ()+ member_bare_fallback: bool = True+ inherited_typed_receiver: bool = False_NO_LANGUAGE_STRATEGIES = _LanguageCallStrategies()@@ -61,10 +68,15 @@ _LANGUAGE_CALL_STRATEGIES: dict[str, _LanguageCallStrategies] = {# Kotlin shares the JVM tiers and the typed-receiver fallback. Java takes# the uniqueness-gated package tier, Kotlin the open one; see# ``_resolve_java_same_package_unique`` for why that is a language rule.+ # A Java member call never reaches the bare-name tiers: measured on jsoup+ # and gson, they bound such calls at 0.38 site precision. Kotlin is+ # unmeasured, so it keeps both defaults."java": replace(_JVM_STRATEGIES,free=("_resolve_java_same_package_unique",),member_fallback=_TYPED_RECEIVER,+ member_bare_fallback=False,+ inherited_typed_receiver=True,),"kotlin": replace(_JVM_STRATEGIES, member_fallback=_TYPED_RECEIVER),"csharp": _LanguageCallStrategies(member_fallback=_TYPED_RECEIVER),diff --git a/packages/core/src/repowise/core/ingestion/call_receiver_typing.py b/packages/core/src/repowise/core/ingestion/call_receiver_typing.pyindex 6c32dae09..e61595717 100644--- a/packages/core/src/repowise/core/ingestion/call_receiver_typing.py+++ b/packages/core/src/repowise/core/ingestion/call_receiver_typing.py@@ -3,6 +3,7 @@from __future__ import annotationsimport posixpath+import refrom bisect import bisect_left, bisect_rightfrom dataclasses import replacefrom pathlib import Path@@ -44,7 +45,12 @@ from .models import CallSite, NamedBinding, ParsedFile, Symbol, symbol_id_languafrom .resolved_call import ResolvedCallfrom .return_types import declared_return_type, go_first_resultfrom .symbol_identity import id_segment_name-from .type_names import POINTER_LIKE_MEMBERS, bare_type_name, type_qualifier+from .type_names import (+ POINTER_LIKE_MEMBERS,+ bare_type_name,+ strip_type_arguments,+ type_qualifier,+)# Which symbols own a class scope, and which of them swallow one. A class span# contains every method body inside it, so both sets are needed to tell a field@@ -54,6 +60,19 @@ _FUNCTION_KINDS = frozenset({"function", "method"})_SOURCE_CACHE_FILES = 4+# Any Java type spelling before a declared name, for ``_declares_name``; the+# words that may precede a bare name without declaring it.+_JAVA_ANY_TYPE = r"[\w$]+(?:\.[\w$]+)*(?:<[^;{}()]*>)?(?:\[\])*"+_NOT_A_TYPE = frozenset({"return", "throw", "new", "else", "case", "yield", "assert"})++# Where a Java declaration header opens its type-parameter list: after a type's+# name, or after a method's modifiers and annotations, before its return type.+_JAVA_TYPE_PARAMETERS = re.compile(+ r"\b(?:class|interface|record)\s+\w+\s*<"+ r"|^(?:\s*(?:@[\w.]+(?:\([^)]*\))?|public|protected|private|static|final|abstract"+ r"|synchronized|native|default|strictfp)\b)*\s*<"+)+# Languages whose grammar mints ``a.b.c.m()`` with the dotted path as its# receiver, every segment after the head a field. Each maps to the name that# means the caller's own instance; TypeScript's ``self`` is a global, not@@ -134,6 +153,21 @@ def _types_by_name(parsed: ParsedFile) -> dict[str, list[str]]:return by_name+def _header_type_parameters(header: str) -> set[str]:+ """The names a Java declaration header's ``<...>`` list declares."""+ opened = _JAVA_TYPE_PARAMETERS.search(header)+ if opened is None:+ return set()+ depth, close = 1, opened.end()+ while close < len(header) and depth:+ depth += {"<": 1, ">": -1}.get(header[close], 0)+ close += 1+ names: set[str] = set()+ for param in strip_type_arguments(header[opened.end() : close - 1]).split(","):+ names.update(param.split()[:1])+ return names++class ReceiverTypingMixin:"""Typed-receiver and C# extension strategies, with the source caches they read."""@@ -246,7 +280,65 @@ class ReceiverTypingMixin:found = self._typed_receiver_lookup(file_path, call, caller_id, type_name)if found is not None and found[1] != "global":return found- return self._typed_receiver_lookup(file_path, call, caller_id, bare)+ found = self._typed_receiver_lookup(file_path, call, caller_id, bare, type_name)+ if found is None and self._strategies_for(file_path).inherited_typed_receiver:+ return self._inherited_typed_target(file_path, call, caller_id, bare)+ return found++ def _inherited_typed_target(+ self, file_path: str, call: CallSite, caller_id: str, bare: str+ ) -> tuple[str, str] | None:+ """The one ancestor method a typed receiver reaches when its type lacks it.++ The type is the repository's only declaration of *bare*, the repo-wide+ tier's evidence, so the answer is scoped ``global``, and only when the+ caller can see it and no type parameter or import shadows it. A type+ that declares the method itself was refused above for a reason this+ keeps.+ """+ if bare in self._externally_bound_names(file_path):+ return None+ declared = self._declared_types_named(bare)+ if len(declared) != 1 or bare in self._java_type_parameters(file_path, caller_id):+ return None+ type_file, (type_id, *_), _ = declared[0]+ if not self._visible_java_type(file_path, bare, type_file):+ return None+ if self._declares(type_id, call.target_name) is not None:+ return None+ hit = self._ancestor_method(type_id, call.target_name, caller_id, class_chain_first=True)+ return None if hit is None else (hit, "global")++ def _visible_java_type(self, file_path: str, bare: str, type_file: str) -> bool:+ """Whether Java lets *file_path* write *bare* for the type in *type_file*.++ Its own file, its package, or a single-type import of that file. A+ wildcard import is not enough: the name may be another package's.+ """+ if type_file == file_path or self._import_names.get(file_path, {}).get(bare) == type_file:+ return True+ index = self._get_jvm_index()+ return index is not None and type_file in index.same_package_files(file_path)++ def _java_type_parameters(self, file_path: str, caller_id: str) -> set[str]:+ """Type parameters the caller and its enclosing types declare.++ Read off each declaration header, up to its body's ``{``, since no+ parsed symbol keeps its ``<...>`` list.+ """+ spans = self._spans_for(file_path)+ line = spans.get(caller_id, (0, 0))[0]+ lines = self._text_of(file_path).splitlines()+ names: set[str] = set()+ for sym_id, (start, end) in spans.items():+ symbol = self._symbols_by_id.get(sym_id)+ if not (start <= line <= end and symbol is not None):+ continue+ if symbol.kind not in _TYPE_KINDS and symbol.kind not in _FUNCTION_KINDS:+ continue+ header = "\n".join(lines[start - 1 : end]).partition("{")[0]+ names.update(_header_type_parameters(header))+ return namesdef _typed_receiver_lookup(self,@@ -254,6 +346,7 @@ class ReceiverTypingMixin:call: CallSite,caller_id: str,type_name: str,+ spelled: str | None = None,) -> tuple[str, str] | None:key = (type_name, call.target_name)# What an import binds is the written name, never its arity.@@ -286,7 +379,7 @@ class ReceiverTypingMixin:if hit is not None:return hit.callee_id, "same_package"- return self._receiver_pair_match(file_path, key)+ return self._receiver_pair_match(file_path, key, spelled)def _import_bound_method(self, file_path: str, bound: str, key: tuple[str, str]@@ -332,7 +425,7 @@ class ReceiverTypingMixin:if language not in _CHAIN_SELF:return Nonereturn self._resolve_chained_receiver(file_path, call, caller_id, language)- type_name, scope = self._receiver_type_and_scope(+ type_name, scope, typing_file = self._receiver_type_and_scope(file_path, caller_id, language, receiver_name)if type_name is None:@@ -349,7 +442,7 @@ class ReceiverTypingMixin:if self._means_the_wrapper(file_path, caller_id, language, call, receiver_name):return None- found = self._typed_receiver_target(file_path, call, caller_id, type_name)+ found = self._typed_receiver_target(typing_file, call, caller_id, type_name)if found is None:# Last, because C# prefers an instance method to an extension.return self._typed_extension_call(file_path, call, caller_id, type_name, language)@@ -366,15 +459,16 @@ class ReceiverTypingMixin:caller_id: str,language: str,receiver_name: str,- ) -> tuple[str | None, str]:- """The receiver's declared type and the scope that declared it.+ ) -> tuple[str | None, str, str]:+ """The receiver's declared type, the scope that declared it, and the file to read it in.A local shadows a field, so the body answers first and its answerstands — including when that answer is "declared twice, no usabletype". Only a name the body never mentions reaches class scope, andonly a name neither binds reaches module scope. A name the body bindswith no type it can read (`{ api -> api.m() }`) is still a local, so it- refuses the field too.+ refuses the field too. A field a repository ancestor declares is read+ in that ancestor's file."""body_types = self._declared_types_in(file_path, caller_id, language)# A builtin type answers only when nothing else does, so a local@@ -383,24 +477,95 @@ class ReceiverTypingMixin:declared = body_types.get(receiver_name)builtin_local = external_type_name(declared) is not Noneif receiver_name in body_types and not builtin_local:- return declared, "body"+ return declared, "body", file_pathif language in IMPLICIT_FIELD_LANGUAGES:- class_id = self._caller_class_id(caller_id)- fields = self._field_types_in(file_path, language).get(class_id, {})- field = fields.get(receiver_name)- if receiver_name in fields and not (builtin_local and external_type_name(field)):- bound = self._bound_names_in(file_path, caller_id, language)- if builtin_local or receiver_name not in bound:- return field, "field"+ found = self._field_type(file_path, caller_id, language, receiver_name, builtin_local)+ if found is not None:+ return foundif builtin_local:- return declared, "body"+ return declared, "body", file_path# Third scope: a module-level def a framework decorator turned into an# instance, which is neither in the body nor a field.if language in FRAMEWORK_DECORATOR_LANGUAGES:type_name = self._framework_receiver_type(file_path, caller_id, language, receiver_name)if type_name is not None:- return type_name, "framework"- return self._module_receiver_type(file_path, caller_id, language, receiver_name), "body"+ return type_name, "framework", file_path+ type_name = self._module_receiver_type(file_path, caller_id, language, receiver_name)+ return type_name, "body", file_path++ def _field_type(+ self, file_path: str, caller_id: str, language: str, name: str, builtin_local: bool+ ) -> tuple[str | None, str, str] | None:+ """The caller class's field *name*, else the one a repository ancestor declares.++ A name the body binds with no readable type is a local and refuses both.+ """+ if not builtin_local and name in self._bound_names_in(file_path, caller_id, language):+ return None+ class_id = self._caller_class_id(caller_id)+ fields = self._field_types_in(file_path, language).get(class_id, {})+ if name in fields:+ field = fields[name]+ return None if builtin_local and external_type_name(field) else (field, "field", file_path)+ if builtin_local:+ return None+ inherited = self._inherited_field(file_path, caller_id, class_id, name, language)+ return None if inherited is None else (inherited[1], "field", inherited[0])++ def _inherited_field(+ self, file_path: str, caller_id: str, class_id: str, name: str, language: str+ ) -> tuple[str, str | None] | None:+ """``(declaring file, type)`` of the field *name* the nearest superclass declares.++ Only where a typed receiver may reach an ancestor (Java). The+ declaration scan skips a type it cannot read (``b.Reader x``,+ ``int[] x``), so the caller, its class and each superclass passed are+ also asked whether they declare the name at all: one that does hides+ the rest, and refuses.+ """+ if not self._strategies_for(file_path).inherited_typed_receiver:+ return None+ if self._declares_name(file_path, caller_id, name) or self._declares_name(+ file_path, class_id, name+ ):+ return None+ for ancestor in self._superclass_chain(class_id):+ path = self._symbol_paths_by_id.get(ancestor)+ if path is None:+ return None+ fields = self._field_types_in(path, language).get(ancestor, {})+ if name in fields:+ return path, fields[name]+ if self._declares_name(path, ancestor, name):+ return None+ return None++ def _declares_name(self, file_path: str, owner_id: str, name: str) -> bool:+ """Does *owner_id*, a method or a class's own scope, declare *name* with any type?++ A scan for the one name, run only where an inherited field would+ answer: admitting every type spelling to the declaration scan slows+ it by about two thirds. Ceiling: a later declarator (``int a, x;``) is+ missed.+ """+ spans = self._spans_for(file_path)+ start, end = spans.get(owner_id, (1, 0))+ owner = self._symbols_by_id.get(owner_id)+ bodies = merge_spans(+ span+ for sym_id, span in spans.items()+ if owner is not None+ and owner.kind not in _FUNCTION_KINDS+ and getattr(self._symbols_by_id.get(sym_id), "kind", None) in _FUNCTION_KINDS+ )+ declared = re.compile(rf"(?<![\w.@$])(?P<type>{_JAVA_ANY_TYPE})\s+{re.escape(name)}\s*[=;,):]")+ lines = self._text_of(file_path).splitlines()+ return any(+ match.group("type") not in _NOT_A_TYPE+ for number in range(start, min(end, len(lines)) + 1)+ if not in_spans(bodies, number)+ for match in declared.finditer(lines[number - 1])+ )def _module_receiver_type(self,@@ -555,8 +720,10 @@ class ReceiverTypingMixin:if symbol is None or symbol.kind not in _TYPE_KINDS:return Nonereturn file_path, class_id, "same_file"- type_name, _ = self._receiver_type_and_scope(file_path, caller_id, language, head)- return None if type_name is None else self._class_named(file_path, type_name)+ type_name, _, typing_file = self._receiver_type_and_scope(+ file_path, caller_id, language, head+ )+ return None if type_name is None else self._class_named(typing_file, type_name)def _chain_hop(self, found: tuple[str, str, str], field: str, language: str@@ -767,7 +934,9 @@ class ReceiverTypingMixin:language = self._typed_receiver_language(file_path, call)if language not in EXTERNAL_TYPE_LANGUAGES:return False- type_name, _ = self._receiver_type_and_scope(file_path, caller_id, language, receiver_name)+ type_name, _, typing_file = self._receiver_type_and_scope(+ file_path, caller_id, language, receiver_name+ )if type_name is None or "::" in type_name:return Falsebuiltin = external_type_name(type_name)@@ -775,7 +944,7 @@ class ReceiverTypingMixin:head = type_qualifier(builtin or type_name) or builtin or type_nameif head in self._known_type_names:return False- return builtin is not None or head in self._externally_bound_names(file_path)+ return builtin is not None or head in self._externally_bound_names(typing_file)def _externally_bound_names(self, file_path: str) -> frozenset[str]:"""Simple names this file imports from outside the repo.diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.pyindex c190eced1..1a49b9598 100644--- a/packages/core/src/repowise/core/ingestion/call_resolver.py+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py@@ -25,6 +25,7 @@ per strategy, and it is what the edge carries.from __future__ import annotationsfrom collections import defaultdict+from collections.abc import Iteratorfrom dataclasses import replacefrom pathlib import PurePosixPathfrom typing import Any@@ -156,7 +157,7 @@ def _is_property_accessor(sym: Any) -> bool:# Languages admitted to the full return-type chain lane; each is admitted# explicitly, once measured.-PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGES: frozenset[str] = frozenset({"cpp", "csharp", "go"})+PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGES: frozenset[str] = frozenset({"cpp", "csharp", "go", "java"})# Chain lanes that need a file or import/re-export identity for the head type:# a repository-global simple type name is not a language binding.@@ -281,6 +282,8 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):)self._ancestors: dict[str, tuple[str, ...]] = {}self._mros: dict[str, tuple[str, ...] | None] = {}+ # {type name: [(file, identity, arity)]}, filled by ``_declared_types_named``.+ self._declared_types: dict[str, list[tuple[str, tuple[str, ...], int]]] = {}# Per-file symbol index: {file_path: {symbol_name: symbol_id}}self._file_symbols: dict[str, dict[str, str]] = {}# The same, top-level symbols only: what a module alias can reach.@@ -963,7 +966,7 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):language = self._language_of(file_path) or ""receiver_call = call.receiver_call- if language == "python" and _is_super_receiver(receiver_call):+ if _is_super_call(call, language):return self._with_props(self._super_call(call, caller_id), call)# A language with an `external_return_types` table reaches the tier for# that table alone; only the constant above admits the full lane.@@ -977,12 +980,15 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):if handled:return resolved+ bare_fallback = self._strategies_for(file_path).member_bare_fallback# --- Method call with receiver: receiver.method() ---if call.receiver_name:handled, hit = self._resolve_member_call(file_path, call, caller_id)- if not handled and call.bare_name_fallback:+ if not handled and call.bare_name_fallback and bare_fallback:hit = self._resolve_free_call(file_path, call, caller_id)return self._with_props(hit, call)+ if receiver_call is not None and not bare_fallback:+ return None# --- Free function call: function() ---return self._with_props(self._resolve_free_call(file_path, call, caller_id), call)@@ -1233,11 +1239,11 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):A receiver records one hop, but the parser keeps every link of a chainas its own site on the chain's first line, so the hop below is read- off the site *inner* names. Only C# reads it; elsewhere an inner call- is still typed as if nothing were chained under it. Go reads it too, so a- builder chain types each link from the one before.+ off the site *inner* names. C#, Go and Java read it, so a builder chain+ types each link from the one before; elsewhere an inner call is still+ typed as if nothing were chained under it."""- if language not in ("csharp", "go"):+ if language not in ("csharp", "go", "java"):return Nonesites = self._chained_sites.get(file_path)if sites is None:@@ -1807,6 +1813,8 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):def _super_call(self, call: CallSite, caller_id: str) -> ResolvedCall | None:"""``super().m()``: the first class after the caller's own in its MRO to declare ``m``.+ Java's ``super.m()`` arrives here too, with ``super`` as its receiver.+Never handed to the bare-name tiers, which answered with whicheversame-named method the file declared last. A base outside therepository ends the walk unresolved: it may declare ``m`` itself.@@ -1904,8 +1912,19 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):return Nonereturn self._ancestor_method(class_id, method_name, caller_id)- def _ancestor_method(self, class_id: str, method_name: str, caller_id: str) -> str | None:- """The one method of this name *class_id*'s ancestors declare, never the caller."""+ def _ancestor_method(+ self, class_id: str, method_name: str, caller_id: str, *, class_chain_first: bool = False+ ) -> str | None:+ """The one method of this name *class_id*'s ancestors declare, never the caller.++ With *class_chain_first*, Java's rule: the nearest declaration up the+ single superclass chain overrides the rest, so it answers before the+ uniqueness check over every ancestor.+ """+ if class_chain_first:+ nearest = self._superclass_chain_method(class_id, method_name)+ if nearest is not None:+ return None if nearest == caller_id else nearesthits = set()for ancestor in self._ancestors_of(class_id):sym_id = self._declares(ancestor, method_name)@@ -1913,6 +1932,33 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):hits.add(sym_id)return next(iter(hits)) if len(hits) == 1 else None+ def _superclass_chain_method(self, class_id: str, method_name: str) -> str | None:+ """The nearest declaration of *method_name* up the single superclass chain."""+ for node in self._superclass_chain(class_id):+ sym_id = self._declares(node, method_name)+ if sym_id is not None:+ return sym_id+ return None++ def _superclass_chain(self, class_id: str) -> Iterator[str]:+ """*class_id*'s superclasses, nearest first.++ The walk stops where a type has no class parent, more than one, or+ one already seen.+ """+ node, seen = class_id, {class_id}+ while True:+ parents = [+ p+ for p in self._heritage_parents.get(node, ())+ if getattr(self._symbols_by_id.get(p), "kind", None) == "class"+ ]+ if len(parents) != 1 or parents[0] in seen:+ return+ seen.add(parents[0])+ node = parents[0]+ yield node+def _declares(self, class_id: str, method_name: str) -> str | None:"""The symbol a type node declares under *method_name*, or None.@@ -1945,12 +1991,14 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):self,file_path: str,key: tuple[str, str],+ spelled: str | None = None,) -> tuple[str, str] | None:"""The symbol a ``(class, method)`` pair names, and the scope that held it.No class declares the pair unless the global method index holds it, andthat check also keeps the merged-import view from being built for a- pair that cannot be in it.+ pair that cannot be in it. *spelled* is the type as the call site+ wrote it when that carries a C# arity (``Policy`1``) the key drops."""if key not in self._global_methods:return None@@ -1963,20 +2011,65 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):if key in merged_methods:return merged_methods[key], "import"- # Trait method dispatch — the method may be defined on a trait's impl- # block in another file. The global index preserves file-insertion- # match order; the caller's own file is skipped.- for path, sym_id in self._global_methods[key]:- if path != file_path:- return sym_id, "global"+ return self._repo_wide_method(key, spelled or key[0])- return None+ def _repo_wide_method(self, key: tuple[str, str], spelled: str) -> tuple[str, str] | None:+ """The global tier: the one method *key* can name anywhere, or None.++ Nothing at this scope tells two same-named types apart, so it answers+ only when one repository type can be meant and one method of it+ matches. Otherwise a call on one project's ``MainWindow`` binds to+ whichever ``MainWindow`` sorts first, even one that merely inherits+ the method. A file declaring only a type the call cannot mean (another+ arity of a C# generic) holds no candidate; any other file, including+ one with no type of that name (a trait ``impl``, an out-of-line C+++ body), still does.+ """+ bare, _, arity = spelled.partition("`")+ declared = self._declared_types_named(bare)+ meant = {identity for _, identity, count in declared if count == int(arity or 0)}+ if len(meant) > 1:+ return None+ owners: dict[str, set[tuple[str, ...]]] = defaultdict(set)+ for path, identity, _ in declared:+ owners[path].add(identity)+ candidates = self._collapse_declarations(+ [+ sym_id+ for path, sym_id in self._global_methods[key]+ if len(owners.get(path, ())) != 1 or owners[path] <= meant+ ]+ )+ if len(candidates) != 1:+ return None+ return next(iter(candidates)), "global"++ def _declared_types_named(self, name: str) -> list[tuple[str, tuple[str, ...], int]]:+ """``(file, identity, arity)`` for each repository type declared as *name*.++ The fragments of one ``partial`` type share an identity. A forward+ declaration and a Rust ``impl`` block declare no type.+ """+ found = self._declared_types.get(name)+ if found is not None:+ return found+ found = []+ for sym_id in self._global_symbols.get(name, ()):+ symbol = self._symbols_by_id[sym_id]+ if symbol.kind not in _TYPE_KINDS or symbol.kind == "impl" or symbol.is_declaration:+ continue+ path = self._symbol_paths_by_id[sym_id]+ arity = symbol.type_parameter_count or 0+ identity = self._partial_fragments.get((path, name)) or (sym_id,)+ found.append((path, (*identity, str(arity)), arity))+ self._declared_types[name] = found+ return founddef _answers_for_a_foreign_type(self, file_path: str, receiver_name: str) -> bool:"""Is the repo-wide tier about to answer a call on a type we do not own?- Asked only of the ``global`` tier, which takes the first file-order- match for a ``(type, method)`` pair with no uniqueness check. A+ Asked only of the ``global`` tier, which answers whenever the+ repository declares one type of that name with the method. Arepository that writes ``impl Trait for Vec<Entity>`` declares a``Vec::new``, and without this every ``Vec::new()`` in the tree wouldbind to it. The narrower tiers are grounded in the caller's own file or@@ -2029,9 +2122,17 @@ def _rivals_a_class_method(symbol_id: str) -> bool:return len(parts) >= 3 and id_segment_name(parts[-1]) != id_segment_name(parts[-2])-def _is_super_receiver(receiver: CallReceiver | None) -> bool:- """Is this chained call's receiver Python's ``super(...)``?"""- return receiver is not None and receiver.target_name == "super" and receiver.receiver_name is None+def _is_super_call(call: CallSite, language: str) -> bool:+ """Python's ``super().m()`` (a chained call) or Java's ``super.m()``."""+ if language == "java":+ return call.receiver_name == "super"+ receiver = call.receiver_call+ return (+ language == "python"+ and receiver is not None+ and receiver.target_name == "super"+ and receiver.receiver_name is None+ )def _c3_merge(sequences: list[tuple[str, ...]]) -> list[str] | None:diff --git a/packages/core/src/repowise/core/ingestion/queries/java.scm b/packages/core/src/repowise/core/ingestion/queries/java.scmindex d0af4cc58..5d6d13d92 100644--- a/packages/core/src/repowise/core/ingestion/queries/java.scm+++ b/packages/core/src/repowise/core/ingestion/queries/java.scm@@ -99,12 +99,29 @@; bare name through the flat same-file index instead of against the caller's own; class.;-; ``super`` stays out: ``super.m()`` arrives bare, where the caller's own class-; answers it and the recursion refusal drops an override calling itself. No-; member strategy answers a ``super`` receiver for Java, so capturing one would-; only move the call onto its bare-name fallback, which skips the caller's class.+; ``super.m()`` is captured too, so the resolver walks the caller's ancestors+; instead of binding the caller's own override.(method_invocation- object: (this) @call.receiver+ object: [(this) (super)] @call.receiver+ name: (identifier) @call.target+ arguments: (argument_list) @call.arguments+) @call.site++; Cast receiver: ((Foo) x).bar(args) names its type at the call site, like the+; fluent construction below. A scoped type (``(a.Foo) x``) is left uncaptured,+; and the anchors keep an intersection cast (``(Foo & Bar) x``) out.+(method_invocation+ object: (parenthesized_expression+ (cast_expression+ .+ type: [+ (type_identifier) @call.receiver+ (generic_type (type_identifier) @call.receiver)+ ]+ .+ value: (_)+ )+ )name: (identifier) @call.targetarguments: (argument_list) @call.arguments) @call.sitediff --git a/tests/unit/ingestion/parser/test_java.py b/tests/unit/ingestion/parser/test_java.pyindex d6b5d5d77..4833d6bc3 100644--- a/tests/unit/ingestion/parser/test_java.py+++ b/tests/unit/ingestion/parser/test_java.py@@ -153,6 +153,8 @@ class TestReceiverlessTwin:assert (10, None) not in self._sites(parser, "set")assert (11, "this") in self._sites(parser, "reset")assert (11, None) not in self._sites(parser, "reset")+ assert (13, "super") in self._sites(parser, "reset")+ assert (13, None) not in self._sites(parser, "reset")fi = _make_file_info("java_pkg/Token.java", "java")calls = parser.parse_file(fi, TWIN_SOURCE).callsassert all(c.bare_name_fallback for c in calls if c.receiver_name)@@ -161,7 +163,6 @@ class TestReceiverlessTwin:def test_genuine_receiverless_calls_are_kept(self, parser: ASTParser) -> None:resets = self._sites(parser, "reset")assert (12, None) in resets, "a bare reset()"- assert (13, None) in resets, "super.reset() has no receiver pattern"assert self._sites(parser, "max") == [(14, None)], "a static-imported call"def test_a_bare_call_sharing_a_line_with_its_member_twin_is_kept(diff --git a/tests/unit/ingestion/test_call_resolver_strategies.py b/tests/unit/ingestion/test_call_resolver_strategies.pyindex 61f80b509..2e3852c38 100644--- a/tests/unit/ingestion/test_call_resolver_strategies.py+++ b/tests/unit/ingestion/test_call_resolver_strategies.py@@ -923,6 +923,156 @@ class TestPythonTypedReceiver:assert not [e for e in edges if str(e[3]).startswith("receiver_typed_")]+class TestRepoWideReceiverTier:+ """The global tier answers only for the one type of a name.++ Two projects each declaring a ``MainWindow`` are told apart by nothing+ that tier sees, so a call naming neither one's namespace gets no edge+ rather than whichever file sorts first.+ """++ _CALLER = "peek/Peek.UITests/PeekTests.cs"+ _RESIZER = (+ "csharp",+ "namespace ImageResizer.Views\n{\n public partial class MainWindow\n {\n"+ " public void Show() { }\n }\n}\n",+ )+ _PEEK = (+ "csharp",+ "namespace Peek.UI\n{\n public partial class MainWindow\n {\n"+ " public void Show() { }\n }\n}\n",+ )++ @staticmethod+ def _test(usings: str = "") -> tuple[str, str]:+ return (+ "csharp",+ f"{usings}namespace Peek.UITests\n{{\n public class PeekTests\n {{\n"+ " public void Opens()\n {\n"+ " var w = new MainWindow();\n w.Show();\n }\n }\n}\n",+ )++ def _resolved(+ self,+ tmp_path: Path,+ files: dict[str, tuple[str, str]],+ method: str = "Show",+ imports: dict[str, dict[str, str]] | None = None,+ **resolver_kwargs: object,+ ) -> list[tuple[str, str]]:+ """``(callee, origin)`` for every edge onto a method named *method*."""+ parsed = _parse_all(tmp_path, files)+ targets: dict[str, set[str]] = {p: set() for p in parsed}+ for path, links in (imports or {}).items():+ _link_imports(parsed, {path: links})+ targets[path] = set(links.values())+ resolver = CallResolver(parsed, targets, repo_path=str(tmp_path), **resolver_kwargs)+ return sorted(+ (rc.callee_id, rc.origin)+ for path, pf in parsed.items()+ for rc in resolver.resolve_file(path, pf.calls)+ if rc.callee_id.endswith(f"::{method}")+ )++ def test_two_same_named_types_declaring_the_method_give_no_edge(+ self, tmp_path: Path+ ) -> None:+ files = {+ "resizer/MainWindow.xaml.cs": self._RESIZER,+ "peek/Peek.UI/MainWindow.xaml.cs": self._PEEK,+ self._CALLER: self._test(),+ }+ assert self._resolved(tmp_path, files) == []++ def test_a_same_named_type_that_only_inherits_the_method_gives_no_edge(+ self, tmp_path: Path+ ) -> None:+ """One declaration is not one candidate: the other ``MainWindow`` may be meant."""+ inherits = (+ "csharp",+ "namespace Peek.UI\n{\n public partial class MainWindow : Window\n {\n"+ " public void Close() { }\n }\n}\n",+ )+ files = {+ "resizer/MainWindow.xaml.cs": self._RESIZER,+ "peek/Peek.UI/MainWindow.xaml.cs": inherits,+ self._CALLER: self._test(),+ }+ assert self._resolved(tmp_path, files) == []++ def test_the_one_type_of_the_name_keeps_its_edge(self, tmp_path: Path) -> None:+ files = {"resizer/MainWindow.xaml.cs": self._RESIZER, self._CALLER: self._test()}+ assert self._resolved(tmp_path, files) == [+ ("resizer/MainWindow.xaml.cs::MainWindow::Show", "receiver_typed_global")+ ]++ def test_the_fragments_of_one_partial_type_count_once(self, tmp_path: Path) -> None:+ crop = (+ "csharp",+ "namespace ImageResizer.Views\n{\n public partial class MainWindow\n {\n"+ " public void Crop() { }\n }\n}\n",+ )+ files = {+ "resizer/MainWindow.xaml.cs": self._RESIZER,+ "resizer/MainWindow.Crop.cs": crop,+ self._CALLER: self._test(),+ }+ fragments = ("resizer/MainWindow.Crop.cs", "resizer/MainWindow.xaml.cs")+ assert self._resolved(+ tmp_path, files, partial_fragments={(f, "MainWindow"): fragments for f in fragments}+ ) == [("resizer/MainWindow.xaml.cs::MainWindow::Show", "receiver_typed_global")]++ def test_a_using_that_names_the_namespace_keeps_the_edge(self, tmp_path: Path) -> None:+ files = {+ "resizer/MainWindow.xaml.cs": self._RESIZER,+ "peek/Peek.UI/MainWindow.xaml.cs": self._PEEK,+ self._CALLER: self._test("using ImageResizer.Views;\n"),+ }+ imports = {self._CALLER: {"ImageResizer.Views": "resizer/MainWindow.xaml.cs"}}+ assert self._resolved(tmp_path, files, imports=imports) == [+ ("resizer/MainWindow.xaml.cs::MainWindow::Show", "receiver_typed_import")+ ]++ def test_csharp_arity_tells_a_generic_from_its_plain_twin(self, tmp_path: Path) -> None:+ """``Policy`` and ``Policy<T>`` are two types; the receiver's arity picks one."""+ files = {+ "src/Policy.cs": (+ "csharp",+ "namespace P\n{\n public partial class Policy\n {\n"+ " public static void Handle() { }\n"+ " public void Show() { }\n }\n}\n",+ ),+ "src/PolicyT.cs": (+ "csharp",+ "namespace P\n{\n public partial class Policy<TResult>\n {\n"+ " public void Show() { }\n }\n}\n",+ ),+ "src/Use.cs": (+ "csharp",+ "namespace P\n{\n public class Use\n {\n"+ " public void Run(Policy<int> g, Policy p)\n {\n"+ " Policy.Handle();\n g.Show();\n"+ " p.Show();\n }\n }\n}\n",+ ),+ }+ assert self._resolved(tmp_path, files) == [+ ("src/Policy.cs::Policy::Show", "receiver_typed_global"),+ ("src/PolicyT.cs::Policy::Show", "receiver_typed_global"),+ ]+ assert self._resolved(tmp_path, files, "Handle") == [+ ("src/Policy.cs::Policy::Handle", "receiver_global")+ ]++ def test_python_classes_sharing_a_name_give_no_edge(self, tmp_path: Path) -> None:+ graph = "class DependencyGraph:\n def add_arc(self, obj):\n return obj\n"+ files = {+ "run.py": ("python", "def run():\n graph = DependencyGraph()\n graph.add_arc(1)\n"),+ "a/graph.py": ("python", graph),+ "b/graph.py": ("python", graph),+ }+ assert self._resolved(tmp_path, files, "add_arc") == []++class TestImportedTypeThroughAReExport:"""An import binds the package, not the module that declares the type.@@ -1170,6 +1320,236 @@ class TestForeignReceiverTypes:assert populated == {"rust"}+class TestInheritedTypedReceiver:+ """A typed receiver whose type lacks the method reaches the one ancestor declaring it."""++ _PKG = "src/org/acme/"+ _BASE = (+ "package org.acme;\npublic class Base {\n"+ " public Object get(int i) { return null; }\n}\n"+ )+ _CHILD = "package org.acme;\npublic class Child extends Base {}\n"+ _GET = "src/org/acme/Base.java::Base::get"++ @staticmethod+ def _caller(head: str = "package org.acme;\n", cls: str = "Caller", method: str = "") -> str:+ return (+ f"{head}public class {cls} {{\n"+ f" public {method}Object run(Child c) {{\n return c.get(0);\n }}\n}}\n"+ )++ def _targets(+ self,+ tmp_path: Path,+ files: dict[str, str],+ parents: dict[str, set[str]] | None = None,+ language: str = "java",+ ) -> list[str]:+ """Callees of ``Caller``'s calls; *parents* stands in for the heritage phase.++ A Java file with no ``package`` line is put in ``org.acme``.+ """+ if language == "java":+ files = {"Base.java": self._BASE, "Child.java": self._CHILD, **files}+ files = {+ k: v if v.startswith("package") else "package org.acme;\n" + v+ for k, v in files.items()+ }+ parsed = _parse_all(tmp_path, {k: (language, v) for k, v in files.items()})+ _link_imports(parsed, {k: {"org.acme.Child": "Child.java"} for k in parsed})+ resolver = CallResolver(+ parsed,+ {k: set() for k in parsed},+ repo_path=str(tmp_path),+ heritage_parents=parents or {"Child.java::Child": {"Base.java::Base"}},+ )+ caller = next(k for k in files if "Caller" in k)+ return [rc.callee_id for rc in resolver.resolve_file(caller, parsed[caller].calls)]++ def test_an_inherited_method_resolves_to_the_ancestor(self, tmp_path: Path) -> None:+ files = {"Base.java": self._BASE, "Child.java": self._CHILD, "Caller.java": self._caller()}+ parsed = _parse_all(tmp_path, {self._PKG + k: ("java", v) for k, v in files.items()})+ resolver = CallResolver(+ parsed,+ {k: set() for k in parsed},+ repo_path=str(tmp_path),+ heritage_parents={self._PKG + "Child.java::Child": {self._PKG + "Base.java::Base"}},+ )+ caller = self._PKG + "Caller.java"+ assert [+ (rc.caller_id, rc.callee_id, rc.confidence, rc.origin)+ for rc in resolver.resolve_file(caller, parsed[caller].calls)+ ] == [(caller + "::Caller::run", self._GET, 0.75, "receiver_typed_global")]++ def test_the_nearest_superclass_declaration_wins(self, tmp_path: Path) -> None:+ mid = "public class Mid extends Base {\n public Object get(int i) { return 1; }\n}\n"+ iface = "public interface Getter {\n Object get(int i);\n}\n"+ child = "public class Child extends Mid implements Getter {}\n"+ parents = {+ "Child.java::Child": {"Mid.java::Mid", "Getter.java::Getter"},+ "Mid.java::Mid": {"Base.java::Base"},+ }+ files = {"Mid.java": mid, "Getter.java": iface, "Child.java": child}+ files["Caller.java"] = self._caller("")+ assert self._targets(tmp_path, files, parents) == ["Mid.java::Mid::get"]++ def test_two_declaring_interfaces_give_no_edge(self, tmp_path: Path) -> None:+ files = {+ "A.java": "public interface A {\n Object get(int i);\n}\n",+ "B.java": "public interface B {\n Object get(int i);\n}\n",+ "Child.java": "public interface Child extends A, B {}\n",+ "Caller.java": self._caller(""),+ }+ parents = {"Child.java::Child": {"A.java::A", "B.java::B"}}+ assert self._targets(tmp_path, files, parents) == []++ @pytest.mark.parametrize(+ "head",+ [+ pytest.param("package q;\nimport com.vendor.*;\n", id="vendor-wildcard"),+ pytest.param("package q;\n", id="other-package-no-import"),+ ],+ )+ def test_a_type_the_caller_cannot_see_gives_no_edge(self, tmp_path: Path, head: str) -> None:+ base = "package p;\n" + self._BASE.partition("\n")[2]+ child = "package p;\n" + self._CHILD.partition("\n")[2]+ files = {"Base.java": base, "Child.java": child, "Caller.java": self._caller(head)}+ assert self._targets(tmp_path, files) == []++ def test_a_single_type_import_makes_it_visible(self, tmp_path: Path) -> None:+ files = {"Caller.java": self._caller("package q;\nimport org.acme.Child;\n")}+ assert self._targets(tmp_path, files) == ["Base.java::Base::get"]++ @pytest.mark.parametrize(+ ("cls", "method"),+ [("Caller<Child>", ""), ("Caller", "<Child extends Comparable<Child>> ")],+ ids=["class-parameter", "method-parameter"],+ )+ def test_a_type_parameter_shadows_the_repo_type(+ self, tmp_path: Path, cls: str, method: str+ ) -> None:+ files = {"Caller.java": self._caller("", cls, method)}+ assert self._targets(tmp_path, files) == []++ def test_kotlin_does_not_walk_ancestors(self, tmp_path: Path) -> None:+ files = {+ "Base.kt": "open class Base {\n fun get(i: Int): Any? = null\n}\n",+ "Child.kt": "class Child : Base()\n",+ "Caller.kt": "fun run(c: Child): Any? {\n return c.get(0)\n}\n",+ }+ parents = {"Child.kt::Child": {"Base.kt::Base"}}+ assert self._targets(tmp_path, files, parents, language="kotlin") == []+++class TestJavaReceiverRecall:+ """Java receivers the typed tiers missed: an inherited field, ``super``, a cast."""++ def _targets(+ self, tmp_path: Path, body: str, head: str = "", members: str = "", mid: str | None = None+ ) -> list[tuple[str, str]]:+ """Callees of ``Sub``'s calls; a *mid* body puts ``b.Mid`` between ``Sub`` and ``Base``."""+ parent = "Base" if mid is None else "Mid"+ files = {+ "a/Base.java": "package a;\npublic class Base {\n protected Reader reader;\n"+ " protected Doc doc;\n public void m() {}\n}\n",+ "a/Reader.java": "package a;\npublic class Reader {\n public void consume() {}\n}\n",+ "a/Node.java": "package a;\npublic class Node {\n public void append() {}\n}\n",+ "a/Doc.java": "package a;\npublic class Doc extends Node {}\n",+ "b/Reader.java": "package b;\npublic class Reader {\n public void consume() {}\n}\n",+ "b/Mid.java": f"package b;\nimport a.Base;\npublic class Mid extends Base {{\n{mid}\n}}\n",+ "b/Sub.java": f"package b;\nimport a.Base;\n{head}public class Sub extends {parent} {{\n"+ f"{members}\n public void m() {{}}\n void go(Object o) {{\n {body}\n }}\n}}\n",+ }+ parsed = _parse_all(tmp_path, {k: ("java", v) for k, v in files.items()})+ _link_imports(parsed, {"b/Sub.java": {"a.Base": "a/Base.java", "a.Node": "a/Node.java"}})+ parents = {"b/Mid.java::Mid": {"a/Base.java::Base"}, "a/Doc.java::Doc": {"a/Node.java::Node"}}+ parents["b/Sub.java::Sub"] = {"a/Base.java::Base" if mid is None else "b/Mid.java::Mid"}+ resolver = CallResolver(+ parsed, {k: set() for k in parsed}, repo_path=str(tmp_path), heritage_parents=parents+ )+ calls = parsed["b/Sub.java"].calls+ return [(rc.callee_id, rc.origin) for rc in resolver.resolve_file("b/Sub.java", calls)]++ def test_an_inherited_field_is_typed_in_the_declaring_file(self, tmp_path: Path) -> None:+ """``Reader`` is ``a.Reader`` where ``Base`` declares it, not the caller's ``b.Reader``."""+ assert self._targets(tmp_path, "reader.consume();") == [+ ("a/Reader.java::Reader::consume", "receiver_field_same_package")+ ]++ def test_an_inherited_field_reaches_its_types_ancestor(self, tmp_path: Path) -> None:+ assert self._targets(tmp_path, "doc.append();") == [+ ("a/Node.java::Node::append", "receiver_field_global")+ ]++ def test_a_local_shadows_an_inherited_field(self, tmp_path: Path) -> None:+ assert self._targets(tmp_path, "Object reader = null; reader.consume();") == []++ def test_an_untyped_lambda_parameter_shadows_an_inherited_field(self, tmp_path: Path) -> None:+ assert self._targets(tmp_path, "run(reader -> reader.consume());") == []++ @pytest.mark.parametrize(+ ("body", "members"),+ [+ ("b.Reader reader = null; reader.consume();", ""),+ ("var reader = 1; reader.consume();", ""),+ ("", " void f(b.Reader reader) { reader.consume(); }"),+ ("reader.consume();", " b.Reader reader;"),+ ("reader.consume();", " java.util.List<String> reader;"),+ ("reader.consume();", " int[] reader;"),+ ],+ ids=["qualified-local", "var-local", "qualified-parameter", "qualified-field",+ "qualified-generic-field", "primitive-array-field"],+ )+ def test_a_name_declared_with_an_unread_type_shadows_an_inherited_field(+ self, tmp_path: Path, body: str, members: str+ ) -> None:+ assert self._targets(tmp_path, body, members=members) == []++ def test_the_nearest_superclass_field_hides_the_rest(self, tmp_path: Path) -> None:+ """``Mid``'s ``reader`` is the package-``b`` one, wherever ``Base`` declares another."""+ mid = " protected Reader reader;"+ assert self._targets(tmp_path, "reader.consume();", mid=mid) == [+ ("b/Reader.java::Reader::consume", "receiver_field_same_package")+ ]++ def test_a_nearer_field_with_an_unread_type_stops_the_walk(self, tmp_path: Path) -> None:+ mid = " protected b.Reader reader;"+ assert self._targets(tmp_path, "reader.consume();", mid=mid) == []++ def test_super_skips_the_callers_own_override(self, tmp_path: Path) -> None:+ assert self._targets(tmp_path, "super.m();") == [("a/Base.java::Base::m", "self_inherited")]++ @pytest.mark.parametrize("cast", ["Node", "Node<String>"])+ def test_a_cast_names_its_receiver_type(self, tmp_path: Path, cast: str) -> None:+ body = f"(({cast}) o).append();"+ assert self._targets(tmp_path, body, "import a.Node;\n") == [+ ("a/Node.java::Node::append", "module_alias")+ ]++ def test_a_scoped_cast_type_is_not_captured(self, tmp_path: Path) -> None:+ source = "class Use {\n void go(Object o) {\n ((a.Node) o).append();\n }\n}\n"+ parsed = _parse_all(tmp_path, {"Use.java": ("java", source)})+ assert [c.receiver_name for c in parsed["Use.java"].calls] == [None]++ def test_an_intersection_cast_names_no_receiver(self, tmp_path: Path) -> None:+ """``(Node & Runnable) o`` names two types; taking either one would guess."""+ source = (+ "class Use {\n void go(Object o) {\n ((Node & Runnable) o).append();\n"+ " ((Node) o).append();\n }\n}\n"+ )+ parsed = _parse_all(tmp_path, {"Use.java": ("java", source)})+ assert sorted(+ (c.line, c.receiver_name or "") for c in parsed["Use.java"].calls+ ) == [(3, ""), (4, "Node")]++ @pytest.mark.xfail(strict=True, reason="`S.super.m()` arrives as `S.m()`; the qualifier is lost")+ def test_a_qualified_super_reaches_the_qualifiers_superclass(self, tmp_path: Path) -> None:+ members = " class In {\n void q() { Sub.super.m(); }\n }"+ assert self._targets(tmp_path, "", members=members) == [+ ("a/Base.java::Base::m", "self_inherited")+ ]++class TestOwnerAwareModuleTier:"""The module and import-name tiers pick an owner, not just a file.@@ -1529,34 +1909,30 @@ class TestExternalReceiverType:"receiver_typed_same_package",) in self._caller_edges(tmp_path, caller, **{"Outer.java": outer})- def test_a_generic_parameter_is_not_refused(self, tmp_path: Path) -> None:- """``T`` is unknown, not external: the name tiers still answer."""+ # Unknown rather than external, so not refused; a Java member call still+ # has no bare-name reading to fall back to.+ def test_a_generic_parameter_gets_no_bare_name_edge(self, tmp_path: Path) -> None:caller = self._caller("","Object o) {\n return run2(o);\n }\n"" public <T> Object run2(T x) {\n return x.get(0);",)- assert [e[1] for e in self._caller_edges(tmp_path, caller) if e[1].endswith("::get")] == [- "src/org/acme/TagSet.java::TagSet::get"- ]+ assert not [e for e in self._caller_edges(tmp_path, caller) if e[1].endswith("::get")]- def test_a_wildcard_imported_unknown_type_is_not_refused(self, tmp_path: Path) -> None:+ def test_a_wildcard_imported_unknown_type_gets_no_bare_name_edge(+ self, tmp_path: Path+ ) -> None:caller = self._caller("import com.vendor.*;\n", "Widget w) {\n return w.get(0);")- assert [e[1] for e in self._caller_edges(tmp_path, caller)] == [- "src/org/acme/TagSet.java::TagSet::get"- ]-- def test_an_unresolved_import_of_a_repo_type_is_not_refused(self, tmp_path: Path) -> None:- """No import-resolution phase runs here, so the import reads as external.+ assert self._caller_edges(tmp_path, caller) == []- The repo declaring the name is what keeps it from being refused.- """+ def test_an_unresolved_import_of_a_repo_type_gets_no_bare_name_edge(+ self, tmp_path: Path+ ) -> None:+ """No import-resolution phase runs here, so the import reads as external."""caller = self._caller("import org.acme.TagSet;\n", "TagSet t) {\n return t.get(0);")- assert [e[1] for e in self._caller_edges(tmp_path, caller)] == [- "src/org/acme/TagSet.java::TagSet::get"- ]+ assert self._caller_edges(tmp_path, caller) == []def test_only_java_records_builtin_declarations(self) -> None:from repowise.core.ingestion.languages.receiver_types import (diff --git a/tests/unit/ingestion/test_enclosing_class_calls.py b/tests/unit/ingestion/test_enclosing_class_calls.pyindex c34e2cbbb..eec74b390 100644--- a/tests/unit/ingestion/test_enclosing_class_calls.py+++ b/tests/unit/ingestion/test_enclosing_class_calls.py@@ -262,12 +262,22 @@ class TestReceiverlessTwin:f"data.set(str) must reach TokenData only; edges: {edges}")- def test_an_untyped_receiver_falls_back_to_the_bare_name(self, tmp_path: Path) -> None:+ def test_an_untyped_receiver_gets_no_bare_name_edge(self, tmp_path: Path) -> None:parsed = _parse_all(tmp_path, {"src/A.java": ("java", JAVA_UNTYPED_RECEIVER)})edges = _edges(parsed, tmp_path)- assert ("src/A.java::A::count", "src/A.java::Box::size", 0.95, "same_file") in edges, (- f"o.size() must keep its bare-name edge; edges: {edges}"- )+ assert _targets_of(edges, "::A::count") == [], f"o.size() is not Box::size; edges: {edges}"++ def test_a_chain_of_unknown_return_type_gets_no_bare_name_edge(self, tmp_path: Path) -> None:+ source = JAVA_UNTYPED_RECEIVER.replace("return o.size();", "return make(o).size();")+ parsed = _parse_all(tmp_path, {"src/A.java": ("java", source)})+ assert _targets_of(_edges(parsed, tmp_path), "::A::count") == []++ def test_a_ruby_untyped_receiver_keeps_the_bare_name(self, tmp_path: Path) -> None:+ source = RUBY_POOL.replace("close(conn)", "conn.close(1)")+ parsed = _parse_all(tmp_path, {"lib/pool.rb": ("ruby", source)})+ edges = _edges(parsed, tmp_path)+ assert parsed["lib/pool.rb"].calls[0].bare_name_fallback+ assert _targets_of(edges, "::drain") == ["lib/pool.rb::Pool::close"], edgesdef test_a_bare_call_on_its_twins_line_still_resolves(self, tmp_path: Path) -> None:"""``helper(b.helper(1))``: the outer call is a genuine implicit receiver."""diff --git a/tests/unit/ingestion/test_return_type_chain_resolution.py b/tests/unit/ingestion/test_return_type_chain_resolution.pyindex 7ad475b7d..b782453a2 100644--- a/tests/unit/ingestion/test_return_type_chain_resolution.py+++ b/tests/unit/ingestion/test_return_type_chain_resolution.py@@ -99,7 +99,7 @@ def test_return_type_chain_retargets_to_declared_type(assert after[0].origin.startswith("return_type_")-def test_java_unknown_member_preserves_legacy_fallback(tmp_path: Path) -> None:+def test_java_unknown_member_gets_no_bare_name_edge(tmp_path: Path) -> None:source = ("class Product {} class Wrong { void run() {} } ""class Use { Product make() { return new Product(); } void go() { make().run(); } }"@@ -118,11 +118,11 @@ def test_java_unknown_member_preserves_legacy_fallback(tmp_path: Path) -> None:"Example.java", [call])- assert len(before) == 1- assert after == before+ assert before == []+ assert after == []-def test_java_ambiguous_overload_return_preserves_legacy_fallback(tmp_path: Path) -> None:+def test_java_ambiguous_overload_return_gets_no_edge(tmp_path: Path) -> None:source = ("class First { void run() {} }\nclass Second { void run() {} }\n""class Factory {\n First make(int value) { return new First(); }\n"@@ -143,7 +143,7 @@ def test_java_ambiguous_overload_return_preserves_legacy_fallback(tmp_path: Path"Example.java", [call])- assert after == before+ assert before == after == []def test_cpp_future_get_can_refuse_a_bare_name_fallback(tmp_path: Path) -> None:@@ -215,7 +215,7 @@ def test_unbound_global_return_type_preserves_legacy_fallback(def test_only_audited_lanes_are_enabled_by_default() -> None:- assert frozenset({"cpp", "csharp", "go"}) == PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGES+ assert frozenset({"cpp", "csharp", "go", "java"}) == PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGESdef test_module_level_chain_keeps_structural_receiver(tmp_path: Path) -> None:@@ -277,7 +277,11 @@ def test_java_external_chain_head_is_exempt_when_the_file_rebinds_the_name(is the claim stated as a test rather than as prose. Java imports resolve torepository files, so the file's import list is what separates the two."""- own = "package a;\npublic class Duration { public long toNanos() { return 0; } }\n"+ own = (+ "package a;\npublic class Duration {\n"+ " public static Duration ofSeconds(int s) { return null; }\n"+ " public long toNanos() { return 0; } }\n"+ )use = ("package b;\nimport a.Duration;\n""class Use { long go() { return Duration.ofSeconds(3).toNanos(); } }\n"@@ -293,7 +297,10 @@ def test_java_external_chain_head_is_exempt_when_the_file_rebinds_the_name(call = _java_chain_call(parsed, "b/Use.java", "toNanos")resolved = CallResolver(- parsed, {"b/Use.java": {"a/Duration.java"}}, repo_path=str(tmp_path)+ parsed,+ {"b/Use.java": {"a/Duration.java"}},+ repo_path=str(tmp_path),+ return_type_chain_languages=frozenset({"java"}),).resolve_file("b/Use.java", [call])assert len(resolved) == 1assert resolved[0].callee_id.endswith("::Duration::toNanos")@@ -314,9 +321,9 @@ def test_a_table_admits_only_its_own_lane(tmp_path: Path) -> None:parsed = _parse(tmp_path, "Example.java", "java", source)call = _java_chain_call(parsed, "Example.java", "run")- resolved = CallResolver(parsed, {}, repo_path=str(tmp_path)).resolve_file(- "Example.java", [call]- )+ resolved = CallResolver(+ parsed, {}, repo_path=str(tmp_path), return_type_chain_languages=frozenset()+ ).resolve_file("Example.java", [call])assert not any(edge.origin.startswith("return_type_") for edge in resolved)@@ -347,9 +354,9 @@ def test_java_external_chain_head_is_exempt_when_the_repo_declares_the_name(parsed.update(_parse(tmp_path, "a/Use.java", "java", use))call = _java_chain_call(parsed, "a/Use.java", "toNanos")- resolved = CallResolver(parsed, {}, repo_path=str(tmp_path)).resolve_file(- "a/Use.java", [call]- )+ resolved = CallResolver(+ parsed, {}, repo_path=str(tmp_path), return_type_chain_languages=frozenset({"java"})+ ).resolve_file("a/Use.java", [call])assert len(resolved) == 1assert resolved[0].callee_id.endswith("::Duration::toNanos")