1 11 package org.eclipse.jface.internal.text.revisions; 12 13 import java.util.Iterator ; 14 import java.util.List ; 15 16 import org.eclipse.jface.text.source.ILineDiffInfo; 17 import org.eclipse.jface.text.source.ILineDiffer; 18 19 20 25 public final class DiffApplier { 26 34 public void applyDiff(List regions, ILineDiffer lineDiffer, int numberOfLines) { 35 clearDiffs(regions); 36 37 int added= 0; 38 int changed= 0; 39 ILineDiffInfo info= null; 40 for (int line= 0; line < numberOfLines; line++) { 41 info= lineDiffer.getLineInfo(line); 42 if (info == null) 43 continue; 44 45 int changeType= info.getChangeType(); 46 switch (changeType) { 47 case ILineDiffInfo.ADDED: 48 added++; 49 continue; 50 case ILineDiffInfo.CHANGED: 51 changed++; 52 continue; 53 case ILineDiffInfo.UNCHANGED: 54 added -= info.getRemovedLinesAbove(); 55 if (added != 0 || changed != 0) { 56 applyDiff(regions, new Hunk(line - changed - Math.max(0, added), added, changed)); 57 added= 0; 58 changed= 0; 59 info= null; 60 } 61 } 62 } 63 64 if (info != null) { 66 added -= info.getRemovedLinesAbove(); 67 if (added != 0 || changed != 0) { 68 applyDiff(regions, new Hunk(numberOfLines - changed, added, changed)); 69 added= 0; 70 changed= 0; 71 } 72 73 } 74 75 } 76 77 private void clearDiffs(List regions) { 78 for (Iterator it= regions.iterator(); it.hasNext();) { 79 ChangeRegion region= (ChangeRegion) it.next(); 80 region.clearDiff(); 81 } 82 } 83 84 90 private void applyDiff(List regions, Hunk hunk) { 91 for (Iterator it= regions.iterator(); it.hasNext();) { 92 ChangeRegion region= (ChangeRegion) it.next(); 93 region.adjustTo(hunk); 94 } 95 } 96 } | Popular Tags |