aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre <pierre.guillot@sonarsource.com>2021-10-08 13:33:26 +0200
committersonartech <sonartech@sonarsource.com>2021-10-13 20:03:34 +0000
commit822c74e7379b8354990e3a3605793d85b1803130 (patch)
tree169ede8e809438f5c10ce1c00ffc0d42fcb1c81a
parent6a8bc0c123bf5dd10f4eb73a0bcea47288269aa7 (diff)
downloadsonarqube-822c74e7379b8354990e3a3605793d85b1803130.tar.gz
sonarqube-822c74e7379b8354990e3a3605793d85b1803130.zip
SONAR-15487 add quickfix flag in plugin-api
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java12
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java24
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java6
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<DefaultIssue> implements
private RuleKey ruleKey;
private Double gap;
private Severity overriddenSeverity;
+ private boolean quickFixAvailable = false;
public DefaultIssue(DefaultInputProject project) {
this(project, null);
@@ -69,6 +70,17 @@ public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements
}
@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<Flow> 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
@@ -61,6 +61,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 <b>path that backtracks the issue from its primary location to the start of the flow</b>.
* Several flows can be registered.