1 11 package org.eclipse.ui.internal.texteditor.quickdiff.compare.rangedifferencer; 12 13 import java.util.List ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.jface.text.IDocument; 18 19 import org.eclipse.ui.internal.texteditor.quickdiff.DiffRegion; 20 21 38 public class RangeDifference { 39 40 41 public final static int NOCHANGE= 0; 42 43 public final static int CHANGE= 2; 44 45 46 public final static int CONFLICT= 1; 47 48 public final static int RIGHT= 2; 49 50 public final static int LEFT= 3; 51 55 public final static int ANCESTOR= 4; 56 57 58 public final static int ERROR= 5; 59 60 61 final int fKind; 62 63 int fLeftStart; 64 int fLeftLength; 65 int fRightStart; 66 int fRightLength; 67 int lAncestorStart; 68 int lAncestorLength; 69 private DiffRegion fRegion; 70 71 76 public RangeDifference(int changeKind) { 77 fKind= changeKind; 78 } 79 80 90 public RangeDifference(int kind, int rightStart, int rightLength, int leftStart, int leftLength) { 91 fKind= kind; 92 fRightStart= rightStart; 93 fRightLength= rightLength; 94 fLeftStart= leftStart; 95 fLeftLength= leftLength; 96 } 97 98 110 public RangeDifference(int kind, int rightStart, int rightLength, int leftStart, int leftLength, 111 int ancestorStart, int ancestorLength) { 112 this(kind, rightStart, rightLength, leftStart, leftLength); 113 lAncestorStart= ancestorStart; 114 lAncestorLength= ancestorLength; 115 } 116 117 124 public int kind() { 125 return fKind; 126 } 127 128 133 public int ancestorStart() { 134 return lAncestorStart; 135 } 136 137 142 public int ancestorLength() { 143 return lAncestorLength; 144 } 145 146 151 public int ancestorEnd() { 152 return lAncestorStart + lAncestorLength; 153 } 154 155 160 public int rightStart() { 161 return fRightStart; 162 } 163 164 169 public int rightLength() { 170 return fRightLength; 171 } 172 173 178 public int rightEnd() { 179 return fRightStart + fRightLength; 180 } 181 182 187 public int leftStart() { 188 return fLeftStart; 189 } 190 191 196 public int leftLength() { 197 return fLeftLength; 198 } 199 200 205 public int leftEnd() { 206 return fLeftStart + fLeftLength; 207 } 208 209 214 public int maxLength() { 215 return Math.max(fRightLength, Math.max(fLeftLength, lAncestorLength)); 216 } 217 218 223 public void shiftLeft(int shift) { 224 Assert.isTrue(shift + fLeftStart >= 0); 225 fLeftStart += shift; 226 } 227 228 233 public void shiftRight(int shift) { 234 Assert.isTrue(shift + fRightStart >= 0); 235 fRightStart += shift; 236 } 237 238 244 public void extendStart(int shift) { 245 Assert.isTrue(shift + fRightStart >= 0); 246 Assert.isTrue(shift + fLeftStart >= 0); 247 fRightStart += shift; 248 fRightLength -= shift; 249 fLeftStart += shift; 250 fLeftLength -= shift; 251 } 252 253 259 public void extendEnd(int shift) { 260 Assert.isTrue(shift + fRightLength >= 0); 261 Assert.isTrue(shift + fLeftLength >= 0); 262 fRightLength += shift; 263 fLeftLength += shift; 264 } 265 266 269 public boolean equals(Object obj) { 270 if (obj instanceof RangeDifference) { 271 RangeDifference d= (RangeDifference) obj; 272 return fKind == d.fKind && fRightStart == d.fRightStart && fRightLength == d.fRightLength && fLeftStart == d.fLeftStart && fLeftLength == d.fLeftLength; 273 } 274 return false; 275 } 276 277 282 public final int hashCode() { 283 return super.hashCode(); 284 } 285 286 293 public DiffRegion getDiffRegion(List differences, IDocument source) { 294 if (fRegion == null) 295 fRegion= new DiffRegion(this, 0, differences, source); 296 return fRegion; 297 } 298 299 302 public String toString() { 303 StringBuffer buf= new StringBuffer ("RangeDifference {"); switch (fKind) { 305 case NOCHANGE: 306 buf.append("NOCHANGE"); break; 308 case CHANGE: 309 buf.append("CHANGE/RIGHT"); break; 311 case CONFLICT: 312 buf.append("CONFLICT"); break; 314 case LEFT: 315 buf.append("LEFT"); break; 317 case ERROR: 318 buf.append("ERROR"); break; 320 case ANCESTOR: 321 buf.append("ANCESTOR"); break; 323 default: 324 break; 325 } 326 327 buf.append(", Left: [" + fLeftStart + "+" + fLeftLength + ")"); buf.append(", Right: [" + fRightStart + "+" + fRightLength + ")"); buf.append("]"); 331 return buf.toString(); 332 } 333 } 334 335 | Popular Tags |