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
feat(dead-code): detect deprecated annotations (#1472)
Akshat malik1e7095af5f72
diff --git a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py b/packages/core/src/repowise/core/analysis/dead_code/analyzer.pyindex e2dc8993e..585255b64 100644--- a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py+++ b/packages/core/src/repowise/core/analysis/dead_code/analyzer.py@@ -68,6 +68,120 @@ _IDENTIFIER_RE = re.compile(rb"[A-Za-z_][A-Za-z0-9_]{2,}")_UNINDEXED_SCAN_PER_FILE_BYTES = 4 * 1024 * 1024_UNINDEXED_SCAN_TOTAL_BYTES = 32 * 1024 * 1024+# ---------------------------------------------------------------------------+# Deprecation detection+# ---------------------------------------------------------------------------++#: Normalised decorator/annotation bases (after stripping leading ``@`` and+#: any call-argument ``(…)`` tail) that signal a symbol is deprecated.+#:+#: Rust inner-attr form (``deprecated``), C# stripped form (``Obsolete``), and+#: C++ stripped form (``deprecated``) are included verbatim because the+#: respective sibling-walk extractors in ``parser.py`` already strip the+#: language-specific bracket pairs before storing.+_DEPRECATED_DECORATOR_BASES: frozenset[str] = frozenset(+ {+ # Python / TypeScript / Scala / Swift+ "deprecated",+ "typing.deprecated",+ "warnings.deprecated",+ # Java / Kotlin (case-sensitive annotation names)+ "Deprecated",+ "kotlin.Deprecated",+ "java.lang.Deprecated",+ # C# (inner attr text after stripping [ ])+ "Obsolete",+ "System.Obsolete",+ "System.ObsoleteAttribute",+ }+)+++#: Regex that strips quoted string literals from a decorator/annotation text+#: before splitting on ``@`` boundaries. Without this,+#: ``@app.route("/deprecated")`` would produce a token whose paren-stripped+#: base is ``app.route`` (correct), but a hypothetical annotation whose+#: *argument* contains ``@something`` would create a spurious token.+_QUOTED_STR_RE: re.Pattern[str] = re.compile(r'"[^"]*"')+++def _decorator_base(raw: str) -> str:+ """Return the normalised base name of a single decorator/annotation token.++ Strips a leading ``@``, trims whitespace, and drops any call-argument+ ``(…)`` tail. For multi-word tokens (e.g. a Java modifier blob fragment+ ``"Deprecated\n public"``) only the first whitespace-delimited word is+ kept, so visibility keywords that trail the annotation name are discarded.++ This function handles ONE token. Callers that receive multi-annotation+ blobs (Java/Kotlin ``modifiers`` node) must split on ``@`` first.+ """+ base = raw.lstrip("@").strip()+ paren = base.find("(")+ if paren >= 0:+ base = base[:paren].strip()+ else:+ # Handle trailing visibility keywords in modifier blobs:+ # "Deprecated\n public" → "Deprecated"+ parts = base.split()+ base = parts[0] if parts else base+ return base+++def _is_symbol_deprecated(sym_name: str, decorators: list[str]) -> bool:+ """Return True when the symbol is marked deprecated by name suffix or annotation.++ Two mechanisms are checked in order:++ 1. **Name suffix**: the name ends with ``_DEPRECATED``, ``_LEGACY``, or+ ``_COMPAT`` (original naming-convention check, preserved for backward+ compatibility).++ 2. **Decorator / annotation**: each entry in *decorators* is treated as a+ possibly multi-annotation modifier blob (Java/Kotlin ``modifiers`` node+ delivers all annotations concatenated with whitespace in a single+ string). Each entry is first cleaned of quoted substrings (to avoid+ matching paths like ``"/deprecated"`` inside ``@app.route("/deprecated")``),+ then split on ``@`` boundaries so every individual annotation is checked+ independently. Each token is normalised via :func:`_decorator_base` and+ tested against ``_DEPRECATED_DECORATOR_BASES`` and the lower-cased+ ``"deprecated"`` catch-all.++ The *decorators* list is produced by ``parser.py`` ``_extract_symbols``:+ - Python / Scala / Swift: full decorator text with leading ``@``+ (e.g. ``"@deprecated"``, ``"@typing.deprecated"``).+ - Java / Kotlin: full modifier-node text — one blob per declaration that+ may contain several annotations plus visibility keywords+ (e.g. ``"@Deprecated\n public"``,+ ``"@Override\n @Deprecated\n public"``).+ - Rust: inner attribute content stripped of ``#[…]``+ (e.g. ``"deprecated"`` from ``#[deprecated]``).+ - C#: inner attribute content stripped of ``[…]``+ (e.g. ``"Obsolete"`` from ``[Obsolete]``).+ - C++: inner attribute content stripped of ``[[…]]``+ (e.g. ``"deprecated"`` from ``[[deprecated]]``).+ """+ # 1. Name suffix+ if any(sym_name.endswith(s) for s in ("_DEPRECATED", "_LEGACY", "_COMPAT")):+ return True+ # 2. Decorator / annotation+ for raw in decorators:+ # Strip quoted strings first so path arguments like "/deprecated"+ # inside ``@app.route("/deprecated")`` do not create false tokens.+ cleaned = _QUOTED_STR_RE.sub('""', raw)+ # Split on '@' to tokenize modifier blobs. A leading '@' produces+ # an empty first element which the ``if not token`` guard discards.+ # No-'@' forms (Rust/C#/C++ inner attrs: "deprecated", "Obsolete")+ # yield a single token equal to the whole string.+ for token in cleaned.split("@"):+ token = token.strip()+ if not token:+ continue+ base = _decorator_base(token)+ if base in _DEPRECATED_DECORATOR_BASES or base.lower() == "deprecated":+ return True+ return False+# Symbol kinds that cannot be independently imported by name in any# supported language. Flagging them as "unused exports" is a guaranteed# false-positive — they're always accessed through an enclosing class /@@ -1102,11 +1216,6 @@ class DeadCodeAnalyzer:# suffix check sees the attribute path itself.decorators = sym.get("decorators", [])- def _decorator_base(d: str) -> str:- stripped = d.lstrip("@")- paren = stripped.find("(")- return stripped[:paren] if paren >= 0 else stripped-if any(_decorator_base(d).startswith(prefix)for d in decorators@@ -1151,8 +1260,8 @@ class DeadCodeAnalyzer:if local_refs and sym_name in local_refs:continue- is_deprecated = any(- sym_name.endswith(suffix) for suffix in ("_DEPRECATED", "_LEGACY", "_COMPAT")+ is_deprecated = _is_symbol_deprecated(+ sym_name, sym.get("decorators") or [])# ``export { local as alias }`` publishes the symbol under the@@ -1339,19 +1448,14 @@ class DeadCodeAnalyzer:decorators = node_data.get("decorators") or []if decorators:- def _dec_base(d: str) -> str:- stripped = d.lstrip("@")- paren = stripped.find("(")- return stripped[:paren] if paren >= 0 else stripped-if any(- _dec_base(d).startswith(prefix)+ _decorator_base(d).startswith(prefix)for d in decoratorsfor prefix in _FRAMEWORK_DECORATORS):continueif any(- _dec_base(d).endswith(suffix)+ _decorator_base(d).endswith(suffix)for d in decoratorsfor suffix in _FRAMEWORK_DECORATOR_SUFFIXES):@@ -1385,6 +1489,12 @@ class DeadCodeAnalyzer:continuegit_meta = self.git_meta_map.get(file_path, {})+ # Private symbols keep the standard 0.65 base confidence even if deprecated.+ # A private symbol has no external consumer by construction —+ # deprecated + uncalled is the strongest possible delete signal and+ # must not be buried below the default min_confidence floor.+ # (0.3 is reserved for unused *exports*, where an invisible consumer+ # outside the repo may still import it.)findings.append(DeadCodeFindingData(kind=DeadCodeKind.UNUSED_INTERNAL,diff --git a/packages/core/src/repowise/core/ingestion/parser.py b/packages/core/src/repowise/core/ingestion/parser.pyindex ff003233c..ecfb274e6 100644--- a/packages/core/src/repowise/core/ingestion/parser.py+++ b/packages/core/src/repowise/core/ingestion/parser.py@@ -581,6 +581,41 @@ class ASTParser:k -= 1break+ # C#: [Obsolete] / [System.Obsolete] are ``attribute_list`` nodes.+ # In tree-sitter-c-sharp the attribute_list is child[0] of the+ # declaration node itself (method_declaration, class_declaration, etc.),+ # NOT a preceding sibling in the class body. Iterate def_node.children+ # and collect attribute_list nodes until the first non-attribute child.+ # Strip the outer [ ] so the inner content matches the same+ # _DEPRECATED_DECORATOR_BASES the analyzer uses for every other lang.+ csharp_attrs: list[str] = []+ if file_info.language == "csharp":+ for child in def_node.children:+ if child.type != "attribute_list":+ break+ attr_text = _node_text(child, src).strip()+ # "[Obsolete]" → "Obsolete"+ if attr_text.startswith("[") and attr_text.endswith("]"):+ csharp_attrs.append(attr_text[1:-1])++ # C/C++: [[deprecated]] / [[deprecated("reason")]] are+ # ``attribute_declaration`` nodes. In tree-sitter-cpp the+ # attribute_declaration is child[0] of function_definition itself+ # (NOT a preceding sibling at translation_unit level). Iterate+ # def_node.children and collect attribute_declaration nodes until+ # the first non-attribute child.+ # Strip the outer [[ ]] so the inner content lands in the same+ # checker as the Rust and C# forms.+ cpp_attrs: list[str] = []+ if file_info.language in ("cpp", "c"):+ for child in def_node.children:+ if child.type != "attribute_declaration":+ break+ attr_text = _node_text(child, src).strip()+ # "[[deprecated]]" → "deprecated"+ if attr_text.startswith("[[") and attr_text.endswith("]]"):+ cpp_attrs.append(attr_text[2:-2])+visibility = config.visibility_fn(name, modifier_texts)is_exported_symbol = False# C/C++ visibility is dictated by AST context (access@@ -657,7 +692,12 @@ class ASTParser:start_line=start_line,end_line=end_line,docstring=docstring,- decorators=[m for m in modifier_texts if m.startswith("@")] + rust_attrs,+ decorators=(+ [m for m in modifier_texts if m.startswith("@")]+ + rust_attrs+ + csharp_attrs+ + cpp_attrs+ ),visibility=visibility, # type: ignore[arg-type]is_async=is_async,language=file_info.language,diff --git a/tests/unit/dead_code/test_deprecated_decorators.py b/tests/unit/dead_code/test_deprecated_decorators.pynew file mode 100644index 000000000..a95406336--- /dev/null+++ b/tests/unit/dead_code/test_deprecated_decorators.py@@ -0,0 +1,479 @@+"""Tests for _is_symbol_deprecated and its effect on confidence scoring.++The real deprecation signal in most codebases is an annotation, not a name+suffix. These tests verify that the full decorator surface (Python, Java/Kotlin,+Rust inner-attr, C# stripped attr, C++ stripped attr, Swift) is recognised and+lowers confidence to 0.3 — placing the finding below the default min_confidence+floor of 0.4 so it shows up in hidden_below_threshold rather than in the+returned findings.+"""++from __future__ import annotations++import pytest++from repowise.core.analysis.dead_code import DeadCodeAnalyzer+from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated+from tests.unit.dead_code._helpers import _build_graph, _old_date++# ---------------------------------------------------------------------------+# Unit tests for _is_symbol_deprecated+# ---------------------------------------------------------------------------+++class TestIsSymbolDeprecated:+ """Pure-function tests — no graph needed."""++ def test_name_suffix_DEPRECATED(self):+ assert _is_symbol_deprecated("process_data_DEPRECATED", []) is True++ def test_name_suffix_LEGACY(self):+ assert _is_symbol_deprecated("config_LEGACY", []) is True++ def test_name_suffix_COMPAT(self):+ assert _is_symbol_deprecated("parse_COMPAT", []) is True++ def test_python_at_deprecated(self):+ assert _is_symbol_deprecated("process_data", ["@deprecated"]) is True++ def test_python_typing_deprecated(self):+ assert _is_symbol_deprecated("process_data", ["@typing.deprecated"]) is True++ def test_python_warnings_deprecated(self):+ assert _is_symbol_deprecated("process_data", ["@warnings.deprecated"]) is True++ def test_java_Deprecated(self):+ # Java / Kotlin annotation — capital D+ assert _is_symbol_deprecated("processData", ["@Deprecated"]) is True++ def test_kotlin_Deprecated(self):+ assert _is_symbol_deprecated("processData", ["@kotlin.Deprecated"]) is True++ def test_scala_deprecated(self):+ assert _is_symbol_deprecated("processData", ["@deprecated"]) is True++ def test_swift_available_deprecated(self):+ # @available(*, deprecated) — call stripped, base is "available"+ # This should NOT match; the actual deprecated signal here is via the+ # argument — the helper only strips the outer call args.+ # Keeping this explicit so behaviour is documented.+ result = _is_symbol_deprecated("func", ["@available(*, deprecated)"])+ # "available" is not in _DEPRECATED_DECORATOR_BASES, so this is False.+ assert result is False++ def test_rust_inner_attr_no_at(self):+ # Rust: parser.py strips #[ ] and stores the inner content directly+ assert _is_symbol_deprecated("my_fn", ["deprecated"]) is True++ def test_rust_inner_attr_with_args(self):+ # #[deprecated(since = "1.0")] → "deprecated(since = \"1.0\")"+ assert _is_symbol_deprecated("my_fn", ['deprecated(since = "1.0")']) is True++ def test_csharp_Obsolete(self):+ # C#: parser.py strips [ ] and stores "Obsolete"+ assert _is_symbol_deprecated("MyMethod", ["Obsolete"]) is True++ def test_csharp_System_Obsolete(self):+ assert _is_symbol_deprecated("MyMethod", ["System.Obsolete"]) is True++ def test_csharp_Obsolete_with_message(self):+ # "[Obsolete(\"Use Foo instead\")]" → "Obsolete(\"Use Foo instead\")"+ assert _is_symbol_deprecated("MyMethod", ['Obsolete("Use Foo instead")']) is True++ def test_cpp_double_bracket_deprecated(self):+ # C++: parser.py strips [[ ]] and stores "deprecated"+ assert _is_symbol_deprecated("my_func", ["deprecated"]) is True++ def test_cpp_deprecated_with_reason(self):+ # [[deprecated("use bar() instead")]] → "deprecated(\"use bar() instead\")"+ assert _is_symbol_deprecated("my_func", ['deprecated("use bar() instead")']) is True++ def test_unrelated_decorator_is_not_deprecated(self):+ assert _is_symbol_deprecated("process_data", ["@property"]) is False+ assert _is_symbol_deprecated("process_data", ["@app.route"]) is False+ assert _is_symbol_deprecated("process_data", ["@staticmethod"]) is False++ def test_empty_decorators_no_suffix_is_not_deprecated(self):+ assert _is_symbol_deprecated("process_data", []) is False++ def test_multiple_decorators_one_deprecated(self):+ assert _is_symbol_deprecated("fn", ["@staticmethod", "@deprecated"]) is True+++# ---------------------------------------------------------------------------+# Integration tests — full analyzer path+# ---------------------------------------------------------------------------+++def _stale_file_node(name: str, *, symbols: list | None = None) -> dict:+ return {+ name: {+ "is_entry_point": False,+ "is_test": False,+ "is_api_contract": False,+ "symbol_count": 5,+ "symbols": symbols or [],+ }+ }+++def _stale_git_meta(name: str) -> dict:+ return {+ name: {+ "commit_count_90d": 0,+ "last_commit_at": _old_date(days=400),+ "age_days": 400,+ "primary_owner_name": None,+ }+ }+++def _symbol(name: str, decorators: list[str]) -> dict:+ return {+ "name": name,+ "kind": "function",+ "visibility": "public",+ "language": "python",+ "decorators": decorators,+ "start_line": 1,+ "end_line": 10,+ }+++class TestDeprecatedDecoratorIntegration:+ """End-to-end: the decorator reaches the confidence score via the analyzer."""++ def _run(self, decorator: str, min_confidence: float = 0.4) -> object:+ """Build a minimal graph with one deprecated export and run the analyzer."""+ g = _build_graph(+ nodes={+ **_stale_file_node(+ "pkg/utils.py",+ symbols=[_symbol("process_data", [decorator])],+ ),+ "pkg/caller.py": {+ "is_entry_point": False,+ "is_test": False,+ "is_api_contract": False,+ "symbol_count": 2,+ "symbols": [],+ },+ },+ edges=[("pkg/caller.py", "pkg/utils.py", {"edge_type": "imports"})],+ )+ git_meta = {**_stale_git_meta("pkg/utils.py"), **_stale_git_meta("pkg/caller.py")}+ analyzer = DeadCodeAnalyzer(g, git_meta_map=git_meta)+ return analyzer.analyze(+ {+ "detect_zombie_packages": False,+ "min_confidence": min_confidence,+ }+ )++ @pytest.mark.parametrize(+ "decorator",+ [+ "@deprecated",+ "@typing.deprecated",+ "@Deprecated",+ # Rust / C# / C++ inner-attr forms reach the graph without "@"+ "deprecated",+ "Obsolete",+ ],+ )+ def test_decorator_scores_confidence_0_3(self, decorator: str):+ report = self._run(decorator, min_confidence=0.0)+ deprecated_findings = [+ f for f in report.findings if f.symbol_name == "process_data"+ ]+ assert len(deprecated_findings) == 1, (+ f"Expected one finding for decorator {decorator!r}; got {deprecated_findings}"+ )+ assert deprecated_findings[0].confidence == pytest.approx(0.3), (+ f"Expected confidence=0.3 for decorator {decorator!r}; "+ f"got {deprecated_findings[0].confidence}"+ )++ @pytest.mark.parametrize(+ "decorator",+ [+ "@deprecated",+ "@Deprecated",+ "deprecated",+ "Obsolete",+ ],+ )+ def test_deprecated_decorator_hidden_under_default_floor(self, decorator: str):+ """Decorated symbols (confidence=0.3) fall below the 0.4 default floor."""+ report = self._run(decorator, min_confidence=0.4)+ deprecated_in_findings = [+ f for f in report.findings if f.symbol_name == "process_data"+ ]+ assert deprecated_in_findings == [], (+ f"Decorated symbol should not appear under default floor; "+ f"decorator={decorator!r}"+ )++ def test_unrelated_decorator_does_not_lower_confidence(self):+ report = self._run("@property", min_confidence=0.0)+ findings = [f for f in report.findings if f.symbol_name == "process_data"]+ assert len(findings) == 1+ assert findings[0].confidence != pytest.approx(0.3), (+ "@property should not lower confidence to 0.3"+ )++ def test_suffix_DEPRECATED_still_works_without_decorator(self):+ """Name-suffix detection (backward compat) is not broken by the new path."""+ g = _build_graph(+ nodes={+ **_stale_file_node(+ "pkg/utils.py",+ symbols=[_symbol("process_data_DEPRECATED", [])],+ ),+ "pkg/caller.py": {+ "is_entry_point": False,+ "is_test": False,+ "is_api_contract": False,+ "symbol_count": 2,+ "symbols": [],+ },+ },+ edges=[("pkg/caller.py", "pkg/utils.py", {"edge_type": "imports"})],+ )+ git_meta = {**_stale_git_meta("pkg/utils.py"), **_stale_git_meta("pkg/caller.py")}+ analyzer = DeadCodeAnalyzer(g, git_meta_map=git_meta)+ report = analyzer.analyze({"detect_zombie_packages": False, "min_confidence": 0.0})+ findings = [f for f in report.findings if f.symbol_name == "process_data_DEPRECATED"]+ assert len(findings) == 1+ assert findings[0].confidence == pytest.approx(0.3)+++# ---------------------------------------------------------------------------+# parse_file roundtrip tests — these are the tests the reviewer asked for.+# They call parse_file on a real code snippet per language and assert on+# symbol.decorators directly, proving the extraction path fires end-to-end+# rather than just testing the string normalization helper in isolation.+# ---------------------------------------------------------------------------+++class TestDeprecatedDecoratorParseFile:+ """parse_file roundtrip: decorator text lands in symbol.decorators."""++ def _parser(self):+ from repowise.core.ingestion.parser import ASTParser++ return ASTParser()++ def _make_file_info(self, path: str, language: str):+ from datetime import datetime++ from repowise.core.ingestion.models import FileInfo++ return FileInfo(+ path=path,+ abs_path=f"/tmp/{path}",+ language=language,+ size_bytes=100,+ git_hash="",+ last_modified=datetime.now(),+ is_test=False,+ is_config=False,+ is_api_contract=False,+ is_entry_point=False,+ )++ # ------------------------------------------------------------------+ # C# — [Obsolete] is child[0] of method_declaration+ # ------------------------------------------------------------------++ def test_csharp_obsolete_lands_in_decorators(self):+ src = b"""+using System;+public class Foo {+ [Obsolete("use Bar instead")]+ public void OldApi() { }++ public void NewApi() { }+}+"""+ fi = self._make_file_info("pkg/Foo.cs", "csharp")+ result = self._parser().parse_file(fi, src)+ old = next((s for s in result.symbols if s.name == "OldApi"), None)+ assert old is not None, "OldApi symbol not found"+ assert any("Obsolete" in d for d in old.decorators), (+ f"Expected 'Obsolete' in decorators; got {old.decorators}"+ )++ def test_csharp_obsolete_is_detected_as_deprecated(self):+ from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated++ src = b"""+using System;+public class Foo {+ [Obsolete("use Bar instead")]+ public void OldApi() { }+}+"""+ fi = self._make_file_info("pkg/Foo.cs", "csharp")+ result = self._parser().parse_file(fi, src)+ old = next((s for s in result.symbols if s.name == "OldApi"), None)+ assert old is not None+ assert _is_symbol_deprecated(old.name, old.decorators), (+ f"OldApi should be deprecated; decorators={old.decorators}"+ )++ def test_csharp_no_attribute_has_empty_decorators(self):+ src = b"""+public class Foo {+ public void NewApi() { }+}+"""+ fi = self._make_file_info("pkg/Foo.cs", "csharp")+ result = self._parser().parse_file(fi, src)+ new = next((s for s in result.symbols if s.name == "NewApi"), None)+ assert new is not None+ assert not any("Obsolete" in d for d in new.decorators)++ # ------------------------------------------------------------------+ # C++ — [[deprecated]] is child[0] of function_definition+ # ------------------------------------------------------------------++ def test_cpp_deprecated_lands_in_decorators(self):+ src = b'[[deprecated("use bar() instead")]] void old_api() { }\n'+ fi = self._make_file_info("pkg/api.cpp", "cpp")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "old_api"), None)+ assert sym is not None, "old_api symbol not found"+ assert any("deprecated" in d for d in sym.decorators), (+ f"Expected 'deprecated' in decorators; got {sym.decorators}"+ )++ def test_cpp_deprecated_is_detected_as_deprecated(self):+ from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated++ src = b"[[deprecated]] void old_api() { }\n"+ fi = self._make_file_info("pkg/api.cpp", "cpp")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "old_api"), None)+ assert sym is not None+ assert _is_symbol_deprecated(sym.name, sym.decorators), (+ f"old_api should be deprecated; decorators={sym.decorators}"+ )++ def test_cpp_no_attribute_has_empty_decorators(self):+ src = b"void new_api() { }\n"+ fi = self._make_file_info("pkg/api.cpp", "cpp")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "new_api"), None)+ assert sym is not None+ assert not any("deprecated" in d for d in sym.decorators)++ # ------------------------------------------------------------------+ # Java — bare @Deprecated (the most common real-world case)+ # ------------------------------------------------------------------++ def test_java_bare_deprecated_lands_in_decorators(self):+ """Regression: bare @Deprecated was silently ignored before blob tokenization."""+ src = b"""+public class Service {+ @Deprecated+ public void processData() { }++ public void newProcess() { }+}+"""+ fi = self._make_file_info("pkg/Service.java", "java")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "processData"), None)+ assert sym is not None, "processData symbol not found"+ assert sym.decorators, (+ f"processData should have non-empty decorators; got {sym.decorators}"+ )++ def test_java_bare_deprecated_is_detected_as_deprecated(self):+ """Regression: bare @Deprecated blob must match _is_symbol_deprecated."""+ from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated++ src = b"""+public class Service {+ @Deprecated+ public void processData() { }+}+"""+ fi = self._make_file_info("pkg/Service.java", "java")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "processData"), None)+ assert sym is not None+ assert _is_symbol_deprecated(sym.name, sym.decorators), (+ f"processData should be deprecated; decorators={sym.decorators}"+ )++ def test_java_deprecated_with_args_is_detected(self):+ from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated++ src = b"""+public class Service {+ @Deprecated(since = "3.2", forRemoval = true)+ public void processData() { }+}+"""+ fi = self._make_file_info("pkg/Service.java", "java")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "processData"), None)+ assert sym is not None+ assert _is_symbol_deprecated(sym.name, sym.decorators), (+ f"processData should be deprecated; decorators={sym.decorators}"+ )++ def test_java_override_plus_deprecated_is_detected(self):+ """Regression: @Override\\n @Deprecated\\n public blob — only second annotation matters."""+ from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated++ src = b"""+public class Service extends Base {+ @Override+ @Deprecated+ public void processData() { }+}+"""+ fi = self._make_file_info("pkg/Service.java", "java")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "processData"), None)+ assert sym is not None+ assert _is_symbol_deprecated(sym.name, sym.decorators), (+ f"processData should be deprecated; decorators={sym.decorators}"+ )++ def test_java_override_only_is_not_deprecated(self):+ from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated++ src = b"""+public class Service extends Base {+ @Override+ public void processData() { }+}+"""+ fi = self._make_file_info("pkg/Service.java", "java")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "processData"), None)+ assert sym is not None+ assert not _is_symbol_deprecated(sym.name, sym.decorators), (+ f"processData should NOT be deprecated; decorators={sym.decorators}"+ )++ # ------------------------------------------------------------------+ # Rust — #[deprecated] is a preceding sibling (existing behaviour preserved)+ # ------------------------------------------------------------------++ def test_rust_deprecated_still_works(self):+ """Rust attribute extraction was correct before; regression guard."""+ from repowise.core.analysis.dead_code.analyzer import _is_symbol_deprecated++ src = b'#[deprecated(since = "1.0", note = "use bar instead")]\npub fn old_api() {}\n'+ fi = self._make_file_info("pkg/lib.rs", "rust")+ result = self._parser().parse_file(fi, src)+ sym = next((s for s in result.symbols if s.name == "old_api"), None)+ assert sym is not None, "old_api symbol not found"+ assert _is_symbol_deprecated(sym.name, sym.decorators), (+ f"old_api should be deprecated; decorators={sym.decorators}"+ )