diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-07-29 17:42:20 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-07-31 11:00:25 +0200 |
commit | 93420cb74009febd28256484ca73241442bc1ff9 (patch) | |
tree | 612fc1f176e3b41cff95dd3038c2726d14725ee2 /plugins/sonar-xoo-plugin/src | |
parent | 5b93180b18e756c6a246b8d22307785d333d0002 (diff) | |
download | sonarqube-93420cb74009febd28256484ca73241442bc1ff9.tar.gz sonarqube-93420cb74009febd28256484ca73241442bc1ff9.zip |
SONAR-6052 Extract primaryLocation as a special attribute
Also rework new issue API on batch side.
Diffstat (limited to 'plugins/sonar-xoo-plugin/src')
6 files changed, 20 insertions, 15 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/checks/TemplateRuleCheck.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/checks/TemplateRuleCheck.java index c6fe84360c3..fc361d40d7c 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/checks/TemplateRuleCheck.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/checks/TemplateRuleCheck.java @@ -40,8 +40,8 @@ public class TemplateRuleCheck implements Check { NewIssue newIssue = sensorContext.newIssue(); newIssue .forRule(ruleKey) - .addLocation(newIssue.newLocation() - .onFile(file) + .at(newIssue.newLocation() + .on(file) .at(file.selectLine(line))) .save(); } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java index 47e8a16794d..e92e5c12564 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java @@ -58,8 +58,8 @@ public class CreateIssueByInternalKeySensor implements Sensor { NewIssue newIssue = context.newIssue(); newIssue .forRule(rule.ruleKey()) - .addLocation(newIssue.newLocation() - .onFile(file) + .at(newIssue.newLocation() + .on(file) .message("This issue is generated on each file")) .save(); } 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 a4bcca64eab..57dbc84464b 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 @@ -34,6 +34,7 @@ import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; import org.sonar.api.batch.sensor.issue.NewIssue; +import org.sonar.api.batch.sensor.issue.NewIssueLocation; import org.sonar.api.rule.RuleKey; import org.sonar.xoo.Xoo; @@ -76,7 +77,7 @@ public class MultilineIssuesSensor implements Sensor { while (m.find()) { Integer issueId = Integer.parseInt(m.group(1)); Integer issueLocationId = Integer.parseInt(m.group(2)); - TextPointer newPointer = file.newPointer(currentLine, m.start()); + TextPointer newPointer = file.newPointer(currentLine, m.end()); if (!startPositions.containsKey(issueId)) { startPositions.put(issueId, new HashMap<Integer, TextPointer>()); } @@ -100,10 +101,14 @@ public class MultilineIssuesSensor implements Sensor { for (Map.Entry<Integer, Map<Integer, TextPointer>> entry : startPositions.entrySet()) { NewIssue newIssue = context.newIssue().forRule(ruleKey); for (Map.Entry<Integer, TextPointer> location : entry.getValue().entrySet()) { - newIssue.addLocation(newIssue.newLocation() - .onFile(file) - .at(file.newRange(location.getValue(), endPositions.get(entry.getKey()).get(location.getKey()))) - .message("Multiline issue")); + NewIssueLocation newLocation = newIssue.newLocation() + .on(file) + .at(file.newRange(location.getValue(), endPositions.get(entry.getKey()).get(location.getKey()))); + if (location.getKey() == 1) { + newIssue.at(newLocation.message("Primary location")); + } else { + newIssue.addLocation(newLocation.message("Location #" + location.getKey())); + } } newIssue.save(); } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java index e53f0b17ccc..b2d047a9994 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java @@ -54,8 +54,8 @@ public class OneIssueOnDirPerFileSensor implements Sensor { NewIssue newIssue = context.newIssue(); newIssue .forRule(ruleKey) - .addLocation(newIssue.newLocation() - .onDir(inputDir) + .at(newIssue.newLocation() + .on(inputDir) .message("This issue is generated for file " + file.relativePath())) .save(); } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java index e8aed769087..8ef94f3d99f 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java @@ -61,8 +61,8 @@ public class OneIssuePerLineSensor implements Sensor { NewIssue newIssue = context.newIssue(); newIssue .forRule(ruleKey) - .addLocation(newIssue.newLocation() - .onFile(file) + .at(newIssue.newLocation() + .on(file) .at(file.selectLine(line)) .message("This issue is generated on each line")) .effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)) diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java index 69bf700b50b..bc7b90a69ae 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java @@ -66,8 +66,8 @@ public class RandomAccessSensor implements Sensor { NewIssue newIssue = context.newIssue(); newIssue .forRule(ruleKey) - .addLocation(newIssue.newLocation() - .onFile(file) + .at(newIssue.newLocation() + .on(file) .at(file.selectLine(1)) .message("This issue is generated on each file")) .save(); |