17
17
18
18
import com .github .difflib .patch .ChangeDelta ;
19
19
import com .github .difflib .patch .Chunk ;
20
- import com .github .difflib .patch .Delta ;
20
+ import com .github .difflib .patch .AbstractDelta ;
21
21
import com .github .difflib .patch .Patch ;
22
22
import java .util .ArrayList ;
23
23
import java .util .List ;
@@ -146,21 +146,21 @@ public static List<String> generateUnifiedDiff(String originalFileName,
146
146
ret .add ("--- " + originalFileName );
147
147
ret .add ("+++ " + revisedFileName );
148
148
149
- List <Delta <String >> patchDeltas = new ArrayList <>(
149
+ List <AbstractDelta <String >> patchDeltas = new ArrayList <>(
150
150
patch .getDeltas ());
151
151
152
152
// code outside the if block also works for single-delta issues.
153
- List <Delta <String >> deltas = new ArrayList <>(); // current
153
+ List <AbstractDelta <String >> deltas = new ArrayList <>(); // current
154
154
// list
155
155
// of
156
156
// Delta's to
157
157
// process
158
- Delta <String > delta = patchDeltas .get (0 );
158
+ AbstractDelta <String > delta = patchDeltas .get (0 );
159
159
deltas .add (delta ); // add the first Delta to the current set
160
160
// if there's more than 1 Delta, we may need to output them together
161
161
if (patchDeltas .size () > 1 ) {
162
162
for (int i = 1 ; i < patchDeltas .size (); i ++) {
163
- int position = delta .getOriginal ().getPosition (); // store
163
+ int position = delta .getSource ().getPosition (); // store
164
164
// the
165
165
// current
166
166
// position
@@ -170,9 +170,9 @@ public static List<String> generateUnifiedDiff(String originalFileName,
170
170
// Check if the next Delta is too close to the current
171
171
// position.
172
172
// And if it is, add it to the current set
173
- Delta <String > nextDelta = patchDeltas .get (i );
174
- if ((position + delta .getOriginal ().size () + contextSize ) >= (nextDelta
175
- .getOriginal ().getPosition () - contextSize )) {
173
+ AbstractDelta <String > nextDelta = patchDeltas .get (i );
174
+ if ((position + delta .getSource ().size () + contextSize ) >= (nextDelta
175
+ .getSource ().getPosition () - contextSize )) {
176
176
deltas .add (nextDelta );
177
177
} else {
178
178
// if it isn't, output the current set,
@@ -207,65 +207,65 @@ public static List<String> generateUnifiedDiff(String originalFileName,
207
207
* @author Bill James (tankerbay@gmail.com)
208
208
*/
209
209
private static List <String > processDeltas (List <String > origLines ,
210
- List <Delta <String >> deltas , int contextSize ) {
210
+ List <AbstractDelta <String >> deltas , int contextSize ) {
211
211
List <String > buffer = new ArrayList <>();
212
212
int origTotal = 0 ; // counter for total lines output from Original
213
213
int revTotal = 0 ; // counter for total lines output from Original
214
214
int line ;
215
215
216
- Delta <String > curDelta = deltas .get (0 );
216
+ AbstractDelta <String > curDelta = deltas .get (0 );
217
217
218
218
// NOTE: +1 to overcome the 0-offset Position
219
- int origStart = curDelta .getOriginal ().getPosition () + 1 - contextSize ;
219
+ int origStart = curDelta .getSource ().getPosition () + 1 - contextSize ;
220
220
if (origStart < 1 ) {
221
221
origStart = 1 ;
222
222
}
223
223
224
- int revStart = curDelta .getRevised ().getPosition () + 1 - contextSize ;
224
+ int revStart = curDelta .getTarget ().getPosition () + 1 - contextSize ;
225
225
if (revStart < 1 ) {
226
226
revStart = 1 ;
227
227
}
228
228
229
229
// find the start of the wrapper context code
230
- int contextStart = curDelta .getOriginal ().getPosition () - contextSize ;
230
+ int contextStart = curDelta .getSource ().getPosition () - contextSize ;
231
231
if (contextStart < 0 ) {
232
232
contextStart = 0 ; // clamp to the start of the file
233
233
}
234
234
235
235
// output the context before the first Delta
236
- for (line = contextStart ; line < curDelta .getOriginal ().getPosition (); line ++) { //
236
+ for (line = contextStart ; line < curDelta .getSource ().getPosition (); line ++) { //
237
237
buffer .add (" " + origLines .get (line ));
238
238
origTotal ++;
239
239
revTotal ++;
240
240
}
241
241
242
242
// output the first Delta
243
243
buffer .addAll (getDeltaText (curDelta ));
244
- origTotal += curDelta .getOriginal ().getLines ().size ();
245
- revTotal += curDelta .getRevised ().getLines ().size ();
244
+ origTotal += curDelta .getSource ().getLines ().size ();
245
+ revTotal += curDelta .getTarget ().getLines ().size ();
246
246
247
247
int deltaIndex = 1 ;
248
248
while (deltaIndex < deltas .size ()) { // for each of the other Deltas
249
- Delta <String > nextDelta = deltas .get (deltaIndex );
250
- int intermediateStart = curDelta .getOriginal ().getPosition ()
251
- + curDelta .getOriginal ().getLines ().size ();
252
- for (line = intermediateStart ; line < nextDelta .getOriginal ()
249
+ AbstractDelta <String > nextDelta = deltas .get (deltaIndex );
250
+ int intermediateStart = curDelta .getSource ().getPosition ()
251
+ + curDelta .getSource ().getLines ().size ();
252
+ for (line = intermediateStart ; line < nextDelta .getSource ()
253
253
.getPosition (); line ++) {
254
254
// output the code between the last Delta and this one
255
255
buffer .add (" " + origLines .get (line ));
256
256
origTotal ++;
257
257
revTotal ++;
258
258
}
259
259
buffer .addAll (getDeltaText (nextDelta )); // output the Delta
260
- origTotal += nextDelta .getOriginal ().getLines ().size ();
261
- revTotal += nextDelta .getRevised ().getLines ().size ();
260
+ origTotal += nextDelta .getSource ().getLines ().size ();
261
+ revTotal += nextDelta .getTarget ().getLines ().size ();
262
262
curDelta = nextDelta ;
263
263
deltaIndex ++;
264
264
}
265
265
266
266
// Now output the post-Delta context code, clamping the end of the file
267
- contextStart = curDelta .getOriginal ().getPosition ()
268
- + curDelta .getOriginal ().getLines ().size ();
267
+ contextStart = curDelta .getSource ().getPosition ()
268
+ + curDelta .getSource ().getLines ().size ();
269
269
for (line = contextStart ; (line < (contextStart + contextSize ))
270
270
&& (line < origLines .size ()); line ++) {
271
271
buffer .add (" " + origLines .get (line ));
@@ -275,7 +275,7 @@ private static List<String> processDeltas(List<String> origLines,
275
275
276
276
// Create and insert the block header, conforming to the Unified Diff
277
277
// standard
278
- StringBuffer header = new StringBuffer ();
278
+ StringBuilder header = new StringBuilder ();
279
279
header .append ("@@ -" );
280
280
header .append (origStart );
281
281
header .append ("," );
@@ -297,12 +297,12 @@ private static List<String> processDeltas(List<String> origLines,
297
297
* @return list of String lines of code.
298
298
* @author Bill James (tankerbay@gmail.com)
299
299
*/
300
- private static List <String > getDeltaText (Delta <String > delta ) {
300
+ private static List <String > getDeltaText (AbstractDelta <String > delta ) {
301
301
List <String > buffer = new ArrayList <>();
302
- for (String line : delta .getOriginal ().getLines ()) {
302
+ for (String line : delta .getSource ().getLines ()) {
303
303
buffer .add ("-" + line );
304
304
}
305
- for (String line : delta .getRevised ().getLines ()) {
305
+ for (String line : delta .getTarget ().getLines ()) {
306
306
buffer .add ("+" + line );
307
307
}
308
308
return buffer ;
0 commit comments