Lines 47-53
Link Here
|
47 |
import org.netbeans.api.java.source.Comment.Style; |
47 |
import org.netbeans.api.java.source.Comment.Style; |
48 |
import org.netbeans.modules.java.source.transform.FieldGroupTree; |
48 |
import org.netbeans.modules.java.source.transform.FieldGroupTree; |
49 |
import static com.sun.source.tree.Tree.*; |
49 |
import static com.sun.source.tree.Tree.*; |
50 |
import org.netbeans.api.java.lexer.JavaTokenId; |
|
|
51 |
import org.netbeans.api.lexer.TokenSequence; |
50 |
import org.netbeans.api.lexer.TokenSequence; |
52 |
import org.netbeans.modules.java.source.builder.CommentHandlerService; |
51 |
import org.netbeans.modules.java.source.builder.CommentHandlerService; |
53 |
import org.netbeans.api.java.source.Comment; |
52 |
import org.netbeans.api.java.source.Comment; |
Lines 85-103
Link Here
|
85 |
private static final Logger LOG = Logger.getLogger(CasualDiff.class.getName()); |
84 |
private static final Logger LOG = Logger.getLogger(CasualDiff.class.getName()); |
86 |
|
85 |
|
87 |
private Map<Integer, String> diffInfo = new HashMap<Integer, String>(); |
86 |
private Map<Integer, String> diffInfo = new HashMap<Integer, String>(); |
|
|
87 |
private final Map<Tree, ?> tree2Tag; |
88 |
private final Map<Object, int[]> tag2Span; |
88 |
|
89 |
|
89 |
// used for diffing var def, when parameter is printed, annotation of |
90 |
// used for diffing var def, when parameter is printed, annotation of |
90 |
// such variable should not provide new line at the end. |
91 |
// such variable should not provide new line at the end. |
91 |
private boolean parameterPrint = false; |
92 |
private boolean parameterPrint = false; |
92 |
|
93 |
|
93 |
protected CasualDiff(Context context, WorkingCopy workingCopy) { |
94 |
protected CasualDiff(Context context, WorkingCopy workingCopy, Map<Tree, ?> tree2Tag, Map<?, int[]> tag2Span) { |
94 |
diffs = new ListBuffer<Diff>(); |
95 |
diffs = new ListBuffer<Diff>(); |
95 |
comments = CommentHandlerService.instance(context); |
96 |
comments = CommentHandlerService.instance(context); |
96 |
this.workingCopy = workingCopy; |
97 |
this.workingCopy = workingCopy; |
97 |
this.tokenSequence = workingCopy.getTokenHierarchy().tokenSequence(JavaTokenId.language()); |
98 |
this.tokenSequence = workingCopy.getTokenHierarchy().tokenSequence(JavaTokenId.language()); |
98 |
this.origText = workingCopy.getText(); |
99 |
this.origText = workingCopy.getText(); |
99 |
this.context = context; |
100 |
this.context = context; |
100 |
printer = new VeryPretty(workingCopy, CodeStyle.getDefault(null)); |
101 |
this.tree2Tag = tree2Tag; |
|
|
102 |
this.tag2Span = (Map<Object, int[]>) tag2Span;//XXX |
103 |
printer = new VeryPretty(workingCopy, CodeStyle.getDefault(null), tree2Tag, tag2Span); |
101 |
} |
104 |
} |
102 |
|
105 |
|
103 |
public com.sun.tools.javac.util.List<Diff> getDiffs() { |
106 |
public com.sun.tools.javac.util.List<Diff> getDiffs() { |
Lines 108-116
Link Here
|
108 |
WorkingCopy copy, |
111 |
WorkingCopy copy, |
109 |
TreePath oldTreePath, |
112 |
TreePath oldTreePath, |
110 |
JCTree newTree, |
113 |
JCTree newTree, |
111 |
Map<Integer, String> userInfo) |
114 |
Map<Integer, String> userInfo, |
|
|
115 |
Map<Tree, ?> tree2Tag, |
116 |
Map<?, int[]> tag2Span) |
112 |
{ |
117 |
{ |
113 |
CasualDiff td = new CasualDiff(context, copy); |
118 |
CasualDiff td = new CasualDiff(context, copy, tree2Tag, tag2Span); |
114 |
JCTree oldTree = (JCTree) oldTreePath.getLeaf(); |
119 |
JCTree oldTree = (JCTree) oldTreePath.getLeaf(); |
115 |
td.oldTopLevel = (JCCompilationUnit) (oldTree.getKind() == Kind.COMPILATION_UNIT ? oldTree : copy.getCompilationUnit()); |
120 |
td.oldTopLevel = (JCCompilationUnit) (oldTree.getKind() == Kind.COMPILATION_UNIT ? oldTree : copy.getCompilationUnit()); |
116 |
|
121 |
|
Lines 125-130
Link Here
|
125 |
} |
130 |
} |
126 |
|
131 |
|
127 |
int[] bounds = td.getBounds(oldTree); |
132 |
int[] bounds = td.getBounds(oldTree); |
|
|
133 |
td.printer.setInitialOffset(bounds[0]); |
128 |
boolean isCUT = oldTree.getKind() == Kind.COMPILATION_UNIT; |
134 |
boolean isCUT = oldTree.getKind() == Kind.COMPILATION_UNIT; |
129 |
int start = isCUT ? 0 : bounds[0]; |
135 |
int start = isCUT ? 0 : bounds[0]; |
130 |
int end = isCUT ? td.workingCopy.getText().length() : bounds[1]; |
136 |
int end = isCUT ? td.workingCopy.getText().length() : bounds[1]; |
Lines 175-183
Link Here
|
175 |
WorkingCopy copy, |
181 |
WorkingCopy copy, |
176 |
List<? extends ImportTree> original, |
182 |
List<? extends ImportTree> original, |
177 |
List<? extends ImportTree> nue, |
183 |
List<? extends ImportTree> nue, |
178 |
Map<Integer, String> userInfo) |
184 |
Map<Integer, String> userInfo, |
|
|
185 |
Map<Tree, ?> tree2Tag, |
186 |
Map<?, int[]> tag2Span) |
179 |
{ |
187 |
{ |
180 |
CasualDiff td = new CasualDiff(context, copy); |
188 |
CasualDiff td = new CasualDiff(context, copy, tree2Tag, tag2Span); |
181 |
td.oldTopLevel = (JCCompilationUnit) copy.getCompilationUnit(); |
189 |
td.oldTopLevel = (JCCompilationUnit) copy.getCompilationUnit(); |
182 |
int start = td.oldTopLevel.getPackageName() != null ? td.endPos(td.oldTopLevel.getPackageName()) : 0; |
190 |
int start = td.oldTopLevel.getPackageName() != null ? td.endPos(td.oldTopLevel.getPackageName()) : 0; |
183 |
|
191 |
|
Lines 2250-2256
Link Here
|
2250 |
found = true; |
2258 |
found = true; |
2251 |
VeryPretty oldPrinter = this.printer; |
2259 |
VeryPretty oldPrinter = this.printer; |
2252 |
int old = oldPrinter.indent(); |
2260 |
int old = oldPrinter.indent(); |
2253 |
this.printer = new VeryPretty(workingCopy); |
2261 |
this.printer = new VeryPretty(workingCopy, CodeStyle.getDefault(null), tree2Tag, tag2Span, oldPrinter.toString().length() + oldPrinter.getInitialOffset());//XXX |
2254 |
this.printer.reset(old); |
2262 |
this.printer.reset(old); |
2255 |
int index = oldList.indexOf(oldT); |
2263 |
int index = oldList.indexOf(oldT); |
2256 |
int[] poss = estimator.getPositions(index); |
2264 |
int[] poss = estimator.getPositions(index); |
Lines 2266-2272
Link Here
|
2266 |
if (lastdel != null && treesMatch(item.element, lastdel, false)) { |
2274 |
if (lastdel != null && treesMatch(item.element, lastdel, false)) { |
2267 |
VeryPretty oldPrinter = this.printer; |
2275 |
VeryPretty oldPrinter = this.printer; |
2268 |
int old = oldPrinter.indent(); |
2276 |
int old = oldPrinter.indent(); |
2269 |
this.printer = new VeryPretty(workingCopy); |
2277 |
this.printer = new VeryPretty(workingCopy, CodeStyle.getDefault(null), tree2Tag, tag2Span, oldPrinter.toString().length() + oldPrinter.getInitialOffset());//XXX |
2270 |
this.printer.reset(old); |
2278 |
this.printer.reset(old); |
2271 |
int index = oldList.indexOf(lastdel); |
2279 |
int index = oldList.indexOf(lastdel); |
2272 |
int[] poss = estimator.getPositions(index); |
2280 |
int[] poss = estimator.getPositions(index); |
Lines 2465-2471
Link Here
|
2465 |
* just returns. |
2473 |
* just returns. |
2466 |
* |
2474 |
* |
2467 |
* @param oldT original tree in source code |
2475 |
* @param oldT original tree in source code |
2468 |
* @param newT tree to repace the original tree |
2476 |
* @param newT tree to replace the original tree |
2469 |
* @return position in original source |
2477 |
* @return position in original source |
2470 |
*/ |
2478 |
*/ |
2471 |
protected int diffTree(JCTree oldT, JCTree newT, int[] elementBounds) { |
2479 |
protected int diffTree(JCTree oldT, JCTree newT, int[] elementBounds) { |
Lines 2473-2478
Link Here
|
2473 |
} |
2481 |
} |
2474 |
|
2482 |
|
2475 |
protected int diffTree(JCTree oldT, JCTree newT, JCTree parent /*used only for modifiers*/, int[] elementBounds) { |
2483 |
protected int diffTree(JCTree oldT, JCTree newT, JCTree parent /*used only for modifiers*/, int[] elementBounds) { |
|
|
2484 |
Object t = tree2Tag.get(newT); |
2485 |
int result; |
2486 |
if (t != null) { |
2487 |
int start = printer.toString().length(); |
2488 |
result = diffTreeImpl(oldT, newT, parent, elementBounds); |
2489 |
int end = printer.toString().length(); |
2490 |
tag2Span.put(t, new int[]{start + printer.getInitialOffset(), end + printer.getInitialOffset()}); |
2491 |
} else { |
2492 |
result = diffTreeImpl(oldT, newT, parent, elementBounds); |
2493 |
} |
2494 |
return result; |
2495 |
} |
2496 |
|
2497 |
protected int diffTreeImpl(JCTree oldT, JCTree newT, JCTree parent /*used only for modifiers*/, int[] elementBounds) { |
2476 |
if (oldT == null && newT != null) |
2498 |
if (oldT == null && newT != null) |
2477 |
throw new IllegalArgumentException("Null is not allowed in parameters."); |
2499 |
throw new IllegalArgumentException("Null is not allowed in parameters."); |
2478 |
|
2500 |
|