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): give Java record accessors a return type so chains through them resolve (#4820)
Swati Ahuja4383908731d6
diff --git a/packages/core/src/repowise/core/ingestion/extractors/synthetic_symbols/java_records.py b/packages/core/src/repowise/core/ingestion/extractors/synthetic_symbols/java_records.pyindex 6f90f51e7..e2dca3f21 100644--- a/packages/core/src/repowise/core/ingestion/extractors/synthetic_symbols/java_records.py+++ b/packages/core/src/repowise/core/ingestion/extractors/synthetic_symbols/java_records.py@@ -92,11 +92,12 @@ def java_record_synthetic_symbols(visibility=ctor_visibility,))- # Component accessors — same name as the component, zero args.+ # Component accessors: same name as the component, zero args. The+ # stored ``name() -> Type`` shape lets a call chain read the return.for comp_name, comp_type in components:out.append(build_synthetic_symbol(name=comp_name, kind="method",- signature=f"public {comp_type or 'Object'} {comp_name}()",+ signature=f"{comp_name}() -> {comp_type or 'Object'}",start_line=line, end_line=line,file_info=file_info, parent_name=record_name,))@@ -104,19 +105,19 @@ def java_record_synthetic_symbols(# Object-contract methods every record gets.out.append(build_synthetic_symbol(name="equals", kind="method",- signature="public boolean equals(Object)",+ signature="equals(Object o) -> boolean",start_line=line, end_line=line,file_info=file_info, parent_name=record_name,))out.append(build_synthetic_symbol(name="hashCode", kind="method",- signature="public int hashCode()",+ signature="hashCode() -> int",start_line=line, end_line=line,file_info=file_info, parent_name=record_name,))out.append(build_synthetic_symbol(name="toString", kind="method",- signature="public String toString()",+ signature="toString() -> String",start_line=line, end_line=line,file_info=file_info, parent_name=record_name,))diff --git a/tests/unit/ingestion/test_java_extractors.py b/tests/unit/ingestion/test_java_extractors.pyindex 30c2281f9..71da95ca7 100644--- a/tests/unit/ingestion/test_java_extractors.py+++ b/tests/unit/ingestion/test_java_extractors.py@@ -88,7 +88,7 @@ class TestJavaRecords:result = parser.parse_file(_file(), src)accessors = {s.name: s for s in result.symbols if s.kind == "method"}assert accessors["a"].visibility == "public"- assert accessors["a"].signature == "public int a()"+ assert accessors["a"].signature == "a() -> int"assert accessors["toString"].visibility == "public"diff --git a/tests/unit/ingestion/test_java_record_synthesis.py b/tests/unit/ingestion/test_java_record_synthesis.pynew file mode 100644index 000000000..445967677--- /dev/null+++ b/tests/unit/ingestion/test_java_record_synthesis.py@@ -0,0 +1,67 @@+"""Java record accessors carry their return type, so a chain through one resolves."""++from __future__ import annotations++from datetime import datetime+from pathlib import Path++from repowise.core.ingestion.call_resolver import CallResolver+from repowise.core.ingestion.models import FileInfo, ParsedFile+from repowise.core.ingestion.parser import parse_file+++def _parse(tmp_path: Path, rel: str, src: str) -> ParsedFile:+ f = tmp_path / rel+ f.parent.mkdir(parents=True, exist_ok=True)+ f.write_text(src)+ info = FileInfo(+ path=rel,+ abs_path=str(f),+ language="java",+ size_bytes=f.stat().st_size,+ git_hash="",+ last_modified=datetime.now(),+ is_test=False,+ is_config=False,+ is_api_contract=False,+ is_entry_point=False,+ )+ return parse_file(info, src.encode("utf-8"))+++_FILES = {+ "src/Interval.java": (+ "package p;\n"+ "public class Interval {\n"+ " public String format() { return \"\"; }\n"+ "}\n"+ ),+ "src/Polling.java": (+ "package p;\n"+ "public record Polling(Interval interval, String name) {}\n"+ ),+ "src/Use.java": (+ "package p;\n"+ "public class Use {\n"+ " String run(Polling polling) {\n"+ " return polling.interval().format();\n"+ " }\n"+ "}\n"+ ),+}+++def test_accessor_signature_declares_its_type(tmp_path: Path) -> None:+ pf = _parse(tmp_path, "src/Polling.java", _FILES["src/Polling.java"])+ sigs = {s.name: s.signature for s in pf.symbols}+ assert sigs["interval"] == "interval() -> Interval"+ assert sigs["toString"] == "toString() -> String"+ assert sigs["equals"] == "equals(Object o) -> boolean"+++def test_a_chain_through_an_accessor_resolves(tmp_path: Path) -> None:+ parsed = {rel: _parse(tmp_path, rel, src) for rel, src in _FILES.items()}+ resolver = CallResolver(parsed, {p: set() for p in parsed}, repo_path=str(tmp_path))+ callees = {rc.callee_id for rc in resolver.resolve_file("src/Use.java", parsed["src/Use.java"].calls)}+ assert "src/Polling.java::Polling::interval" in callees+ assert "src/Interval.java::Interval::format" in callees