use of org.sonar.api.source.Symbol in project sonarqube by SonarSource.
the class SymbolReferencesSensor method processLine.
private static void processLine(File symbolFile, int lineNumber, Symbolizable.SymbolTableBuilder symbolTableBuilder, String line) {
try {
Iterator<String> split = Splitter.on(",").split(line).iterator();
Symbol s = addSymbol(symbolTableBuilder, split.next());
while (split.hasNext()) {
addReference(symbolTableBuilder, s, split.next());
}
} catch (Exception e) {
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + symbolFile.getAbsolutePath(), e);
}
}
use of org.sonar.api.source.Symbol 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);
}
use of org.sonar.api.source.Symbol in project sonarqube by SonarSource.
the class DefaultSymbolizableTest method should_update_cache_when_done.
@Test
public void should_update_cache_when_done() {
DefaultSensorStorage sensorStorage = mock(DefaultSensorStorage.class);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata(Strings.repeat("azerty\n", 20)).build();
DefaultSymbolizable symbolPerspective = new DefaultSymbolizable(inputFile, sensorStorage, mock(AnalysisMode.class));
Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolPerspective.newSymbolTableBuilder();
Symbol firstSymbol = symbolTableBuilder.newSymbol(4, 8);
symbolTableBuilder.newReference(firstSymbol, 12);
symbolTableBuilder.newReference(firstSymbol, 70);
Symbol otherSymbol = symbolTableBuilder.newSymbol(25, 33);
symbolTableBuilder.newReference(otherSymbol, 44);
symbolTableBuilder.newReference(otherSymbol, 60);
symbolTableBuilder.newReference(otherSymbol, 108);
Symbolizable.SymbolTable symbolTable = symbolTableBuilder.build();
symbolPerspective.setSymbolTable(symbolTable);
ArgumentCaptor<DefaultSymbolTable> argCaptor = ArgumentCaptor.forClass(DefaultSymbolTable.class);
verify(sensorStorage).store(argCaptor.capture());
// Map<Symbol, Set<TextRange>>
assertThat(argCaptor.getValue().getReferencesBySymbol().keySet()).hasSize(2);
}
use of org.sonar.api.source.Symbol in project sonarqube by SonarSource.
the class DeprecatedDefaultSymbolTableTest method should_reject_reference_conflicting_with_declaration.
@Test
public void should_reject_reference_conflicting_with_declaration() {
throwable.expect(IllegalArgumentException.class);
Symbolizable.SymbolTableBuilder symbolTableBuilder = new DeprecatedDefaultSymbolTable.Builder(new DefaultSymbolTable(null).onFile(inputFile));
Symbol symbol = symbolTableBuilder.newSymbol(10, 20);
symbolTableBuilder.newReference(symbol, 15);
}
use of org.sonar.api.source.Symbol in project sonarqube by SonarSource.
the class DeprecatedDefaultSymbolTableTest method variable_length_references.
@Test
public void variable_length_references() {
Symbolizable.SymbolTableBuilder symbolTableBuilder = new DeprecatedDefaultSymbolTable.Builder(new DefaultSymbolTable(null).onFile(inputFile));
Symbol firstSymbol = symbolTableBuilder.newSymbol(10, 20);
symbolTableBuilder.newReference(firstSymbol, 32);
symbolTableBuilder.newReference(firstSymbol, 44, 47);
DeprecatedDefaultSymbolTable symbolTable = (DeprecatedDefaultSymbolTable) symbolTableBuilder.build();
assertThat(symbolTable.getWrapped().getReferencesBySymbol().keySet()).containsExactly(range(10, 20));
Set<TextRange> references = symbolTable.getWrapped().getReferencesBySymbol().get(range(10, 20));
assertThat(references).containsExactly(range(32, 42), range(44, 47));
}
Aggregations