use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SignificantCodeRepository method toArray.
private static LineRange[] toArray(CloseableIterator<LineSgnificantCode> lineRanges, int numLines) {
LineRange[] ranges = new LineRange[numLines];
LineSgnificantCode currentLine = null;
for (int i = 0; i < numLines; i++) {
if (currentLine == null) {
if (!lineRanges.hasNext()) {
break;
}
currentLine = lineRanges.next();
}
if (currentLine.getLine() == i + 1) {
ranges[i] = new LineRange(currentLine.getStartOffset(), currentLine.getEndOffset());
currentLine = null;
}
}
return ranges;
}
use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SourceLinesHashRepositoryImplTest method SignificantCodeLineHashesComputer_delegates_after_taking_ranges_into_account.
@Test
public void SignificantCodeLineHashesComputer_delegates_after_taking_ranges_into_account() {
LineRange[] lineRanges = { new LineRange(0, 1), null, new LineRange(1, 5), new LineRange(2, 7), new LineRange(4, 5) };
SourceLineHashesComputer lineHashComputer = mock(SourceLineHashesComputer.class);
SignificantCodeLineHashesComputer computer = new SignificantCodeLineHashesComputer(lineHashComputer, lineRanges);
computer.addLine("testline");
computer.addLine("testline");
computer.addLine("testline");
computer.addLine("testline");
computer.addLine("testline");
computer.addLine("testline");
verify(lineHashComputer).addLine("t");
// there is an extra line at the end which will be ignored since there is no range for it
verify(lineHashComputer, times(2)).addLine("");
verify(lineHashComputer).addLine("estl");
verify(lineHashComputer).addLine("stlin");
verify(lineHashComputer).addLine("l");
verifyNoMoreInteractions(lineHashComputer);
}
use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SourceLinesHashRepositoryImplTest method should_return_version_of_line_hashes_with_significant_code_in_the_report.
@Test
public void should_return_version_of_line_hashes_with_significant_code_in_the_report() {
LineRange[] lineRanges = { new LineRange(0, 1), null, new LineRange(1, 5) };
when(significantCodeRepository.getRangesPerLine(file)).thenReturn(Optional.of(lineRanges));
assertThat(underTest.getLineHashesVersion(file)).isEqualTo(LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue());
verify(significantCodeRepository).getRangesPerLine(file);
verifyNoMoreInteractions(significantCodeRepository);
verifyZeroInteractions(dbLineHashVersion);
}
use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SourceLinesHashRepositoryImplTest method should_persist_with_significant_code_from_cache_if_possible.
@Test
public void should_persist_with_significant_code_from_cache_if_possible() {
List<String> lineHashes = Lists.newArrayList("line1", "line2", "line3");
LineRange[] lineRanges = { new LineRange(0, 1), null, new LineRange(1, 5) };
sourceLinesHashCache.computeIfAbsent(file, c -> lineHashes);
when(dbLineHashVersion.hasLineHashesWithoutSignificantCode(file)).thenReturn(false);
when(significantCodeRepository.getRangesPerLine(file)).thenReturn(Optional.of(lineRanges));
LineHashesComputer hashesComputer = underTest.getLineHashesComputerToPersist(file);
assertThat(hashesComputer).isInstanceOf(CachedLineHashesComputer.class);
assertThat(hashesComputer.getResult()).isEqualTo(lineHashes);
}
use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SourceLinesHashRepositoryImplTest method should_create_hash_with_significant_code.
@Test
public void should_create_hash_with_significant_code() {
LineRange[] lineRanges = { new LineRange(0, 1), null, new LineRange(1, 5) };
when(dbLineHashVersion.hasLineHashesWithSignificantCode(file)).thenReturn(true);
when(significantCodeRepository.getRangesPerLine(file)).thenReturn(Optional.of(lineRanges));
List<String> lineHashes = underTest.getLineHashesMatchingDBVersion(file);
assertLineHashes(lineHashes, "l", "", "ine3");
verify(dbLineHashVersion).hasLineHashesWithoutSignificantCode(file);
verifyNoMoreInteractions(dbLineHashVersion);
verify(significantCodeRepository).getRangesPerLine(file);
verifyNoMoreInteractions(significantCodeRepository);
}
Aggregations