From 822c74e7379b8354990e3a3605793d85b1803130 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 8 Oct 2021 13:33:26 +0200 Subject: [PATCH] SONAR-15487 add quickfix flag in plugin-api --- .../sensor/issue/internal/DefaultIssue.java | 12 ++++++++++ .../issue/internal/DefaultIssueTest.java | 24 +++++++++++++++---- .../sonar/api/batch/sensor/issue/Issue.java | 6 +++++ .../api/batch/sensor/issue/NewIssue.java | 6 +++++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index 00b0db6392c..ffa35e49945 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -37,6 +37,7 @@ public class DefaultIssue extends AbstractDefaultIssue implements private RuleKey ruleKey; private Double gap; private Severity overriddenSeverity; + private boolean quickFixAvailable = false; public DefaultIssue(DefaultInputProject project) { this(project, null); @@ -68,6 +69,17 @@ public class DefaultIssue extends AbstractDefaultIssue implements return this; } + @Override + public DefaultIssue setQuickFixAvailable(boolean quickFixAvailable) { + this.quickFixAvailable = quickFixAvailable; + return this; + } + + @Override + public boolean isQuickFixAvailable() { + return quickFixAvailable; + } + @Override public Severity overriddenSeverity() { return this.overriddenSeverity; diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java index 86ca1fff7bf..25199bd9509 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java @@ -26,16 +26,14 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.rule.Severity; -import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.rule.RuleKey; import org.sonar.api.batch.fs.internal.DefaultInputDir; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation; +import org.sonar.api.batch.rule.Severity; +import org.sonar.api.batch.sensor.internal.SensorStorage; +import org.sonar.api.rule.RuleKey; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -156,4 +154,20 @@ public class DefaultIssueTest { verify(storage).store(issue); } + @Test + public void default_issue_has_no_quickfix() { + SensorStorage storage = mock(SensorStorage.class); + DefaultIssue issue = new DefaultIssue(project, storage); + + assertThat(issue.isQuickFixAvailable()).isFalse(); + } + + @Test + public void issue_can_have_quickfix() { + SensorStorage storage = mock(SensorStorage.class); + DefaultIssue issue = new DefaultIssue(project, storage).setQuickFixAvailable(true); + + assertThat(issue.isQuickFixAvailable()).isTrue(); + } + } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java index 839f44f7fdb..a8c39285311 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java @@ -63,4 +63,10 @@ public interface Issue extends IIssue { */ @Override List flows(); + + /** + * Is there a QuickFix available in SonarLint for this issue + * @since 9.2 + */ + boolean isQuickFixAvailable(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java index 7f065925220..3655444dc02 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java @@ -60,6 +60,12 @@ public interface NewIssue { */ NewIssue addLocation(NewIssueLocation secondaryLocation); + /** + * Register if a QuickFix would be available on SonarLint for this issue. + * @since 9.2 + */ + NewIssue setQuickFixAvailable(boolean quickFixAvailable); + /** * Register a flow for this issue. A flow is an ordered list of issue locations that help to understand the issue. * It should be a path that backtracks the issue from its primary location to the start of the flow. -- 2.39.5