1 11 package org.eclipse.ltk.core.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 16 import org.eclipse.ltk.core.refactoring.history.IRefactoringExecutionListener; 17 import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryListener; 18 import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService; 19 20 88 public abstract class RefactoringDescriptor implements Comparable { 89 90 103 public static final int BREAKING_CHANGE= 1 << 0; 104 105 118 public static final String ID_UNKNOWN= "org.eclipse.ltk.core.refactoring.unknown"; 120 131 public static final int MULTI_CHANGE= 1 << 2; 132 133 134 public static final int NONE= 0; 135 136 148 public static final int STRUCTURAL_CHANGE= 1 << 1; 149 150 159 public static final int USER_CHANGE= 1 << 8; 160 161 162 private String fComment; 163 164 165 private String fDescription; 166 167 168 private int fFlags; 169 170 171 private String fProject; 172 173 174 private final String fRefactoringId; 175 176 180 private long fTimeStamp= -1; 181 182 200 protected RefactoringDescriptor(final String id, final String project, final String description, final String comment, final int flags) { 201 Assert.isNotNull(id); 202 Assert.isLegal(!"".equals(id), "Refactoring id must not be empty"); Assert.isLegal(project == null || !"".equals(project), "Project must either be null or non-empty"); Assert.isNotNull(description); 205 Assert.isLegal(!"".equals(description), "Description must not be empty"); Assert.isLegal(flags >= NONE, "Flags must be non-negative"); fRefactoringId= id; 208 fDescription= description; 209 fProject= project; 210 fComment= comment; 211 fFlags= flags; 212 } 213 214 217 public final int compareTo(final Object object) { 218 if (object instanceof RefactoringDescriptor) { 219 final RefactoringDescriptor descriptor= (RefactoringDescriptor) object; 220 final long delta= fTimeStamp - descriptor.fTimeStamp; 221 if (delta < 0) 222 return -1; 223 else if (delta > 0) 224 return +1; 225 } 226 return 0; 227 } 228 229 251 public abstract Refactoring createRefactoring(RefactoringStatus status) throws CoreException; 252 253 256 public final boolean equals(final Object object) { 257 if (object instanceof RefactoringDescriptor) { 258 final RefactoringDescriptor descriptor= (RefactoringDescriptor) object; 259 return fTimeStamp == descriptor.fTimeStamp && getDescription().equals(descriptor.getDescription()); 260 } 261 return false; 262 } 263 264 273 public final String getComment() { 274 return (fComment != null) ? fComment : ""; } 276 277 285 public final String getDescription() { 286 return fDescription; 287 } 288 289 294 public final int getFlags() { 295 return fFlags; 296 } 297 298 303 public final String getID() { 304 return fRefactoringId; 305 } 306 307 312 public final String getProject() { 313 return fProject; 314 } 315 316 322 public final long getTimeStamp() { 323 return fTimeStamp; 324 } 325 326 329 public final int hashCode() { 330 int code= getDescription().hashCode(); 331 if (fTimeStamp >= 0) 332 code+= (17 * fTimeStamp); 333 return code; 334 } 335 336 346 public void setComment(final String comment) { 347 fComment= comment; 348 } 349 350 362 public void setDescription(final String description) { 363 Assert.isNotNull(description); 364 Assert.isLegal(!"".equals(description), "Description must not be empty"); fDescription= description; 366 } 367 368 380 public void setFlags(final int flags) { 381 Assert.isLegal(flags >= NONE, "Flags must be non-negative"); fFlags= flags; 383 } 384 385 396 public void setProject(final String project) { 397 Assert.isLegal(project == null || !"".equals(project), "Project must either be null or non-empty"); fProject= project; 399 } 400 401 412 public void setTimeStamp(final long stamp) { 413 Assert.isTrue(stamp >= 0); 414 fTimeStamp= stamp; 415 } 416 417 420 public String toString() { 421 422 final StringBuffer buffer= new StringBuffer (128); 423 424 buffer.append(getClass().getName()); 425 if (fRefactoringId.equals(ID_UNKNOWN)) 426 buffer.append("[unknown refactoring]"); else { 428 buffer.append("[timeStamp="); buffer.append(fTimeStamp); 430 buffer.append(",id="); buffer.append(fRefactoringId); 432 buffer.append(",description="); buffer.append(fDescription); 434 buffer.append(",project="); buffer.append(fProject); 436 buffer.append(",comment="); buffer.append(fComment); 438 buffer.append(",flags="); buffer.append(fFlags); 440 buffer.append("]"); } 442 443 return buffer.toString(); 444 } 445 } 446 | Popular Tags |