use of org.sonar.api.source.Highlightable 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 in project sonarqube by SonarSource.
the class HighlightableBuilderTest method project_should_not_be_highlightable.
@Test
public void project_should_not_be_highlightable() {
HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class), mock(AnalysisMode.class));
Highlightable perspective = builder.loadPerspective(Highlightable.class, new DefaultInputModule("struts"));
assertThat(perspective).isNull();
}
use of org.sonar.api.source.Highlightable 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();
}
use of org.sonar.api.source.Highlightable in project sonarqube by SonarSource.
the class HighlightableBuilderTest method should_load_default_perspective.
@Test
public void should_load_default_perspective() {
HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class), mock(AnalysisMode.class));
Highlightable perspective = builder.loadPerspective(Highlightable.class, new TestInputFileBuilder("foo", "foo.c").build());
assertThat(perspective).isNotNull().isInstanceOf(DefaultHighlightable.class);
}
Aggregations