public static int commentEnd(CommentSet comments, CommentSet.RelativePosition pos) { List<Comment> list = comments.getComments(pos); if (list.isEmpty()) { return -1; } else { return list.get(list.size() - 1).endPos(); } }
private int adjustLocalPointer(int localPointer, CommentSet cs, CommentSet.RelativePosition position) { if (cs == null) return localPointer; List<Comment> cl = cs.getComments(position); if (!cl.isEmpty()) { for (Comment comment : cl) { localPointer = Math.max(comment.endPos(), localPointer); } } return localPointer; }
private int getPosAfterCommentStart(Tree t, int minPos) { CommentSet cs = getCommentsForTree(t, true); List<Comment> cmm = cs.getComments(CommentSet.RelativePosition.PRECEDING); if (cmm.isEmpty()) { cmm = cs.getComments(CommentSet.RelativePosition.INNER); } if (cmm.isEmpty()) { return minPos; } Comment c = cmm.get(cmm.size() - 1); int pos = c.endPos(); assert pos >= 0; return Math.max(minPos, pos); }
private int getPosAfterCommentEnd(Tree t, int minPos) { CommentSet cs = getCommentsForTree(t, false); List<Comment> cmm = cs.getComments(CommentSet.RelativePosition.TRAILING); if (cmm.isEmpty()) { cmm = cs.getComments(CommentSet.RelativePosition.INLINE); } if (cmm.isEmpty()) { return minPos; } Comment c = cmm.get(cmm.size() - 1); int pos = c.endPos(); assert pos >= 0; if (c.style() == Comment.Style.LINE || c.style() == Comment.Style.WHITESPACE) { // compensate trailing newline to preserve line ends for line comment and whitespace if (pos > 0 && diffContext.origText.charAt(pos - 1) == '\n') { pos--; } } return Math.max(minPos, pos); }
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); } }
return localPointer; int newP = oldPrecedingComments.get(oldPrecedingComments.size() - 1).endPos(); if (newP > localPointer && newP < oldTreeStartPos) { copyTo(localPointer, newP);
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); }
int nextTarget = Math.max(localPointer, oldC.endPos()); if (commentsMatch(oldC, newC)) { if(preceding && oldC == javadoc && oldDoc != null) { localPointer = diffDocTree((DCDocComment)oldDoc, (DCTree)oldDoc, (DCTree)newDoc, new int[]{localPointer, oldC.endPos()}); } else { first = false; localPointer = Math.max(localPointer, oldC.endPos());