]> source.dussan.org Git - sonarqube.git/commitdiff
Create a shortcut to add secondary issue locations 573/head
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 6 Oct 2015 18:43:53 +0000 (20:43 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 6 Oct 2015 22:02:09 +0000 (00:02 +0200)
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java
sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java

index dec367142aff8f5f2effddce6e51ff5eeab24758..49ba26109d15611a7ecf42ee70d0cddab4c66d7c 100644 (file)
@@ -144,7 +144,11 @@ public class MultilineIssuesSensor implements Sensor {
               .message("Flow step #" + flowNum);
             flowLocations.add(newLocation);
           }
-          newIssue.addFlow(flowLocations);
+          if (flowLocations.size() == 1) {
+            newIssue.addLocation(flowLocations.get(0));
+          } else {
+            newIssue.addFlow(flowLocations);
+          }
         }
       }
       newIssue.save();
index 85f05374a3e0ad35bfee008fa633e3f3d95c5af5..acc5d3343b498b6872e74db11c706e1c5917a1c1 100644 (file)
@@ -83,6 +83,12 @@ public class DeprecatedIssueBuilderWrapper implements Issuable.IssueBuilder {
     return this;
   }
 
+  @Override
+  public IssueBuilder addLocation(NewIssueLocation secondaryLocation) {
+    newIssue.addLocation(secondaryLocation);
+    return this;
+  }
+
   @Override
   public IssueBuilder addFlow(Iterable<NewIssueLocation> flowLocations) {
     newIssue.addFlow(flowLocations);
index a1185baa607ba136a9c27a4692bea6c8fa66fd88..e351c69a3e091909453e9de1ec2fc9ba1b666e9b 100644 (file)
@@ -80,6 +80,11 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder {
     throw unsupported();
   }
 
+  @Override
+  public IssueBuilder addLocation(NewIssueLocation secondaryLocation) {
+    throw unsupported();
+  }
+
   @Override
   public IssueBuilder addFlow(Iterable<NewIssueLocation> flow) {
     throw unsupported();
index 66630bf99917fbcc17a3e02cfe38af33eb251d9c..b6b2e068835dfdb747c2a4548f7e3e9cbc9ba7a3 100644 (file)
@@ -55,6 +55,12 @@ public interface NewIssue {
    */
   NewIssue at(NewIssueLocation primaryLocation);
 
+  /**
+   * Add a secondary location for this issue. Several secondary locations can be registered.
+   * @since 5.2
+   */
+  NewIssue addLocation(NewIssueLocation secondaryLocation);
+
   /**
    * Register a flow for this issue. A flow is an ordered list of issue locations that help to understand the issue.
    * It could be a path leading to the primary location. Several flows can be registered.
index bed2162a7b9a0908e3da7984fc55b6bfbb33aa5e..10f3e83706cf25139a48cea5d08b132f3001516e 100644 (file)
@@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -101,6 +102,12 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue {
     return this;
   }
 
+  @Override
+  public NewIssue addLocation(NewIssueLocation secondaryLocation) {
+    flows.add(Arrays.asList((IssueLocation) secondaryLocation));
+    return this;
+  }
+
   @Override
   public DefaultIssue addFlow(Iterable<NewIssueLocation> locations) {
     List<IssueLocation> flowAsList = new ArrayList<>();
index 38fe85f4a2ce22c4fc418692af214a0f8fceae4f..de822ecb824f75eb0f095be865977990f1eb2434 100644 (file)
@@ -94,6 +94,12 @@ public interface Issuable extends Perspective {
      */
     IssueBuilder at(NewIssueLocation primaryLocation);
 
+    /**
+     * @since 5.2
+     * @see NewIssue#addLocation(NewIssueLocation)
+     */
+    IssueBuilder addLocation(NewIssueLocation secondaryLocation);
+
     /**
      * @since 5.2
      * @see NewIssue#addFlow(Iterable)