use of org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method dont_save_for_test_files.
@Test
public void dont_save_for_test_files() {
DefaultInputFile testInputFile = new TestInputFileBuilder("foo", "src/Foo.java").setLines(2).setOriginalLineStartOffsets(new int[] { 0, 50 }).setOriginalLineEndOffsets(new int[] { 49, 100 }).setLastValidOffset(101).setType(InputFile.Type.TEST).build();
DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage).onFile(testInputFile).addToken(testInputFile.newRange(1, 2, 1, 5), "foo");
tokens.save();
verifyZeroInteractions(sensorStorage);
assertThat(tokens.getTokenLines()).isEmpty();
}
use of org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method handle_exclusions.
@Test
public void handle_exclusions() {
inputFile.setExcludedForDuplication(true);
DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage).onFile(inputFile).addToken(inputFile.newRange(1, 2, 1, 5), "foo");
tokens.save();
verifyZeroInteractions(sensorStorage);
assertThat(tokens.getTokenLines()).isEmpty();
}
use of org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method save_many_tokens.
@Test
public void save_many_tokens() {
DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage).onFile(inputFile).addToken(inputFile.newRange(1, 2, 1, 5), "foo").addToken(inputFile.newRange(1, 6, 1, 10), "bar").addToken(inputFile.newRange(1, 20, 1, 25), "biz").addToken(inputFile.newRange(2, 1, 2, 10), "next");
tokens.save();
verify(sensorStorage).store(tokens);
assertThat(tokens.getTokenLines()).extracting("value", "startLine", "hashCode", "startUnit", "endUnit").containsExactly(tuple("foobarbiz", 1, "foobarbiz".hashCode(), 1, 3), tuple("next", 2, "next".hashCode(), 4, 4));
}
use of org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method save_no_tokens.
@Test
public void save_no_tokens() {
DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage).onFile(inputFile);
tokens.save();
verify(sensorStorage).store(tokens);
assertThat(tokens.inputFile()).isEqualTo(inputFile);
}
use of org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(NewCpdTokens cpdTokens) {
DefaultCpdTokens defaultCpdTokens = (DefaultCpdTokens) cpdTokens;
DefaultInputFile inputFile = (DefaultInputFile) defaultCpdTokens.inputFile();
inputFile.setPublished(true);
PmdBlockChunker blockChunker = new PmdBlockChunker(getCpdBlockSize(inputFile.language()));
List<Block> blocks = blockChunker.chunk(inputFile.key(), defaultCpdTokens.getTokenLines());
index.insert(inputFile, blocks);
}
Aggregations