aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/issue/filter/FilterableIssue.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java15
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java10
3 files changed, 36 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/issue/filter/FilterableIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/issue/filter/FilterableIssue.java
index 5192d27352e..c5bc91d5815 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/issue/filter/FilterableIssue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/issue/filter/FilterableIssue.java
@@ -22,6 +22,7 @@ package org.sonar.api.scan.issue.filter;
import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.ThreadSafe;
+import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.rule.RuleKey;
/**
@@ -38,10 +39,21 @@ public interface FilterableIssue {
String message();
+ /**
+ * @deprecated since 7.2. Use {@link #textRange() instead}.
+ */
+
+ @Deprecated
@CheckForNull
Integer line();
/**
+ * @since 7.2
+ */
+ @CheckForNull
+ TextRange textRange();
+
+ /**
* @deprecated since 5.5 use {@link #gap()}
*/
@Deprecated
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
index 58ca9cfb488..b1b9cbc0477 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
@@ -26,7 +26,10 @@ import javax.annotation.concurrent.ThreadSafe;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.batch.fs.InputModule;
+import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultTextPointer;
+import org.sonar.api.batch.fs.internal.DefaultTextRange;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.scan.issue.filter.FilterableIssue;
import org.sonar.scanner.ProjectAnalysisInfo;
@@ -66,12 +69,24 @@ public class DefaultFilterableIssue implements FilterableIssue {
return rawIssue.getMsg();
}
+ @Deprecated
@Override
public Integer line() {
return rawIssue.hasTextRange() ? rawIssue.getTextRange().getStartLine() : null;
}
@Override
+ public TextRange textRange() {
+ if (!rawIssue.hasTextRange()) {
+ return null;
+ }
+
+ return new DefaultTextRange(
+ new DefaultTextPointer(rawIssue.getTextRange().getStartLine(), rawIssue.getTextRange().getStartOffset()),
+ new DefaultTextPointer(rawIssue.getTextRange().getEndLine(), rawIssue.getTextRange().getEndOffset()));
+ }
+
+ @Override
public Double gap() {
return rawIssue.getGap() != 0 ? rawIssue.getGap() : null;
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java
index 15758ce5825..b7cba5eb550 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java
@@ -50,7 +50,11 @@ public class DefaultFilterableIssueTest {
Issue.Builder builder = Issue.newBuilder();
builder.setGap(3.0);
- builder.setTextRange(TextRange.newBuilder().setStartLine(30));
+ builder.setTextRange(TextRange.newBuilder()
+ .setStartLine(30)
+ .setStartOffset(10)
+ .setEndLine(31)
+ .setEndOffset(3));
builder.setSeverity(Severity.MAJOR);
return builder.build();
}
@@ -72,6 +76,10 @@ public class DefaultFilterableIssueTest {
assertThat(issue.componentKey()).isEqualTo(componentKey);
assertThat(issue.creationDate()).isEqualTo(new Date(10_000));
assertThat(issue.line()).isEqualTo(30);
+ assertThat(issue.textRange().start().line()).isEqualTo(30);
+ assertThat(issue.textRange().start().lineOffset()).isEqualTo(10);
+ assertThat(issue.textRange().end().line()).isEqualTo(31);
+ assertThat(issue.textRange().end().lineOffset()).isEqualTo(3);
assertThat(issue.projectKey()).isEqualTo("projectKey");
assertThat(issue.effortToFix()).isEqualTo(3.0);
assertThat(issue.severity()).isEqualTo("MAJOR");