use of org.sonar.duplications.block.BlockChunker in project sonarqube by SonarSource.
the class JavaCpdBlockIndexer method createIndex.
private void createIndex(Iterable<InputFile> sourceFiles) {
TokenChunker tokenChunker = JavaTokenProducer.build();
StatementChunker statementChunker = JavaStatementBuilder.build();
BlockChunker blockChunker = new BlockChunker(BLOCK_SIZE);
for (InputFile inputFile : sourceFiles) {
LOG.debug("Populating index from {}", inputFile);
String resourceEffectiveKey = ((DefaultInputFile) inputFile).key();
List<Statement> statements;
try (InputStream is = new FileInputStream(inputFile.file());
Reader reader = new InputStreamReader(is, fs.encoding())) {
statements = statementChunker.chunk(tokenChunker.chunk(reader));
} catch (FileNotFoundException e) {
throw new IllegalStateException("Cannot find file " + inputFile.file(), e);
} catch (IOException e) {
throw new IllegalStateException("Exception handling file: " + inputFile.file(), e);
}
List<Block> blocks = blockChunker.chunk(resourceEffectiveKey, statements);
index.insert(inputFile, blocks);
}
}
use of org.sonar.duplications.block.BlockChunker in project sonarqube by SonarSource.
the class JavaDuplicationsFunctionalTest method addToIndex.
private static void addToIndex(CloneIndex index, String resourceId, String sourceCode) {
List<Statement> statements = STATEMENT_CHUNKER.chunk(TOKEN_CHUNKER.chunk(sourceCode));
BlockChunker blockChunker = new BlockChunker(2);
List<Block> blocks = blockChunker.chunk(resourceId, statements);
for (Block block : blocks) {
index.insert(block);
}
}
Aggregations