Search in sources :

Example 1 with NewSymbolTable

use of org.sonar.api.batch.sensor.symbol.NewSymbolTable in project sonarqube by SonarSource.

the class SensorContextTesterTest method duplicateSymbolReferences.

@Test(expected = UnsupportedOperationException.class)
public void duplicateSymbolReferences() {
    NewSymbolTable symbolTable = tester.newSymbolTable().onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build());
    symbolTable.newSymbol(1, 8, 1, 10);
    symbolTable.save();
    symbolTable = tester.newSymbolTable().onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build());
    symbolTable.newSymbol(1, 8, 1, 10);
    symbolTable.save();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) NewSymbolTable(org.sonar.api.batch.sensor.symbol.NewSymbolTable) Test(org.junit.Test)

Example 2 with NewSymbolTable

use of org.sonar.api.batch.sensor.symbol.NewSymbolTable in project sonarqube by SonarSource.

the class SensorContextTesterTest method testSymbolReferences.

@Test
public void testSymbolReferences() {
    assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull();
    NewSymbolTable symbolTable = tester.newSymbolTable().onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build());
    symbolTable.newSymbol(1, 8, 1, 10);
    symbolTable.newSymbol(1, 1, 1, 5).newReference(6, 9).newReference(1, 10, 1, 13);
    symbolTable.save();
    assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull();
    assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 8)).isEmpty();
    assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 3)).extracting("start.line", "start.lineOffset", "end.line", "end.lineOffset").containsExactly(tuple(1, 6, 1, 9), tuple(1, 10, 1, 13));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) NewSymbolTable(org.sonar.api.batch.sensor.symbol.NewSymbolTable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 NewSymbolTable (org.sonar.api.batch.sensor.symbol.NewSymbolTable)2