use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class TaskResult method highlightingTypeFor.
/**
* Get highlighting types at a given position in an inputfile
* @param lineOffset 0-based offset in file
*/
public List<TypeOfText> highlightingTypeFor(InputFile file, int line, int lineOffset) {
int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
if (!reader.hasSyntaxHighlighting(ref)) {
return Collections.emptyList();
}
TextPointer pointer = file.newPointer(line, lineOffset);
List<TypeOfText> result = new ArrayList<>();
try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(ref)) {
while (it.hasNext()) {
ScannerReport.SyntaxHighlightingRule rule = it.next();
TextRange ruleRange = toRange(file, rule.getRange());
if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
result.add(ScannerReportUtils.toBatchType(rule.getType()));
}
}
} catch (Exception e) {
throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath(), e);
}
return result;
}
use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class ModuleIssues method applyFlows.
private static void applyFlows(ScannerReport.Issue.Builder builder, ScannerReport.IssueLocation.Builder locationBuilder, ScannerReport.TextRange.Builder textRangeBuilder, Issue issue) {
ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder();
for (Flow flow : issue.flows()) {
if (flow.locations().isEmpty()) {
return;
}
flowBuilder.clear();
for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) {
locationBuilder.clear();
locationBuilder.setComponentRef(((DefaultInputComponent) location.inputComponent()).batchId());
String message = location.message();
if (message != null) {
locationBuilder.setMsg(message);
}
TextRange textRange = location.textRange();
if (textRange != null) {
locationBuilder.setTextRange(toProtobufTextRange(textRangeBuilder, textRange));
}
flowBuilder.addLocation(locationBuilder.build());
}
builder.addFlow(flowBuilder.build());
}
}
use of org.sonar.api.batch.fs.TextRange 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));
}
use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class DefaultSymbolTable method newSymbol.
@Override
public NewSymbol newSymbol(int startLine, int startLineOffset, int endLine, int endLineOffset) {
checkInputFileNotNull();
TextRange declarationRange;
try {
declarationRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to create symbol on file " + inputFile, e);
}
return newSymbol(declarationRange);
}
use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class DefaultHighlighting method highlight.
@Override
public DefaultHighlighting highlight(int startOffset, int endOffset, TypeOfText typeOfText) {
checkInputFileNotNull();
TextRange newRange;
try {
newRange = inputFile.newRange(startOffset, endOffset);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to highlight file " + inputFile, e);
}
return highlight(newRange, typeOfText);
}
Aggregations