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 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.TextRange in project sonarqube by SonarSource.
the class OneCodeSmellIssuePerTestLineSensor method createIssues.
private static void createIssues(InputFile file, SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
for (int line = 1; line <= file.lines(); line++) {
TextRange text = file.selectLine(line);
// do not count empty lines, which can be a pain with end-of-file return
if (text.end().lineOffset() == 0) {
continue;
}
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(text).message("This code smell issue is generated on each line of a test file")).save();
}
}
use of org.sonar.api.batch.fs.TextRange in project sonarqube by SonarSource.
the class OneCodeSmellIssuePerLineSensor method createIssues.
private static void createIssues(InputFile file, SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
for (int line = 1; line <= file.lines(); line++) {
TextRange text = file.selectLine(line);
// do not count empty lines, which can be a pain with end-of-file return
if (text.end().lineOffset() == 0) {
continue;
}
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(text).message("This code smell issue is generated on each line")).save();
}
}
Aggregations