use of org.sonar.api.batch.sensor.issue.NewIssueLocation in project sonarlint-core by SonarSource.
the class DeprecatedIssueBuilderWrapper method build.
@Override
public Issue build() {
if (newIssue.primaryLocation() == null) {
NewIssueLocation newLocation = newIssue.newLocation().on(primaryComponent);
if (primaryMessage != null) {
newLocation.message(primaryMessage);
}
if (primaryComponent.isFile() && primaryRange != null) {
newLocation.at(primaryRange);
}
newIssue.at(newLocation);
}
return new DeprecatedIssueWrapper(newIssue);
}
use of org.sonar.api.batch.sensor.issue.NewIssueLocation in project sonar-web by SonarSource.
the class WebSensor method saveMetrics.
private static void saveMetrics(SensorContext context, WebSourceCode sourceCode) {
InputFile inputFile = sourceCode.inputFile();
saveComplexityDistribution(context, sourceCode);
for (Map.Entry<Metric<Integer>, Integer> entry : sourceCode.getMeasures().entrySet()) {
context.<Integer>newMeasure().on(inputFile).forMetric(entry.getKey()).withValue(entry.getValue()).save();
}
for (WebIssue issue : sourceCode.getIssues()) {
NewIssue newIssue = context.newIssue().forRule(issue.ruleKey()).gap(issue.cost());
Integer line = issue.line();
NewIssueLocation location = newIssue.newLocation().on(inputFile).message(issue.message());
if (line != null) {
location.at(inputFile.selectLine(line));
}
newIssue.at(location);
newIssue.save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssueLocation in project sonar-go by SonarSource.
the class GoSensor method reportIssue.
private void reportIssue(Issue issue, SensorContext context, InputFile inputFile) {
// TODO improve common rule engine to handle this out of the box
RuleKey ruleKey = checks.ruleKey(issue.getCheck());
Objects.requireNonNull(ruleKey, "Rule key not found for " + issue.getCheck().getClass());
NewIssue newIssue = context.newIssue();
NewIssueLocation location = newIssue.newLocation().on(inputFile).message(issue.getMessage());
if (issue.hasLocation()) {
location.at(newRange(inputFile, issue.getPrimary().from, issue.getPrimary().to));
}
newIssue.forRule(ruleKey).at(location).gap(issue.getEffortToFix());
Arrays.stream(issue.getSecondaries()).forEach(secondary -> newIssue.addLocation(newIssue.newLocation().on(inputFile).at(newRange(inputFile, secondary.from, secondary.to)).message(secondary.description == null ? "" : secondary.description)));
newIssue.save();
}
use of org.sonar.api.batch.sensor.issue.NewIssueLocation in project sonarqube by SonarSource.
the class MultilineIssuesSensor method createIssues.
private static void createIssues(InputFile file, SensorContext context, Map<Integer, TextPointer> startPositions, Map<Integer, TextPointer> endPositions, Map<Integer, Table<Integer, Integer, TextPointer>> startFlowsPositions, Map<Integer, Table<Integer, Integer, TextPointer>> endFlowsPositions) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
for (Map.Entry<Integer, TextPointer> entry : startPositions.entrySet()) {
NewIssue newIssue = context.newIssue().forRule(ruleKey);
Integer issueId = entry.getKey();
NewIssueLocation primaryLocation = newIssue.newLocation().on(file).at(file.newRange(entry.getValue(), endPositions.get(issueId)));
newIssue.at(primaryLocation.message("Primary location"));
if (startFlowsPositions.containsKey(issueId)) {
Table<Integer, Integer, TextPointer> flows = startFlowsPositions.get(issueId);
for (Map.Entry<Integer, Map<Integer, TextPointer>> flowEntry : flows.rowMap().entrySet()) {
Integer flowId = flowEntry.getKey();
List<NewIssueLocation> flowLocations = Lists.newArrayList();
List<Integer> flowNums = Lists.newArrayList(flowEntry.getValue().keySet());
Collections.sort(flowNums);
for (Integer flowNum : flowNums) {
TextPointer start = flowEntry.getValue().get(flowNum);
TextPointer end = endFlowsPositions.get(issueId).row(flowId).get(flowNum);
NewIssueLocation newLocation = newIssue.newLocation().on(file).at(file.newRange(start, end)).message("Flow step #" + flowNum);
flowLocations.add(newLocation);
}
if (flowLocations.size() == 1) {
newIssue.addLocation(flowLocations.get(0));
} else {
newIssue.addFlow(flowLocations);
}
}
}
newIssue.save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssueLocation in project sonarqube by SonarSource.
the class CustomMessageSensor method processFile.
@Override
protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
NewIssue newIssue = context.newIssue().forRule(ruleKey);
NewIssueLocation location = newIssue.newLocation().on(inputFile);
settings.get(MESSAGE_PROPERTY).ifPresent(location::message);
newIssue.at(location).save();
}
Aggregations