1 11 package org.eclipse.jface.internal.text.revisions; 12 13 import java.util.ArrayList ; 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 HunkComputer { 26 34 public static Hunk[] computeHunks(ILineDiffer differ, int lines) { 35 List hunks= new ArrayList (lines); 36 37 int added= 0; 38 int changed= 0; 39 ILineDiffInfo info= null; 40 for (int line= 0; line < lines; line++) { 41 info= differ.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 hunks.add(new Hunk(line - changed - Math.max(0, added), added, changed)); 57 added= 0; 58 changed= 0; 59 } 60 } 61 } 62 63 if (info != null) { 65 added -= info.getRemovedLinesBelow(); 66 if (added != 0 || changed != 0) { 67 hunks.add(new Hunk(lines - changed, added, changed)); 68 added= 0; 69 changed= 0; 70 } 71 } 72 73 return (Hunk[]) hunks.toArray(new Hunk[hunks.size()]); 74 } 75 private HunkComputer() { 76 } 77 } | Popular Tags |