From 4fb1577d39c91eb49f10686a9f07bcc7cac26cde Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Mon, 25 May 2026 12:05:06 +0000 Subject: [PATCH 1/2] feat(protocol): expose analyzer quick fixes in scan output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Engine.Issue has carried quickFixes() since sonarlint-core 11.x and the sonar-plugin-api has shipped the NewIssue.addQuickFix(...) builder for several major versions. Until now the daemon silently dropped them at the protocol-DTO boundary, leaving downstream consumers (the agent pipeline and the JSON CLI users) to guess at remediations. This change carries quick fixes end-to-end: Protocol DTOs (new) - TextEdit(startLine, startColumn, endLine, endColumn, replacement) — a single in-file replacement edit - FileEdit(filePath, edits) — all TextEdits a quick fix applies to one file; null-normalised and defensively copied - QuickFix(message, fileEdits) — an analyzer-supplied remediation, possibly spanning multiple files Issue DTO - Added List quickFixes field (compact ctor null-normalises and copies). A backwards-compatible 9-arg constructor delegates with List.of(), so the ~15 existing test call sites keep compiling. IssueMapper - mapQuickFixes(List, baseDir) translates the engine's QuickFix / ClientInputFileEdit / TextEdit tree into our DTOs, resolving each edit's target file path through the same resolveFilePath() the primary issue uses (so quick-fix paths share the baseDir-relative, '/'-separated convention). - The original 5-arg map(...) overload is preserved and delegates to a new 6-arg overload that takes the quickFixes list. Test coverage (356/356 pass, +20 new): - Per-DTO Jackson roundtrip + null-normalisation + defensive-copy contracts (TextEditTest x3, FileEditTest x5, QuickFixTest x5, IssueTest +3). - IssueMapperTest +3: single-edit roundtrip, empty list, multi-file. - AnalysisServiceTest +1: the existing UtilityClass.java fixture raises java:S1118; assert the resulting protocol Issue carries at least one QuickFix with one FileEdit + TextEdit, and that the quick-fix file path matches the issue's file path. This is the canary that proves the full daemon -> JSON pipeline emits real analyzer-supplied edits, not just the schema. JSON shape is additive: existing consumers that don't read .quickFixes remain unaffected; new consumers gain a per-issue remediation list. Targeting 0.3.0-SNAPSHOT (0.2.0 was tagged at HEAD of main). --- pom.xml | 2 +- .../sonarpredict/daemon/IssueMapper.java | 63 +++++++++++++-- .../sonarpredict/protocol/dto/FileEdit.java | 23 ++++++ .../sonarpredict/protocol/dto/Issue.java | 40 +++++++++- .../sonarpredict/protocol/dto/QuickFix.java | 27 +++++++ .../sonarpredict/protocol/dto/TextEdit.java | 24 ++++++ .../daemon/AnalysisServiceTest.java | 27 +++++++ .../sonarpredict/daemon/IssueMapperTest.java | 80 +++++++++++++++++++ .../protocol/dto/FileEditTest.java | 59 ++++++++++++++ .../sonarpredict/protocol/dto/IssueTest.java | 36 +++++++++ .../protocol/dto/QuickFixTest.java | 59 ++++++++++++++ .../protocol/dto/TextEditTest.java | 36 +++++++++ 12 files changed, 465 insertions(+), 11 deletions(-) create mode 100644 src/main/java/io/github/randomcodespace/sonarpredict/protocol/dto/FileEdit.java create mode 100644 src/main/java/io/github/randomcodespace/sonarpredict/protocol/dto/QuickFix.java create mode 100644 src/main/java/io/github/randomcodespace/sonarpredict/protocol/dto/TextEdit.java create mode 100644 src/test/java/io/github/randomcodespace/sonarpredict/protocol/dto/FileEditTest.java create mode 100644 src/test/java/io/github/randomcodespace/sonarpredict/protocol/dto/QuickFixTest.java create mode 100644 src/test/java/io/github/randomcodespace/sonarpredict/protocol/dto/TextEditTest.java diff --git a/pom.xml b/pom.xml index 135a623..1fa3a28 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.randomcodespace.sonarpredict sonar-predictor - 0.2.0-SNAPSHOT + 0.3.0-SNAPSHOT