diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-09-13 13:15:04 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-09-16 20:03:14 +0000 |
commit | e302f298b39c133f7290571b13db668610867fa1 (patch) | |
tree | 1d885b5919ccd5fae411df8487f70b5fbb892832 | |
parent | 1125e9dd1378ebc9aa381eeb7139e7a95e269a42 (diff) | |
download | sonarqube-e302f298b39c133f7290571b13db668610867fa1.tar.gz sonarqube-e302f298b39c133f7290571b13db668610867fa1.zip |
SONAR-17288 Add ITs
-rw-r--r-- | plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java index 933bd2490ca..db54208c928 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java @@ -21,10 +21,12 @@ package org.sonar.xoo.rule; import java.io.IOException; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -46,6 +48,7 @@ import org.sonar.xoo.Xoo; import static org.sonar.api.batch.sensor.issue.NewIssue.FlowType.DATA; import static org.sonar.api.batch.sensor.issue.NewIssue.FlowType.EXECUTION; +import static org.sonar.api.utils.Preconditions.checkState; public class MultilineIssuesSensor implements Sensor { @@ -99,23 +102,20 @@ public class MultilineIssuesSensor implements Sensor { .at(file.newRange(parsedIssue.start, parsedIssue.end)); newIssue.at(primaryLocation.message("Primary location")); - IssueFlows issueFlows = flowIndex.getFlows(parsedIssue.issueId); - if (issueFlows != null) { - for (ParsedFlow flow : issueFlows.getFlows()) { - List<NewIssueLocation> flowLocations = new LinkedList<>(); - - for (ParsedFlowLocation flowLocation : flow.getLocations()) { - flowLocations.add(newIssue.newLocation() - .on(file) - .at(file.newRange(flowLocation.start, flowLocation.end)) - .message("Flow step #" + flowLocation.flowLocationId)); - } - - if (flow.getType() != null) { - newIssue.addFlow(flowLocations, flow.getType(), "flow #" + flow.getFlowId()); - } else { - newIssue.addFlow(flowLocations); - } + for (ParsedFlow flow : flowIndex.getFlows(parsedIssue.issueId)) { + List<NewIssueLocation> flowLocations = new LinkedList<>(); + + for (ParsedFlowLocation flowLocation : flow.getLocations()) { + flowLocations.add(newIssue.newLocation() + .on(file) + .at(file.newRange(flowLocation.start, flowLocation.end)) + .message("Flow step #" + flowLocation.flowLocationId)); + } + + if (flow.getType() != null) { + newIssue.addFlow(flowLocations, flow.getType(), "flow #" + flow.getFlowId()); + } else { + newIssue.addFlow(flowLocations); } } newIssue.save(); @@ -191,9 +191,8 @@ public class MultilineIssuesSensor implements Sensor { flowsByIssueId.computeIfAbsent(flowLocation.issueId, issueId -> new IssueFlows()).addLocation(flowLocation, type); } - @CheckForNull - public IssueFlows getFlows(int issueId) { - return flowsByIssueId.get(issueId); + public Collection<ParsedFlow> getFlows(int issueId) { + return Optional.ofNullable(flowsByIssueId.get(issueId)).map(IssueFlows::getFlows).orElse(Collections.emptyList()); } } @@ -222,12 +221,10 @@ public class MultilineIssuesSensor implements Sensor { private void addLocation(ParsedFlowLocation flowLocation) { if (locationsById.containsKey(flowLocation.flowLocationId)) { - if (flowLocation.start != null) { - locationsById.get(flowLocation.flowLocationId).start = flowLocation.start; - } else if (flowLocation.end != null) { - locationsById.get(flowLocation.flowLocationId).end = flowLocation.end; - } + checkState(flowLocation.end != null, "Existing flow should be the end"); + locationsById.get(flowLocation.flowLocationId).end = flowLocation.end; } else { + checkState(flowLocation.start != null, "New flow should be the start"); locationsById.put(flowLocation.flowLocationId, flowLocation); } } |