private void addCommentsToContext(DiffContext context) { Map<Integer, Comment> m = new HashMap<>(usedComments.size()); for (Comment c : usedComments) { m.put(c.pos(), c); } context.usedComments = m; }
public int pos(RelativePosition position) { List<Comment> list = getComments(position); return list.isEmpty() ? NOPOS : list.get(0).pos(); }
public static int commentStart(DiffContext diffContext, CommentSet comments, CommentSet.RelativePosition pos, int limit) { List<Comment> list = comments.getComments(pos); if (list.isEmpty()) { return Integer.MAX_VALUE; } else { diffContext.tokenSequence.move(limit); moveToSrcRelevant(diffContext.tokenSequence, Direction.BACKWARD); limit = diffContext.tokenSequence.offset() + diffContext.tokenSequence.token().length(); int start = Integer.MAX_VALUE; for (Comment c : list) { if (c.pos() >= limit) start = Math.min(start, c.pos()); } return start; } }
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); // comment that ends exactly at the GB boundary cannot be really // reassigned from the previous member. if (epAfterBlock >= comment.endPos()) { // set new offset, after the guarded block break; } } toMove.add(comment); idx++; } if (toMove.size() > 0) { doMoveComments(wc, from, to, offset, toMove, 0, idx); } }
private int commentStartCorrect(Comment c) { tokenSequence.move(c.pos()); boolean wasPrevious = false; while (tokenSequence.movePrevious()) { if (tokenSequence.token().id() != JavaTokenId.WHITESPACE) { return tokenSequence.offset() + tokenSequence.token().length(); } int lastNewLine = tokenSequence.token().text().toString().lastIndexOf('\n'); if (lastNewLine != (-1)) { return tokenSequence.offset() + lastNewLine + 1; } wasPrevious = true; } if (wasPrevious) return tokenSequence.offset(); else return c.pos(); }
protected int diffInnerComments(JCTree oldT, JCTree newT, int localPointer) { if (innerCommentsProcessed) { return localPointer; } innerCommentsProcessed = true; CommentSet cs = getCommentsForTree(newT, true); CommentSet old = getCommentsForTree(oldT, true); List<Comment> oldPrecedingComments = cs == old ? ((CommentSetImpl)cs).getOrigComments(CommentSet.RelativePosition.INNER) : old.getComments(CommentSet.RelativePosition.INNER); List<Comment> newPrecedingComments = cs.getComments(CommentSet.RelativePosition.INNER); if (sameComments(oldPrecedingComments, newPrecedingComments)) { if (oldPrecedingComments.isEmpty()) { return localPointer; } // WHITESPACE comments have pos == -1, and no real useful data Comment c = oldPrecedingComments.get(oldPrecedingComments.size() - 1); if (c.pos() == -1) { return localPointer; } int newP = c.endPos(); copyTo(localPointer, newP); return newP; } return diffCommentLists(getOldPos(oldT), oldPrecedingComments, newPrecedingComments, null, null, true, false, true, false, localPointer); }
tm.addComment(to, comment, comment.pos() <= offset);
if (!listContains(oldList, newC)) { copyTo(localPointer, localPointer = oldC.pos()); printer.printComment(newC, !trailing, false, true); oldC = safeNext(oldIter);