use of org.sonar.api.source.Symbolizable in project sonarqube by SonarSource.
the class SymbolReferencesSensor method processFileSymbol.
private void processFileSymbol(InputFile inputFile, SensorContext context) {
File ioFile = inputFile.file();
File symbolFile = new File(ioFile.getParentFile(), ioFile.getName() + SYMBOL_EXTENSION);
if (symbolFile.exists()) {
LOG.debug("Processing " + symbolFile.getAbsolutePath());
try {
List<String> lines = FileUtils.readLines(symbolFile, context.fileSystem().encoding().name());
int lineNumber = 0;
Symbolizable symbolizable = perspectives.as(Symbolizable.class, inputFile);
if (symbolizable != null) {
Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolizable.newSymbolTableBuilder();
for (String line : lines) {
lineNumber++;
if (StringUtils.isBlank(line) || line.startsWith("#")) {
continue;
}
processLine(symbolFile, lineNumber, symbolTableBuilder, line);
}
symbolizable.setSymbolTable(symbolTableBuilder.build());
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
use of org.sonar.api.source.Symbolizable in project sonarqube by SonarSource.
the class SymbolReferencesSensorTest method testExecution.
@Test
public void testExecution() throws IOException {
File symbol = new File(baseDir, "src/foo.xoo.symbol");
FileUtils.write(symbol, "1:4,7\n12:15,23:33\n\n#comment");
InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
fileSystem.add(inputFile);
Symbolizable symbolizable = mock(Symbolizable.class);
when(perspectives.as(Symbolizable.class, inputFile)).thenReturn(symbolizable);
Symbolizable.SymbolTableBuilder symbolTableBuilder = mock(Symbolizable.SymbolTableBuilder.class);
when(symbolizable.newSymbolTableBuilder()).thenReturn(symbolTableBuilder);
Symbol symbol1 = mock(Symbol.class);
when(symbolTableBuilder.newSymbol(1, 4)).thenReturn(symbol1);
Symbol symbol2 = mock(Symbol.class);
when(symbolTableBuilder.newSymbol(12, 15)).thenReturn(symbol2);
sensor.execute(context);
verify(symbolTableBuilder).newSymbol(1, 4);
verify(symbolTableBuilder).newReference(symbol1, 7);
verify(symbolTableBuilder).newSymbol(12, 15);
verify(symbolTableBuilder).newReference(symbol2, 23, 33);
}
Aggregations