Mercurial > projects > dwt2
comparison org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | 5feec68b4556 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.text.edits.TextEditCopier; | |
14 | |
15 import org.eclipse.text.edits.MultiTextEdit; // packageimport | |
16 import org.eclipse.text.edits.CopySourceEdit; // packageimport | |
17 import org.eclipse.text.edits.MoveSourceEdit; // packageimport | |
18 import org.eclipse.text.edits.CopyingRangeMarker; // packageimport | |
19 import org.eclipse.text.edits.ReplaceEdit; // packageimport | |
20 import org.eclipse.text.edits.EditDocument; // packageimport | |
21 import org.eclipse.text.edits.UndoCollector; // packageimport | |
22 import org.eclipse.text.edits.DeleteEdit; // packageimport | |
23 import org.eclipse.text.edits.MoveTargetEdit; // packageimport | |
24 import org.eclipse.text.edits.CopyTargetEdit; // packageimport | |
25 import org.eclipse.text.edits.ISourceModifier; // packageimport | |
26 import org.eclipse.text.edits.TextEditMessages; // packageimport | |
27 import org.eclipse.text.edits.TextEditProcessor; // packageimport | |
28 import org.eclipse.text.edits.MalformedTreeException; // packageimport | |
29 import org.eclipse.text.edits.TreeIterationInfo; // packageimport | |
30 import org.eclipse.text.edits.TextEditVisitor; // packageimport | |
31 import org.eclipse.text.edits.TextEditGroup; // packageimport | |
32 import org.eclipse.text.edits.TextEdit; // packageimport | |
33 import org.eclipse.text.edits.RangeMarker; // packageimport | |
34 import org.eclipse.text.edits.UndoEdit; // packageimport | |
35 import org.eclipse.text.edits.InsertEdit; // packageimport | |
36 | |
37 | |
38 import java.lang.all; | |
39 import java.util.List; | |
40 import java.util.ArrayList; | |
41 import java.util.Iterator; | |
42 import java.util.Map; | |
43 import java.util.HashMap; | |
44 import java.util.Set; | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 import org.eclipse.core.runtime.Assert; | |
52 | |
53 | |
54 /** | |
55 * Copies a tree of text edits. A text edit copier keeps a map | |
56 * between original and new text edits. It can be used to map | |
57 * a copy back to its original edit. | |
58 * | |
59 * @since 3.0 | |
60 */ | |
61 public final class TextEditCopier { | |
62 | |
63 private TextEdit fEdit; | |
64 private Map fCopies; | |
65 | |
66 /** | |
67 * Constructs a new <code>TextEditCopier</code> for the | |
68 * given edit. The actual copy is done by calling <code> | |
69 * perform</code>. | |
70 * | |
71 * @param edit the edit to copy | |
72 * | |
73 * @see #perform() | |
74 */ | |
75 public this(TextEdit edit) { | |
76 // super(); | |
77 Assert.isNotNull(edit); | |
78 fEdit= edit; | |
79 fCopies= new HashMap(); | |
80 } | |
81 | |
82 /** | |
83 * Performs the actual copying. | |
84 * | |
85 * @return the copy | |
86 */ | |
87 public TextEdit perform() { | |
88 TextEdit result= doCopy(fEdit); | |
89 if (result !is null) { | |
90 for (Iterator iter= fCopies.keySet().iterator(); iter.hasNext();) { | |
91 TextEdit edit= cast(TextEdit)iter.next(); | |
92 edit.postProcessCopy_package(this); | |
93 } | |
94 } | |
95 return result; | |
96 } | |
97 | |
98 /** | |
99 * Returns the copy for the original text edit. | |
100 * | |
101 * @param original the original for which the copy | |
102 * is requested | |
103 * @return the copy of the original edit or <code>null</code> | |
104 * if the original isn't managed by this copier | |
105 */ | |
106 public TextEdit getCopy(TextEdit original) { | |
107 Assert.isNotNull(original); | |
108 return cast(TextEdit)fCopies.get(original); | |
109 } | |
110 | |
111 //---- helper methods -------------------------------------------- | |
112 | |
113 private TextEdit doCopy(TextEdit edit) { | |
114 TextEdit result= edit.doCopy_package(); | |
115 List children= edit.internalGetChildren(); | |
116 if (children !is null) { | |
117 List newChildren= new ArrayList(children.size()); | |
118 for (Iterator iter= children.iterator(); iter.hasNext();) { | |
119 TextEdit childCopy= doCopy(cast(TextEdit)iter.next()); | |
120 childCopy.internalSetParent(result); | |
121 newChildren.add(childCopy); | |
122 } | |
123 result.internalSetChildren(newChildren); | |
124 } | |
125 addCopy(edit, result); | |
126 return result; | |
127 } | |
128 | |
129 private void addCopy(TextEdit original, TextEdit copy) { | |
130 fCopies.put(original, copy); | |
131 } | |
132 } |