From 704cdda91825f66dd47303edc7fa2f916cb5764f Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 26 Aug 2015 17:40:42 +0200 Subject: [PATCH] SONAR-4865 Apply some feedback on issue location API --- .../issue/DeprecatedIssueBuilderWrapper.java | 4 ++-- .../sonar/core/issue/DefaultIssueBuilder.java | 2 +- .../org/sonar/api/batch/fs/InputFile.java | 16 ++++++++++++---- .../org/sonar/api/batch/fs/TextRange.java | 9 ++++++++- .../api/batch/sensor/issue/NewIssue.java | 19 +++++++------------ .../sensor/issue/internal/DefaultIssue.java | 6 ------ .../java/org/sonar/api/issue/Issuable.java | 5 +++-- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java index 146a40e06e3..e3f416a9ef9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java @@ -90,8 +90,8 @@ public class DeprecatedIssueBuilderWrapper implements Issuable.IssueBuilder { } @Override - public IssueBuilder addExecutionFlow(NewIssueLocation... flow) { - newIssue.addExecutionFlow(flow); + public IssueBuilder addExecutionFlow(Iterable flowLocations) { + newIssue.addExecutionFlow(flowLocations); return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java index 4a107e45948..e65a71bab69 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java @@ -81,7 +81,7 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder { } @Override - public IssueBuilder addExecutionFlow(NewIssueLocation... flow) { + public IssueBuilder addExecutionFlow(Iterable flow) { throw unsupported(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java index fb1f25bdcdf..ecf61d7cd64 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java @@ -115,31 +115,39 @@ public interface InputFile extends InputPath { boolean isEmpty(); /** - * Return a {@link TextPointer} in the given file. + * Returns a {@link TextPointer} in the given file. * @param line Line of the pointer. Start at 1. * @param lineOffset Offset in the line. Start at 0. * @throw {@link IllegalArgumentException} if line or offset is not valid for the given file. + * @since 5.2 */ TextPointer newPointer(int line, int lineOffset); /** - * Return a {@link TextRange} in the given file. + * Returns a {@link TextRange} in the given file. * @param start start pointer * @param end end pointer * @throw {@link IllegalArgumentException} if start or stop pointers are not valid for the given file. + * @since 5.2 */ TextRange newRange(TextPointer start, TextPointer end); /** - * Return a {@link TextRange} in the given file. + * Returns a {@link TextRange} in the given file. + *
    + *
  • newRange(1, 0, 1, 1) selects the first character at line 1
  • + *
  • newRange(1, 0, 1, 10) selects the 10 first characters at line 1
  • + *
* @throw {@link IllegalArgumentException} if start or stop positions are not valid for the given file. + * @since 5.2 */ TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset); /** - * Return a {@link TextRange} in the given file that select the full line. + * Returns a {@link TextRange} in the given file that select the full line. * @param line Start at 1. * @throw {@link IllegalArgumentException} if line is not valid for the given file. + * @since 5.2 */ TextRange selectLine(int line); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextRange.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextRange.java index 08239a1e0cd..213c0060d2c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextRange.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextRange.java @@ -20,7 +20,14 @@ package org.sonar.api.batch.fs; /** - * Represents a text range in an {@link InputFile} + * Represents a text range in an {@link InputFile}. + * + * A range is delimited by two {@link TextPointer}. + *
    + *
  • TextRange(TextPointer(1, 0), TextPointer(1, 1)) represents the first character at line 1
  • + *
  • TextRange(TextPointer(1, 0), TextPointer(1, 10)) represents the 10 first characters at line 1
  • + *
+ * @see InputFile#newRange(int, int, int, int) * * @since 5.2 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java index 5ae14bcda20..c156c953136 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java @@ -50,38 +50,33 @@ public interface NewIssue { NewIssue overrideSeverity(@Nullable Severity severity); /** + * Primary location for this issue. * @since 5.2 - * Primary for this issue. */ NewIssue at(NewIssueLocation primaryLocation); /** - * @since 5.2 * Register an additional location for this issue. - */ - NewIssue addLocation(NewIssueLocation location); - - /** * @since 5.2 - * Register an execution flow for this issue. */ - NewIssue addExecutionFlow(NewIssueLocation... locations); + NewIssue addLocation(NewIssueLocation location); /** + * Register an execution flow for this issue. An execution flow is an ordered list of issue locations that help to understand the issue. + * It is usually the path leading to the primary location. Several execution flows can be registered. * @since 5.2 - * Register an execution flow for this issue. */ - NewIssue addExecutionFlow(Iterable locations); + NewIssue addExecutionFlow(Iterable flowLocations); /** - * @since 5.2 * Create a new location for this issue. First registered location is considered as primary location. + * @since 5.2 */ NewIssueLocation newLocation(); /** - * @since 5.2 * Attach a new attribute to the issue. Not used by SQ but can be reused later for integration needs (for example it is returned by WS). + * @since 5.2 */ NewIssue addAttribute(String key, String value); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index e4c3b73ba85..1c623ee92f6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -25,7 +25,6 @@ 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; @@ -109,11 +108,6 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { return this; } - @Override - public DefaultIssue addExecutionFlow(NewIssueLocation... locations) { - return addExecutionFlow(Arrays.asList(locations)); - } - @Override public DefaultIssue addExecutionFlow(Iterable locations) { List flowAsList = new ArrayList<>(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java index c2adf0e5e11..fad75b15d28 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java @@ -101,9 +101,10 @@ public interface Issuable extends Perspective { /** * @since 5.2 - * Register an execution flow for this issue. + * Register an execution flow for this issue. An execution flow is an ordered list of issue locations that help to understand the issue. + * It is usually the path leading to the primary location. Several execution flows can be registered. */ - IssueBuilder addExecutionFlow(NewIssueLocation... flow); + IssueBuilder addExecutionFlow(Iterable flowLocations); /** * Overrides the severity declared in Quality profile. Do not execute in standard use-cases. -- 2.39.5