diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-02 12:01:17 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-02 12:01:17 +0100 |
commit | b1428a83957f5e16475cdb99a5da7a195776fb15 (patch) | |
tree | 7a82d4229759d99ffc32971994f0e55caed4ca51 | |
parent | 000da09563cf669ea0f3bbe81d7101c5ffe9736e (diff) | |
download | sonarqube-b1428a83957f5e16475cdb99a5da7a195776fb15.tar.gz sonarqube-b1428a83957f5e16475cdb99a5da7a195776fb15.zip |
SONAR-5827 Do not produce empty higlighting rules like 0,0,k
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java | 10 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java index dfdee4980b2..ae387199288 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java @@ -368,21 +368,25 @@ public class SourcePersister implements ScanPersister { private <G> void writeDataPerLine(long[] originalLineOffsets, G item, int globalStartOffset, int globalEndOffset, StringBuilder[] dataPerLine, int startLine, RangeItemWriter<G> writer) { int currentLineIdx = startLine; - // We know current rule starts on current line + // We know current item starts on current line long ruleStartOffsetCurrentLine = globalStartOffset; while (currentLineIdx < originalLineOffsets.length && globalEndOffset >= originalLineOffsets[currentLineIdx]) { - // rule continue on next line so write current line and continue on next line with same rule + // item continue on next line so write current line and continue on next line with same item writeItem(item, dataPerLine, currentLineIdx, ruleStartOffsetCurrentLine - originalLineOffsets[currentLineIdx - 1], originalLineOffsets[currentLineIdx] - originalLineOffsets[currentLineIdx - 1], writer); currentLineIdx++; ruleStartOffsetCurrentLine = originalLineOffsets[currentLineIdx - 1]; } - // Rule ends on current line + // item ends on current line writeItem(item, dataPerLine, currentLineIdx, ruleStartOffsetCurrentLine - originalLineOffsets[currentLineIdx - 1], globalEndOffset - originalLineOffsets[currentLineIdx - 1], writer); } private <G> void writeItem(G item, StringBuilder[] dataPerLine, int currentLineIdx, long startLineOffset, long endLineOffset, RangeItemWriter<G> writer) { + if (startLineOffset == endLineOffset) { + // Do not store empty items + return; + } if (dataPerLine[currentLineIdx - 1] == null) { dataPerLine[currentLineIdx - 1] = new StringBuilder(); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java index 0633c2ee5e8..52a6a9b2414 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java @@ -292,14 +292,14 @@ public class SourcePersisterTest extends AbstractDaoTestCase { .setOriginalLineOffsets(new long[] {0, 4, 7}); SyntaxHighlightingData highlighting = new SyntaxHighlightingDataBuilder() - .registerHighlightingRule(0, 3, TypeOfText.ANNOTATION) + .registerHighlightingRule(0, 4, TypeOfText.ANNOTATION) .registerHighlightingRule(4, 5, TypeOfText.COMMENT) .registerHighlightingRule(7, 16, TypeOfText.CONSTANT) .build(); String[] highlightingPerLine = sourcePersister.computeHighlightingPerLine(file, highlighting); - assertThat(highlightingPerLine).containsOnly("0,3,a", "0,1,cd", "0,9,c"); + assertThat(highlightingPerLine).containsOnly("0,4,a", "0,1,cd", "0,9,c"); } @Test |