1 11 package org.eclipse.ltk.internal.core.refactoring; 12 13 import org.eclipse.text.edits.TextEdit; 14 import org.eclipse.text.edits.UndoEdit; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.NullProgressMonitor; 19 20 import org.eclipse.jface.text.BadLocationException; 21 import org.eclipse.jface.text.IDocument; 22 23 import org.eclipse.ltk.core.refactoring.Change; 24 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 25 26 public class UndoDocumentChange extends Change { 27 28 private String fName; 29 private UndoEdit fUndo; 30 private IDocument fDocument; 31 private int fLength; 32 33 public UndoDocumentChange(String name, IDocument document, UndoEdit undo) { 34 fName= name; 35 fUndo= undo; 36 fDocument= document; 37 } 38 39 42 public String getName() { 43 return fName; 44 } 45 46 49 public Object getModifiedElement() { 50 return null; 51 } 52 53 56 public void initializeValidationData(IProgressMonitor pm) { 57 fLength= fDocument.getLength(); 58 } 59 60 63 public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { 64 if (pm == null) 65 pm= new NullProgressMonitor(); 66 pm.beginTask("", 1); RefactoringStatus result= TextChanges.isValid(fDocument, fLength); 68 pm.worked(1); 69 return result; 70 } 71 72 75 public Change perform(IProgressMonitor pm) throws CoreException { 76 try { 77 UndoEdit redo= fUndo.apply(fDocument, TextEdit.CREATE_UNDO); 78 Change result= new UndoDocumentChange(getName(), fDocument, redo); 79 return result; 80 } catch (BadLocationException e) { 81 throw Changes.asCoreException(e); 82 } 83 } 84 } 85 | Popular Tags |