use of org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable in project sonarqube by SonarSource.
the class SensorContextTester method referencesForSymbolAt.
/**
* Return list of symbol references ranges for the symbol at a given position in a file.
* @param componentKey Key of the file like 'myProjectKey:src/foo.php'
* @param line Line you want to query
* @param lineOffset Offset you want to query.
* @return List of references for the symbol (potentially empty) or null if there is no symbol at this position.
*/
@CheckForNull
public Collection<TextRange> referencesForSymbolAt(String componentKey, int line, int lineOffset) {
DefaultSymbolTable symbolTable = sensorStorage.symbolsPerComponent.get(componentKey);
if (symbolTable == null) {
return null;
}
DefaultTextPointer location = new DefaultTextPointer(line, lineOffset);
for (Map.Entry<TextRange, Set<TextRange>> symbol : symbolTable.getReferencesBySymbol().entrySet()) {
if (symbol.getKey().start().compareTo(location) <= 0 && symbol.getKey().end().compareTo(location) > 0) {
return symbol.getValue();
}
}
return null;
}
use of org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method duplicateSymbolTable.
@Test(expected = UnsupportedOperationException.class)
public void duplicateSymbolTable() throws Exception {
InputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.java").setModuleBaseDir(temp.newFolder().toPath()).build();
DefaultSymbolTable st = new DefaultSymbolTable(null).onFile(inputFile);
underTest.store(st);
underTest.store(st);
}
use of org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable 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.batch.sensor.symbol.internal.DefaultSymbolTable 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.batch.sensor.symbol.internal.DefaultSymbolTable 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