Search in sources :

Example 1 with Range

use of com.google.gerrit.extensions.client.Comment.Range in project gerrit by GerritCodeReview.

the class PostReview method ensureRangesDoNotOverlap.

private static void ensureRangesDoNotOverlap(String commentPath, List<FixReplacementInfo> fixReplacementInfos) throws BadRequestException {
    List<Range> sortedRanges = fixReplacementInfos.stream().map(fixReplacementInfo -> fixReplacementInfo.range).sorted().collect(toList());
    int previousEndLine = 0;
    int previousOffset = -1;
    for (Range range : sortedRanges) {
        if (range.startLine < previousEndLine || (range.startLine == previousEndLine && range.startCharacter < previousOffset)) {
            throw new BadRequestException(String.format("Replacements overlap for the robot comment on %s", commentPath));
        }
        previousEndLine = range.endLine;
        previousOffset = range.endCharacter;
    }
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Range(com.google.gerrit.extensions.client.Comment.Range)

Example 2 with Range

use of com.google.gerrit.extensions.client.Comment.Range in project gerrit by GerritCodeReview.

the class ChangeIT method invalidRange.

@Test
public void invalidRange() throws Exception {
    String changeId = createChange().getChangeId();
    ReviewInput review = new ReviewInput();
    ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
    comment.range = new Range();
    comment.range.startLine = 1;
    comment.range.endLine = 1;
    comment.range.startCharacter = -1;
    comment.range.endCharacter = 0;
    comment.path = PushOneCommit.FILE_NAME;
    comment.side = Side.REVISION;
    comment.message = "comment 1";
    review.comments = ImmutableMap.of(comment.path, Lists.newArrayList(comment));
    exception.expect(BadRequestException.class);
    gApi.changes().id(changeId).current().review(review);
}
Also used : Range(com.google.gerrit.extensions.client.Comment.Range) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Range (com.google.gerrit.extensions.client.Comment.Range)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 Test (org.junit.Test)1