1 11 package org.eclipse.ltk.core.refactoring.participants; 12 13 import java.util.Arrays ; 14 import java.util.HashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 22 import org.eclipse.core.resources.IFile; 23 import org.eclipse.core.resources.IResource; 24 25 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 26 27 import org.eclipse.ltk.internal.core.refactoring.RefactoringCoreMessages; 28 import org.eclipse.ltk.internal.core.refactoring.Resources; 29 30 52 public class ValidateEditChecker implements IConditionChecker { 53 54 private Set fFiles= new HashSet (); 55 private Object fContext; 56 57 67 public ValidateEditChecker(Object context) { 68 fContext= context; 69 } 70 71 76 public void addFile(IFile file) { 77 Assert.isNotNull(file); 78 fFiles.add(file); 79 } 80 81 86 public void addFiles(IFile[] files) { 87 Assert.isNotNull(files); 88 fFiles.addAll(Arrays.asList(files)); 89 } 90 91 94 public RefactoringStatus check(IProgressMonitor monitor) throws CoreException { 95 IResource[] resources= (IResource[])fFiles.toArray(new IResource[fFiles.size()]); 96 RefactoringStatus result= new RefactoringStatus(); 97 IStatus status= Resources.checkInSync(resources); 98 if (!status.isOK()) 99 result.merge(RefactoringStatus.create(status)); 100 status= Resources.makeCommittable(resources, fContext); 101 if (!status.isOK()) { 102 result.merge(RefactoringStatus.create(status)); 103 if (!result.hasFatalError()) { 104 result.addFatalError(RefactoringCoreMessages.ValidateEditChecker_failed); 105 } 106 } 107 return result; 108 } 109 } 110 | Popular Tags |