Mercurial > projects > dwt-addons
annotate dwtx/text/edits/TextEditCopier.d @ 153:f70d9508c95c
Fix java Collection imports
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 25 Aug 2008 00:27:31 +0200 |
parents | 51e6e63f930e |
children | 7926b636c282 |
rev | line source |
---|---|
129 | 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 dwtx.text.edits.TextEditCopier; | |
14 | |
131 | 15 import dwtx.text.edits.MultiTextEdit; // packageimport |
16 import dwtx.text.edits.CopySourceEdit; // packageimport | |
17 import dwtx.text.edits.MoveSourceEdit; // packageimport | |
18 import dwtx.text.edits.CopyingRangeMarker; // packageimport | |
19 import dwtx.text.edits.ReplaceEdit; // packageimport | |
20 import dwtx.text.edits.EditDocument; // packageimport | |
21 import dwtx.text.edits.UndoCollector; // packageimport | |
22 import dwtx.text.edits.DeleteEdit; // packageimport | |
23 import dwtx.text.edits.MoveTargetEdit; // packageimport | |
24 import dwtx.text.edits.CopyTargetEdit; // packageimport | |
25 import dwtx.text.edits.ISourceModifier; // packageimport | |
26 import dwtx.text.edits.TextEditMessages; // packageimport | |
27 import dwtx.text.edits.TextEditProcessor; // packageimport | |
28 import dwtx.text.edits.MalformedTreeException; // packageimport | |
29 import dwtx.text.edits.TreeIterationInfo; // packageimport | |
30 import dwtx.text.edits.TextEditVisitor; // packageimport | |
31 import dwtx.text.edits.TextEditGroup; // packageimport | |
32 import dwtx.text.edits.TextEdit; // packageimport | |
33 import dwtx.text.edits.RangeMarker; // packageimport | |
34 import dwtx.text.edits.UndoEdit; // packageimport | |
35 import dwtx.text.edits.InsertEdit; // packageimport | |
36 | |
37 | |
129 | 38 import dwt.dwthelper.utils; |
39 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
40 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
41 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
42 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
43 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
44 |
129 | 45 |
46 import dwtx.core.runtime.Assert; | |
47 | |
48 | |
49 /** | |
50 * Copies a tree of text edits. A text edit copier keeps a map | |
51 * between original and new text edits. It can be used to map | |
52 * a copy back to its original edit. | |
53 * | |
54 * @since 3.0 | |
55 */ | |
56 public final class TextEditCopier { | |
57 | |
58 private TextEdit fEdit; | |
59 private Map fCopies; | |
60 | |
61 /** | |
62 * Constructs a new <code>TextEditCopier</code> for the | |
63 * given edit. The actual copy is done by calling <code> | |
64 * perform</code>. | |
65 * | |
66 * @param edit the edit to copy | |
67 * | |
68 * @see #perform() | |
69 */ | |
130 | 70 public this(TextEdit edit) { |
129 | 71 super(); |
72 Assert.isNotNull(edit); | |
73 fEdit= edit; | |
74 fCopies= new HashMap(); | |
75 } | |
76 | |
77 /** | |
78 * Performs the actual copying. | |
79 * | |
80 * @return the copy | |
81 */ | |
82 public TextEdit perform() { | |
83 TextEdit result= doCopy(fEdit); | |
84 if (result !is null) { | |
85 for (Iterator iter= fCopies.keySet().iterator(); iter.hasNext();) { | |
134 | 86 TextEdit edit= cast(TextEdit)iter.next(); |
129 | 87 edit.postProcessCopy(this); |
88 } | |
89 } | |
90 return result; | |
91 } | |
92 | |
93 /** | |
94 * Returns the copy for the original text edit. | |
95 * | |
96 * @param original the original for which the copy | |
97 * is requested | |
98 * @return the copy of the original edit or <code>null</code> | |
99 * if the original isn't managed by this copier | |
100 */ | |
101 public TextEdit getCopy(TextEdit original) { | |
102 Assert.isNotNull(original); | |
134 | 103 return cast(TextEdit)fCopies.get(original); |
129 | 104 } |
105 | |
106 //---- helper methods -------------------------------------------- | |
107 | |
108 private TextEdit doCopy(TextEdit edit) { | |
109 TextEdit result= edit.doCopy(); | |
110 List children= edit.internalGetChildren(); | |
111 if (children !is null) { | |
112 List newChildren= new ArrayList(children.size()); | |
113 for (Iterator iter= children.iterator(); iter.hasNext();) { | |
134 | 114 TextEdit childCopy= doCopy(cast(TextEdit)iter.next()); |
129 | 115 childCopy.internalSetParent(result); |
116 newChildren.add(childCopy); | |
117 } | |
118 result.internalSetChildren(newChildren); | |
119 } | |
120 addCopy(edit, result); | |
121 return result; | |
122 } | |
123 | |
124 private void addCopy(TextEdit original, TextEdit copy) { | |
125 fCopies.put(original, copy); | |
126 } | |
127 } |