1 11 package org.eclipse.text.edits; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.core.runtime.Assert; 20 21 22 29 public final class TextEditCopier { 30 31 private TextEdit fEdit; 32 private Map fCopies; 33 34 43 public TextEditCopier(TextEdit edit) { 44 super(); 45 Assert.isNotNull(edit); 46 fEdit= edit; 47 fCopies= new HashMap (); 48 } 49 50 55 public TextEdit perform() { 56 TextEdit result= doCopy(fEdit); 57 if (result != null) { 58 for (Iterator iter= fCopies.keySet().iterator(); iter.hasNext();) { 59 TextEdit edit= (TextEdit)iter.next(); 60 edit.postProcessCopy(this); 61 } 62 } 63 return result; 64 } 65 66 74 public TextEdit getCopy(TextEdit original) { 75 Assert.isNotNull(original); 76 return (TextEdit)fCopies.get(original); 77 } 78 79 81 private TextEdit doCopy(TextEdit edit) { 82 TextEdit result= edit.doCopy(); 83 List children= edit.internalGetChildren(); 84 if (children != null) { 85 List newChildren= new ArrayList (children.size()); 86 for (Iterator iter= children.iterator(); iter.hasNext();) { 87 TextEdit childCopy= doCopy((TextEdit)iter.next()); 88 childCopy.internalSetParent(result); 89 newChildren.add(childCopy); 90 } 91 result.internalSetChildren(newChildren); 92 } 93 addCopy(edit, result); 94 return result; 95 } 96 97 private void addCopy(TextEdit original, TextEdit copy) { 98 fCopies.put(original, copy); 99 } 100 } 101 | Popular Tags |