private static void moveCommentsBeforeOffset(WorkingCopy wc, Tree from, Tree to, int offset, Document doc) {
List<Comment> toMove = new LinkedList<>();
int idx = 0;
for (Comment comment : wc.getTreeUtilities().getComments(from, true)) {
if (comment.pos() >= offset || comment.endPos() > offset) {
break;
}
DocumentGuards guards = LineDocumentUtils.as(doc, DocumentGuards.class);
if (guards != null) {
int epAfterBlock = guards.adjustPosition(comment.pos(), true);
if (epAfterBlock >= comment.endPos()) {
break;
}
}
toMove.add(comment);
idx++;
}
if (toMove.size() > 0) {
doMoveComments(wc, from, to, offset, toMove, 0, idx);
}
}