use of org.sonar.api.batch.fs.TextPointer in project sonar-java by SonarSource.
the class JavaIssueTest method assertLocation.
private static void assertLocation(IssueLocation location, InputFile file, String message, int startLine, int startOffset, int endLine, int endOffset) {
assertThat(location.inputComponent()).isEqualTo(file);
assertThat(location.message()).isEqualTo(message);
TextRange textRange = location.textRange();
TextPointer start = textRange.start();
assertThat(start.line()).isEqualTo(startLine);
assertThat(start.lineOffset()).isEqualTo(startOffset);
TextPointer end = textRange.end();
assertThat(end.line()).isEqualTo(endLine);
assertThat(end.lineOffset()).isEqualTo(endOffset);
}
use of org.sonar.api.batch.fs.TextPointer in project sonarqube by SonarSource.
the class MultilineIssuesSensor method parseIssues.
private static void parseIssues(InputFile file, SensorContext context, Map<Integer, TextPointer> startPositions, Map<Integer, TextPointer> endPositions) {
int currentLine = 0;
try {
for (String lineStr : Files.readAllLines(file.path(), file.charset())) {
currentLine++;
Matcher m = START_ISSUE_PATTERN.matcher(lineStr);
while (m.find()) {
Integer issueId = Integer.parseInt(m.group(1));
TextPointer newPointer = file.newPointer(currentLine, m.end());
startPositions.put(issueId, newPointer);
}
m = END_ISSUE_PATTERN.matcher(lineStr);
while (m.find()) {
Integer issueId = Integer.parseInt(m.group(1));
TextPointer newPointer = file.newPointer(currentLine, m.start());
endPositions.put(issueId, newPointer);
}
}
} catch (IOException e) {
throw new IllegalStateException("Unable to read file", e);
}
}
use of org.sonar.api.batch.fs.TextPointer in project sonarqube by SonarSource.
the class DefaultInputFile method selectLine.
@Override
public TextRange selectLine(int line) {
checkMetadata();
TextPointer startPointer = newPointer(line, 0);
TextPointer endPointer = newPointer(line, lineLength(line));
return newRangeValidPointers(startPointer, endPointer, true);
}
use of org.sonar.api.batch.fs.TextPointer in project sonarqube by SonarSource.
the class DefaultInputFile method newRange.
@Override
public TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset) {
checkMetadata();
TextPointer start = newPointer(startLine, startLineOffset);
TextPointer end = newPointer(endLine, endLineOffset);
return newRangeValidPointers(start, end, false);
}
use of org.sonar.api.batch.fs.TextPointer 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;
}
Aggregations