use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class IssuePublisher method applyFlows.
private static void applyFlows(Consumer<ScannerReport.Flow> consumer, ScannerReport.IssueLocation.Builder locationBuilder, ScannerReport.TextRange.Builder textRangeBuilder, Collection<Flow> flows) {
ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder();
for (Flow flow : flows) {
if (flow.locations().isEmpty()) {
return;
}
flowBuilder.clear();
for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) {
int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).scannerId();
locationBuilder.clear();
locationBuilder.setComponentRef(locationComponentRef);
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());
}
consumer.accept(flowBuilder.build());
}
}
use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class AnalysisResult 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 = ((DefaultInputComponent) file).scannerId();
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, e);
}
return result;
}
use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class DefaultHighlighting method highlight.
@Override
public DefaultHighlighting highlight(int startLine, int startLineOffset, int endLine, int endLineOffset, TypeOfText typeOfText) {
checkInputFileNotNull();
TextRange newRange;
try {
newRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to highlight file " + inputFile, e);
}
return highlight(newRange, typeOfText);
}
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 DefaultCpdTokens method addToken.
@Override
public NewCpdTokens addToken(int startLine, int startLineOffset, int endLine, int endLineOffset, String image) {
checkInputFileNotNull();
TextRange newRange;
try {
newRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to register token in file " + inputFile, e);
}
return addToken(newRange, image);
}
Aggregations