1 11 package org.eclipse.jdt.internal.corext.refactoring.changes; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.SubProgressMonitor; 16 17 import org.eclipse.core.resources.IFile; 18 import org.eclipse.core.resources.IResource; 19 20 import org.eclipse.core.filebuffers.FileBuffers; 21 import org.eclipse.core.filebuffers.ITextFileBuffer; 22 import org.eclipse.core.filebuffers.LocationKind; 23 24 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; 25 import org.eclipse.jdt.internal.corext.refactoring.base.JDTChange; 26 import org.eclipse.ltk.core.refactoring.Change; 27 28 abstract class AbstractDeleteChange extends JDTChange { 29 30 protected abstract Change doDelete(IProgressMonitor pm) throws CoreException; 31 32 35 public final Change perform(IProgressMonitor pm) throws CoreException { 36 try { 37 pm.beginTask(RefactoringCoreMessages.AbstractDeleteChange_deleting, 1); 38 Change undo= doDelete(pm); 39 return undo; 40 } finally { 41 pm.done(); 42 } 43 } 44 45 protected static void saveFileIfNeeded(IFile file, IProgressMonitor pm) throws CoreException { 46 ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE); 47 if (buffer != null && buffer.isDirty() && buffer.isStateValidated() && buffer.isSynchronized()) { 48 pm.beginTask("", 2); buffer.commit(new SubProgressMonitor(pm, 1), false); 50 file.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(pm, 1)); 51 pm.done(); 52 } else { 53 pm.beginTask("", 1); pm.worked(1); 55 pm.done(); 56 } 57 } 58 } 59 60 | Popular Tags |