Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix: preserve Java and C# method return types (#1713)

nightcitybladeb86c1a27c27c
diff --git a/packages/core/src/repowise/core/ingestion/extractors/signatures.py b/packages/core/src/repowise/core/ingestion/extractors/signatures.py
index 5a553b8de..6d11c8489 100644
--- a/packages/core/src/repowise/core/ingestion/extractors/signatures.py
+++ b/packages/core/src/repowise/core/ingestion/extractors/signatures.py
@@ -43,8 +43,14 @@ def build_signature(node_type: str, name: str, params_text: str, def_node: Node,
# TypeScript/JavaScript class method
return f"{name}{params_text}{_ret(('return_type',))}"
if node_type == "method_declaration":
- # Go method: include receiver text and result type
recv_node = def_node.child_by_field_name("receiver")
+ declared_type_fields = ("type", "returns")
+ if recv_node is None and any(
+ def_node.child_by_field_name(field) is not None for field in declared_type_fields
+ ):
+ # Java/C#: the declared type is the return type; there is no method keyword.
+ return f"{name}{params_text}{_ret(declared_type_fields)}"
+ # Go method: include receiver text and result type.
recv_text = node_text(recv_node, src) if recv_node else ""
recv_prefix = f"{recv_text} " if recv_text else ""
return f"func {recv_prefix}{name}{params_text}{_ret(('result',))}"
diff --git a/tests/unit/ingestion/parser/test_method_signatures.py b/tests/unit/ingestion/parser/test_method_signatures.py
new file mode 100644
index 000000000..2f39f9f96
--- /dev/null
+++ b/tests/unit/ingestion/parser/test_method_signatures.py
@@ -0,0 +1,40 @@
+from __future__ import annotations
+
+import pytest
+
+from repowise.core.ingestion.parser import ASTParser
+from tests.unit.ingestion.parser._helpers import _make_file_info
+
+
+ ("path", "language", "source", "name", "expected"),
+ [
+ (
+ "Example.java",
+ "java",
+ b"class Example { V get(K key) { return null; } }",
+ "get",
+ "get(K key) -> V",
+ ),
+ (
+ "Example.cs",
+ "csharp",
+ b"class Example { V Get(K key) { return default; } }",
+ "Get",
+ "Get(K key) -> V",
+ ),
+ (
+ "example.go",
+ "go",
+ b'package example\ntype Example struct{}\nfunc (e *Example) Get(key string) (string, error) { return "", nil }',
+ "Get",
+ "func (e *Example) Get(key string) -> (string, error)",
+ ),
+ ],
+)
+def test_method_signature_uses_language_syntax(
+ parser: ASTParser, path: str, language: str, source: bytes, name: str, expected: str
+) -> None:
+ result = parser.parse_file(_make_file_info(path, language), source)
+ method = next(symbol for symbol in result.symbols if symbol.name == name)
+ assert method.signature == expected