# -*- coding: utf-8 -*- """把误删的合法续行补回来。 上一版我用「上一行是否以 + 结尾」来判断孤立续行 —— 这条规则是错的。 合法的 Java 续行里,加号本来就在**续行开头**,上一行以一个方法调用或 字符串结尾,不带加号。所以合法的 3 行被误删了,只剩调试的 2 行该删。 这里精确补回那 3 行。 """ from __future__ import annotations import sys from pathlib import Path RELAY = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\android\src" r"\com\lanremote\watch\RelayTransport.java") # 要补回的续行:(触发上一行的特征, 要补的整行) REPAIRS = [ (' String body = "{\\"code\\":\\"" + Json.escape(pairingCode)', ' + "\\",\\"name\\":\\"" + Json.escape(clientName) + "\\"}";'), (' lastError = "连不上中转:" + exc.getClass().getSimpleName()', ' + (exc.getMessage() == null ? "" : " " + exc.getMessage());'), ] def main() -> int: lines = RELAY.read_text(encoding="utf-8").splitlines(keepends=True) out = [] fixed = 0 for line in lines: out.append(line) stripped = line.rstrip("\n") for trigger, addition in REPAIRS: if stripped == trigger: # 下一行是不是已经是续行?是就别重复插 out.append(addition + "\n") fixed += 1 break RELAY.write_text("".join(out), encoding="utf-8") print(f" 补回 {fixed} 行(期望 3 行)") text = RELAY.read_text(encoding="utf-8") if "[dbg]" in text: print(" [注意] 还有 [dbg] 残留") return 1 return 0 if __name__ == "__main__": sys.exit(main())