#!/usr/bin/env python3 """Scan *.java for block comments in the last N lines (tail noise / orphan */). Read-only.""" from __future__ import annotations import sys from pathlib import Path TAIL_LINES = 50 REPO = Path(__file__).resolve().parent.parent def main() -> int: suspicious: list[tuple[Path, str]] = [] with_slash: list[Path] = [] for p in REPO.rglob("*.java"): sp = str(p) if "/target/" in sp: continue try: t = p.read_text(encoding="utf-8", errors="replace") except OSError: continue lines = t.splitlines() if not lines: continue tail = "\n".join(lines[-TAIL_LINES:]) if "/*" in tail or "*/" in tail: with_slash.append(p) low = tail.lower() if "location" in low and "/*" in tail: suspicious.append((p, "Location in tail block")) if "jd-core" in low or "jd core" in low: suspicious.append((p, "jd-core in tail")) if "decompil" in low and "/*" in tail: suspicious.append((p, "decompil+block in tail")) # Trailing */ only: last non-empty line is */ nonws = [ln for ln in lines[-20:] if ln.strip()] if len(nonws) >= 1 and nonws[-1].strip() == "*/" and "/**" not in "\n".join(lines[-5:]): # might be orphan closer (rare) if "*/" in tail and tail.count("/*") < tail.count("*/"): suspicious.append((p, "possible orphan */ at EOF")) print(f"Scanned under {REPO}") print(f"Files with /* or */ in last {TAIL_LINES} lines: {len(with_slash)}") print(f"Flagged suspicious: {len(suspicious)}") for p, reason in suspicious[:80]: print(f" {reason}: {p.relative_to(REPO)}") if len(suspicious) > 80: print(f" ... and {len(suspicious) - 80} more") return 0 if __name__ == "__main__": sys.exit(main())