use of org.sonar.api.source.Highlightable.HighlightingBuilder in project sonarqube by SonarSource.
the class SyntaxHighlightingSensor method processFileHighlighting.
private void processFileHighlighting(InputFile inputFile, SensorContext context) {
File ioFile = inputFile.file();
File highlightingFile = new File(ioFile.getParentFile(), ioFile.getName() + HIGHLIGHTING_EXTENSION);
if (highlightingFile.exists()) {
LOG.debug("Processing " + highlightingFile.getAbsolutePath());
try {
List<String> lines = FileUtils.readLines(highlightingFile, context.fileSystem().encoding().name());
int lineNumber = 0;
Highlightable highlightable = perspectives.as(Highlightable.class, inputFile);
if (highlightable != null) {
HighlightingBuilder highlightingBuilder = highlightable.newHighlighting();
for (String line : lines) {
lineNumber++;
if (StringUtils.isBlank(line) || line.startsWith("#")) {
continue;
}
processLine(highlightingFile, lineNumber, highlightingBuilder, line);
}
highlightingBuilder.done();
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
use of org.sonar.api.source.Highlightable.HighlightingBuilder in project sonarqube by SonarSource.
the class SyntaxHighlightingSensorTest method testExecution.
@Test
public void testExecution() throws IOException {
File symbol = new File(baseDir, "src/foo.xoo.highlighting");
FileUtils.write(symbol, "1:4:k\n12:15:cppd\n\n#comment");
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).initMetadata(" xoo\nazertyazer\nfoo").build();
context.fileSystem().add(inputFile);
Highlightable highlightable = mock(Highlightable.class);
when(perspectives.as(Highlightable.class, inputFile)).thenReturn(highlightable);
HighlightingBuilder builder = mock(Highlightable.HighlightingBuilder.class);
when(highlightable.newHighlighting()).thenReturn(builder);
sensor.execute(context);
verify(builder).highlight(1, 4, "k");
verify(builder).highlight(12, 15, "cppd");
verify(builder).done();
}
Aggregations