diff --git a/src/test/java/org/checkstyle/autofix/RemoveViolationComments.java b/src/test/java/org/checkstyle/autofix/RemoveViolationComments.java index 28af9da..3b2d6d9 100644 --- a/src/test/java/org/checkstyle/autofix/RemoveViolationComments.java +++ b/src/test/java/org/checkstyle/autofix/RemoveViolationComments.java @@ -73,7 +73,16 @@ public Space visitSpace(Space space, Space.Location loc, ExecutionContext ctx) { else { result = space.withComments(filteredComments); if (!suffixAccumulator.isEmpty()) { - result = result.withWhitespace(suffixAccumulator.toString()); + if (filteredComments.isEmpty()) { + result = result.withWhitespace(suffixAccumulator.toString()); + } + else { + final Comment lastComment = filteredComments + .get(filteredComments.size() - 1); + filteredComments.set(filteredComments.size() - 1, + lastComment.withSuffix(suffixAccumulator.toString())); + result = space.withComments(filteredComments); + } } } return super.visitSpace(result, loc, ctx);