Lines 170-176
Link Here
|
170 |
//was: |
170 |
//was: |
171 |
// int ln = td.oldTopLevel.lineMap.getLineNumber(start); |
171 |
// int ln = td.oldTopLevel.lineMap.getLineNumber(start); |
172 |
// int lineStart = td.oldTopLevel.lineMap.getStartPosition(ln); |
172 |
// int lineStart = td.oldTopLevel.lineMap.getStartPosition(ln); |
173 |
|
173 |
|
174 |
td.printer.setInitialOffset(lineStart); |
174 |
td.printer.setInitialOffset(lineStart); |
175 |
|
175 |
|
176 |
Tree current = oldTree; |
176 |
Tree current = oldTree; |
Lines 288-294
Link Here
|
288 |
localPointer = diffList(oldT.getTypeDecls(), newT.getTypeDecls(), localPointer, est, Measure.MEMBER, printer); |
288 |
localPointer = diffList(oldT.getTypeDecls(), newT.getTypeDecls(), localPointer, est, Measure.MEMBER, printer); |
289 |
printer.print(origText.substring(localPointer)); |
289 |
printer.print(origText.substring(localPointer)); |
290 |
} |
290 |
} |
291 |
|
291 |
|
292 |
private static int getOldIndent(DiffContext diffContext, Tree t) { |
292 |
private static int getOldIndent(DiffContext diffContext, Tree t) { |
293 |
if (diffContext.doc != null) { |
293 |
if (diffContext.doc != null) { |
294 |
try { |
294 |
try { |
Lines 534-540
Link Here
|
534 |
} |
534 |
} |
535 |
return bounds[1]; |
535 |
return bounds[1]; |
536 |
} |
536 |
} |
537 |
|
537 |
|
538 |
private boolean isEnum(Tree tree) { |
538 |
private boolean isEnum(Tree tree) { |
539 |
if (tree instanceof FieldGroupTree) return ((FieldGroupTree) tree).isEnum(); |
539 |
if (tree instanceof FieldGroupTree) return ((FieldGroupTree) tree).isEnum(); |
540 |
if (tree instanceof VariableTree) return (((JCVariableDecl) tree).getModifiers().flags & Flags.ENUM) != 0; |
540 |
if (tree instanceof VariableTree) return (((JCVariableDecl) tree).getModifiers().flags & Flags.ENUM) != 0; |
Lines 622-628
Link Here
|
622 |
} |
622 |
} |
623 |
if (oldT.params.isEmpty()) { |
623 |
if (oldT.params.isEmpty()) { |
624 |
// compute the position. Find the parameters closing ')', its |
624 |
// compute the position. Find the parameters closing ')', its |
625 |
// start position is important for us. This is used when |
625 |
// start position is important for us. This is used when |
626 |
// there was not any parameter in original tree. |
626 |
// there was not any parameter in original tree. |
627 |
int startOffset = oldT.pos; |
627 |
int startOffset = oldT.pos; |
628 |
|
628 |
|
Lines 876-883
Link Here
|
876 |
JCTree tree = oldstats.get(oldstats.size() - 1); |
876 |
JCTree tree = oldstats.get(oldstats.size() - 1); |
877 |
localPointer = adjustLocalPointer(localPointer, comments.getComments(oldT), CommentSet.RelativePosition.INNER); |
877 |
localPointer = adjustLocalPointer(localPointer, comments.getComments(oldT), CommentSet.RelativePosition.INNER); |
878 |
CommentSet cs = comments.getComments(tree); |
878 |
CommentSet cs = comments.getComments(tree); |
879 |
localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.INLINE); |
879 |
localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.INLINE); |
880 |
localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.TRAILING); |
880 |
localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.TRAILING); |
881 |
*/ |
881 |
*/ |
882 |
copyTo(localPointer, localPointer = endPos(oldT)); |
882 |
copyTo(localPointer, localPointer = endPos(oldT)); |
883 |
} |
883 |
} |
Lines 906-912
Link Here
|
906 |
return false; |
906 |
return false; |
907 |
} |
907 |
} |
908 |
} |
908 |
} |
909 |
|
909 |
|
910 |
|
910 |
|
911 |
protected int diffDoLoop(JCDoWhileLoop oldT, JCDoWhileLoop newT, int[] bounds) { |
911 |
protected int diffDoLoop(JCDoWhileLoop oldT, JCDoWhileLoop newT, int[] bounds) { |
912 |
int localPointer = bounds[0]; |
912 |
int localPointer = bounds[0]; |
Lines 1135-1141
Link Here
|
1135 |
for (Tree t = l.head; t!= null; l = l.tail, t = l.head) { |
1135 |
for (Tree t = l.head; t!= null; l = l.tail, t = l.head) { |
1136 |
printer.oldTrees.remove(t); |
1136 |
printer.oldTrees.remove(t); |
1137 |
} |
1137 |
} |
1138 |
} |
1138 |
} |
1139 |
localPointer = diffParameterList(oldT.resources, |
1139 |
localPointer = diffParameterList(oldT.resources, |
1140 |
newT.resources, |
1140 |
newT.resources, |
1141 |
parens ? new JavaTokenId[] { JavaTokenId.LPAREN, JavaTokenId.RPAREN } : null, |
1141 |
parens ? new JavaTokenId[] { JavaTokenId.LPAREN, JavaTokenId.RPAREN } : null, |
Lines 1152-1158
Link Here
|
1152 |
} |
1152 |
} |
1153 |
} |
1153 |
} |
1154 |
} |
1154 |
} |
1155 |
|
1155 |
|
1156 |
copyTo(localPointer, bodyPos[0]); |
1156 |
copyTo(localPointer, bodyPos[0]); |
1157 |
localPointer = diffTree(oldT.body, newT.body, bodyPos); |
1157 |
localPointer = diffTree(oldT.body, newT.body, bodyPos); |
1158 |
copyTo(localPointer, localPointer = bodyPos[1]); |
1158 |
copyTo(localPointer, localPointer = bodyPos[1]); |
Lines 1503-1509
Link Here
|
1503 |
} |
1503 |
} |
1504 |
} |
1504 |
} |
1505 |
//#174552 end |
1505 |
//#174552 end |
1506 |
|
1506 |
|
1507 |
// rhs |
1507 |
// rhs |
1508 |
copyTo(localPointer, rhsBounds[0]); |
1508 |
copyTo(localPointer, rhsBounds[0]); |
1509 |
localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds); |
1509 |
localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds); |
Lines 1858-1864
Link Here
|
1858 |
localPointer = tokenSequence.offset(); |
1858 |
localPointer = tokenSequence.offset(); |
1859 |
} |
1859 |
} |
1860 |
} |
1860 |
} |
1861 |
|
1861 |
|
1862 |
localPointer = diffAnnotationsLists(oldT.getAnnotations(), newT.getAnnotations(), startPos, localPointer); |
1862 |
localPointer = diffAnnotationsLists(oldT.getAnnotations(), newT.getAnnotations(), startPos, localPointer); |
1863 |
|
1863 |
|
1864 |
if ((oldT.flags & Flags.ANNOTATION) != 0) { |
1864 |
if ((oldT.flags & Flags.ANNOTATION) != 0) { |
Lines 1904-1910
Link Here
|
1904 |
|
1904 |
|
1905 |
private int diffAnnotationsLists(com.sun.tools.javac.util.List<JCAnnotation> oldAnnotations, com.sun.tools.javac.util.List<JCAnnotation> newAnnotations, int startPos, int localPointer) { |
1905 |
private int diffAnnotationsLists(com.sun.tools.javac.util.List<JCAnnotation> oldAnnotations, com.sun.tools.javac.util.List<JCAnnotation> newAnnotations, int startPos, int localPointer) { |
1906 |
int annotationsEnd = oldAnnotations.nonEmpty() ? endPos(oldAnnotations) : localPointer; |
1906 |
int annotationsEnd = oldAnnotations.nonEmpty() ? endPos(oldAnnotations) : localPointer; |
1907 |
|
1907 |
|
1908 |
if (listsMatch(oldAnnotations, newAnnotations)) { |
1908 |
if (listsMatch(oldAnnotations, newAnnotations)) { |
1909 |
copyTo(localPointer, localPointer = (annotationsEnd != localPointer ? annotationsEnd : startPos)); |
1909 |
copyTo(localPointer, localPointer = (annotationsEnd != localPointer ? annotationsEnd : startPos)); |
1910 |
} else { |
1910 |
} else { |
Lines 2344-2350
Link Here
|
2344 |
{ |
2344 |
{ |
2345 |
return diffParameterList(oldList, newList, null, makeAround, pos, measure, spaceBefore, spaceAfter, isEnum, separator); |
2345 |
return diffParameterList(oldList, newList, null, makeAround, pos, measure, spaceBefore, spaceAfter, isEnum, separator); |
2346 |
} |
2346 |
} |
2347 |
|
2347 |
|
2348 |
private int diffParameterList( |
2348 |
private int diffParameterList( |
2349 |
List<? extends JCTree> oldList, |
2349 |
List<? extends JCTree> oldList, |
2350 |
List<? extends JCTree> newList, |
2350 |
List<? extends JCTree> newList, |
Lines 2583-2589
Link Here
|
2583 |
} |
2583 |
} |
2584 |
case INSERT: { |
2584 |
case INSERT: { |
2585 |
JCVariableDecl decl = (JCVariableDecl) item.element; |
2585 |
JCVariableDecl decl = (JCVariableDecl) item.element; |
2586 |
|
2586 |
|
2587 |
if (oldIndex == 0) { |
2587 |
if (oldIndex == 0) { |
2588 |
int oldPrec = printer.setPrec(TreeInfo.noPrec); |
2588 |
int oldPrec = printer.setPrec(TreeInfo.noPrec); |
2589 |
printer.visitVarDef(decl); |
2589 |
printer.visitVarDef(decl); |
Lines 2890-2896
Link Here
|
2890 |
printer.print(this.printer.toString()); |
2890 |
printer.print(this.printer.toString()); |
2891 |
this.printer = oldPrinter; |
2891 |
this.printer = oldPrinter; |
2892 |
this.printer.undent(old); |
2892 |
this.printer.undent(old); |
2893 |
lastdel = null; |
2893 |
//lastdel = null; |
2894 |
break; |
2894 |
break; |
2895 |
} |
2895 |
} |
2896 |
} |
2896 |
} |
Lines 2938-2944
Link Here
|
2938 |
protected int diffPrecedingComments(JCTree oldT, JCTree newT, int localPointer) { |
2938 |
protected int diffPrecedingComments(JCTree oldT, JCTree newT, int localPointer) { |
2939 |
return diffPrecedingComments(oldT, newT, getOldPos(oldT), localPointer); |
2939 |
return diffPrecedingComments(oldT, newT, getOldPos(oldT), localPointer); |
2940 |
} |
2940 |
} |
2941 |
|
2941 |
|
2942 |
protected int diffPrecedingComments(JCTree oldT, JCTree newT, int oldTreeStartPos, int localPointer) { |
2942 |
protected int diffPrecedingComments(JCTree oldT, JCTree newT, int oldTreeStartPos, int localPointer) { |
2943 |
CommentSet cs = comments.getComments(newT); |
2943 |
CommentSet cs = comments.getComments(newT); |
2944 |
CommentSet old = comments.getComments(oldT); |
2944 |
CommentSet old = comments.getComments(oldT); |
Lines 2964-2970
Link Here
|
2964 |
while (printer.out.isWhitespaceLine()) |
2964 |
while (printer.out.isWhitespaceLine()) |
2965 |
printer.eatChars(1); |
2965 |
printer.eatChars(1); |
2966 |
} |
2966 |
} |
2967 |
|
2967 |
|
2968 |
localPointer = diffCommentLists(getOldPos(oldT), oldInlineComments, newInlineComments, false, false, localPointer); |
2968 |
localPointer = diffCommentLists(getOldPos(oldT), oldInlineComments, newInlineComments, false, false, localPointer); |
2969 |
|
2969 |
|
2970 |
boolean containedEmbeddedNewLine = false; |
2970 |
boolean containedEmbeddedNewLine = false; |
Lines 2973-2979
Link Here
|
2973 |
for (Comment oldComment : oldInlineComments) { |
2973 |
for (Comment oldComment : oldInlineComments) { |
2974 |
if (oldComment.style() == Style.LINE) containedEmbeddedNewLine = true; |
2974 |
if (oldComment.style() == Style.LINE) containedEmbeddedNewLine = true; |
2975 |
} |
2975 |
} |
2976 |
|
2976 |
|
2977 |
for (Comment nueComment : newInlineComments) { |
2977 |
for (Comment nueComment : newInlineComments) { |
2978 |
if (nueComment.style() == Style.LINE) containsEmbeddedNewLine = true; |
2978 |
if (nueComment.style() == Style.LINE) containsEmbeddedNewLine = true; |
2979 |
} |
2979 |
} |
Lines 2990-2996
Link Here
|
2990 |
Iterator<Comment> newIter = newList.iterator(); |
2990 |
Iterator<Comment> newIter = newList.iterator(); |
2991 |
Comment oldC = safeNext(oldIter); |
2991 |
Comment oldC = safeNext(oldIter); |
2992 |
Comment newC = safeNext(newIter); |
2992 |
Comment newC = safeNext(newIter); |
2993 |
|
2993 |
|
2994 |
while (oldC != null && newC != null) { |
2994 |
while (oldC != null && newC != null) { |
2995 |
if (!commentsMatch(oldC, newC)) return false; |
2995 |
if (!commentsMatch(oldC, newC)) return false; |
2996 |
oldC = safeNext(oldIter); |
2996 |
oldC = safeNext(oldIter); |
Lines 2999-3005
Link Here
|
2999 |
|
2999 |
|
3000 |
return !((oldC == null) ^ (newC == null)); |
3000 |
return !((oldC == null) ^ (newC == null)); |
3001 |
} |
3001 |
} |
3002 |
|
3002 |
|
3003 |
// refactor it! make it better |
3003 |
// refactor it! make it better |
3004 |
private int diffCommentLists(int oldTreeStartPos, List<Comment>oldList, |
3004 |
private int diffCommentLists(int oldTreeStartPos, List<Comment>oldList, |
3005 |
List<Comment>newList, boolean trailing, boolean preceding, int localPointer) { |
3005 |
List<Comment>newList, boolean trailing, boolean preceding, int localPointer) { |
Lines 3058-3064
Link Here
|
3058 |
} |
3058 |
} |
3059 |
while (newC != null) { |
3059 |
while (newC != null) { |
3060 |
if (Style.WHITESPACE != newC.style()) { |
3060 |
if (Style.WHITESPACE != newC.style()) { |
3061 |
// printer.print(newC.getText()); |
3061 |
// printer.print(newC.getText()); |
3062 |
if (!firstNewCommentPrinted && preceding) { |
3062 |
if (!firstNewCommentPrinted && preceding) { |
3063 |
copyTo(localPointer, localPointer = oldTreeStartPos); |
3063 |
copyTo(localPointer, localPointer = oldTreeStartPos); |
3064 |
} |
3064 |
} |
Lines 3204-3210
Link Here
|
3204 |
return oldBounds[1]; |
3204 |
return oldBounds[1]; |
3205 |
} |
3205 |
} |
3206 |
} |
3206 |
} |
3207 |
|
3207 |
|
3208 |
int commentsStart = Math.min(commentStart(comments.getComments(oldT), CommentSet.RelativePosition.INLINE), commentStart(comments.getComments(oldT), CommentSet.RelativePosition.TRAILING)); |
3208 |
int commentsStart = Math.min(commentStart(comments.getComments(oldT), CommentSet.RelativePosition.INLINE), commentStart(comments.getComments(oldT), CommentSet.RelativePosition.TRAILING)); |
3209 |
if (commentsStart < elementBounds[1]) { |
3209 |
if (commentsStart < elementBounds[1]) { |
3210 |
int lastIndex; |
3210 |
int lastIndex; |