Search in sources :

Example 1 with Symbol

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);
    }
}
Also used : Symbol(org.sonar.api.source.Symbol) IOException(java.io.IOException)

Example 2 with Symbol

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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Symbol(org.sonar.api.source.Symbol) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) Symbolizable(org.sonar.api.source.Symbolizable) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 3 with Symbol

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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Symbol(org.sonar.api.source.Symbol) DefaultSensorStorage(org.sonar.scanner.sensor.DefaultSensorStorage) AnalysisMode(org.sonar.api.batch.AnalysisMode) DefaultSymbolizable(org.sonar.scanner.source.DefaultSymbolizable) DefaultSymbolTable(org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable) Symbolizable(org.sonar.api.source.Symbolizable) DefaultSymbolizable(org.sonar.scanner.source.DefaultSymbolizable) Test(org.junit.Test)

Example 4 with Symbol

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);
}
Also used : Symbol(org.sonar.api.source.Symbol) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DeprecatedDefaultSymbolTable(org.sonar.scanner.source.DeprecatedDefaultSymbolTable) DefaultSymbolTable(org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable) Symbolizable(org.sonar.api.source.Symbolizable) Test(org.junit.Test)

Example 5 with Symbol

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));
}
Also used : Symbol(org.sonar.api.source.Symbol) DeprecatedDefaultSymbolTable(org.sonar.scanner.source.DeprecatedDefaultSymbolTable) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) TextRange(org.sonar.api.batch.fs.TextRange) DeprecatedDefaultSymbolTable(org.sonar.scanner.source.DeprecatedDefaultSymbolTable) DefaultSymbolTable(org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable) Symbolizable(org.sonar.api.source.Symbolizable) Test(org.junit.Test)

Aggregations

Symbol (org.sonar.api.source.Symbol)6 Test (org.junit.Test)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 Symbolizable (org.sonar.api.source.Symbolizable)5 DefaultSymbolTable (org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable)4 DeprecatedDefaultSymbolTable (org.sonar.scanner.source.DeprecatedDefaultSymbolTable)3 File (java.io.File)1 IOException (java.io.IOException)1 AnalysisMode (org.sonar.api.batch.AnalysisMode)1 InputFile (org.sonar.api.batch.fs.InputFile)1 TextRange (org.sonar.api.batch.fs.TextRange)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 DefaultSensorStorage (org.sonar.scanner.sensor.DefaultSensorStorage)1 DefaultSymbolizable (org.sonar.scanner.source.DefaultSymbolizable)1