1 11 package org.eclipse.ltk.internal.core.refactoring; 12 13 import org.eclipse.text.edits.MalformedTreeException; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 19 import org.eclipse.core.resources.IFile; 20 21 import org.eclipse.jface.text.BadLocationException; 22 23 import org.eclipse.ltk.core.refactoring.IRefactoringCoreStatusCodes; 24 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 25 26 public class Changes { 27 28 public static RefactoringStatus validateModifiesFiles(IFile[] filesToModify) { 29 RefactoringStatus result= new RefactoringStatus(); 30 IStatus status= Resources.checkInSync(filesToModify); 31 if (!status.isOK()) 32 result.merge(RefactoringStatus.create(status)); 33 status= Resources.makeCommittable(filesToModify, null); 34 if (!status.isOK()) { 35 result.merge(RefactoringStatus.create(status)); 36 if (!result.hasFatalError()) { 37 result.addFatalError(RefactoringCoreMessages.Changes_validateEdit); 38 } 39 } 40 return result; 41 } 42 43 public static RefactoringStatus checkInSync(IFile[] filesToModify) { 44 RefactoringStatus result= new RefactoringStatus(); 45 IStatus status= Resources.checkInSync(filesToModify); 46 if (!status.isOK()) 47 result.merge(RefactoringStatus.create(status)); 48 return result; 49 } 50 51 public static CoreException asCoreException(BadLocationException e) { 52 String message= e.getMessage(); 53 if (message == null) 54 message= "BadLocationException"; return new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.BAD_LOCATION, message, e)); 56 } 57 58 public static CoreException asCoreException(MalformedTreeException e) { 59 String message= e.getMessage(); 60 if (message == null) 61 message= "MalformedTreeException"; return new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.BAD_LOCATION, message, e)); 63 } 64 } 65 | Popular Tags |