Mercurial > projects > dwt-addons
annotate dwtx/text/edits/MoveTargetEdit.d @ 153:f70d9508c95c
Fix java Collection imports
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 25 Aug 2008 00:27:31 +0200 |
parents | 5cf141e43417 |
children |
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.MoveTargetEdit; | |
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.CopyTargetEdit; // packageimport | |
24 import dwtx.text.edits.TextEditCopier; // 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:
150
diff
changeset
|
40 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
41 |
129 | 42 |
43 import dwtx.jface.text.BadLocationException; | |
44 import dwtx.jface.text.IDocument; | |
45 | |
46 /** | |
47 * A move target edit denotes the target of a move operation. Move | |
48 * target edits are only valid inside an edit tree if they have a | |
49 * corresponding source edit. Furthermore a target edit can't | |
50 * can't be a direct or indirect child of its associated source edit. | |
51 * Violating one of two requirements will result in a <code> | |
52 * MalformedTreeException</code> when executing the edit tree. | |
53 * <p> | |
54 * Move target edits can't be used as a parent for other edits. | |
55 * Trying to add an edit to a move target edit results in a <code> | |
56 * MalformedTreeException</code> as well. | |
57 * | |
58 * @see dwtx.text.edits.MoveSourceEdit | |
59 * @see dwtx.text.edits.CopyTargetEdit | |
60 * | |
61 * @since 3.0 | |
62 */ | |
63 public final class MoveTargetEdit : TextEdit { | |
64 | |
65 private MoveSourceEdit fSource; | |
66 | |
67 /** | |
68 * Constructs a new move target edit | |
69 * | |
70 * @param offset the edit's offset | |
71 */ | |
130 | 72 public this(int offset) { |
129 | 73 super(offset, 0); |
74 } | |
75 | |
76 /** | |
77 * Constructs an new move target edit | |
78 * | |
79 * @param offset the edit's offset | |
80 * @param source the corresponding source edit | |
81 */ | |
130 | 82 public this(int offset, MoveSourceEdit source) { |
129 | 83 this(offset); |
84 setSourceEdit(source); | |
85 } | |
86 | |
87 /* | |
88 * Copy constructor | |
89 */ | |
130 | 90 private this(MoveTargetEdit other) { |
129 | 91 super(other); |
92 } | |
93 | |
94 /** | |
95 * Returns the associated source edit or <code>null</code> | |
96 * if no source edit is associated yet. | |
97 * | |
98 * @return the source edit or <code>null</code> | |
99 */ | |
150 | 100 public MoveSourceEdit getSourceEdit() { |
129 | 101 return fSource; |
102 } | |
103 | |
104 /** | |
105 * Sets the source edit. | |
106 * | |
107 * @param edit the source edit | |
108 * | |
109 * @exception MalformedTreeException is thrown if the target edit | |
110 * is a direct or indirect child of the source edit | |
111 */ | |
112 public void setSourceEdit(MoveSourceEdit edit) { | |
113 if (fSource !is edit) { | |
114 fSource= edit; | |
115 fSource.setTargetEdit(this); | |
116 TextEdit parent= getParent(); | |
117 while (parent !is null) { | |
118 if (parent is fSource) | |
119 throw new MalformedTreeException(parent, this, TextEditMessages.getString("MoveTargetEdit.wrong_parent")); //$NON-NLS-1$ | |
120 parent= parent.getParent(); | |
121 } | |
122 } | |
123 } | |
124 | |
125 /* | |
126 * @see TextEdit#doCopy | |
127 */ | |
128 protected TextEdit doCopy() { | |
129 return new MoveTargetEdit(this); | |
130 } | |
131 | |
132 /* | |
133 * @see TextEdit#postProcessCopy | |
134 */ | |
135 protected void postProcessCopy(TextEditCopier copier) { | |
136 if (fSource !is null) { | |
134 | 137 MoveTargetEdit target= cast(MoveTargetEdit)copier.getCopy(this); |
138 MoveSourceEdit source= cast(MoveSourceEdit)copier.getCopy(fSource); | |
129 | 139 if (target !is null && source !is null) |
140 target.setSourceEdit(source); | |
141 } | |
142 } | |
143 | |
144 /* | |
145 * @see TextEdit#accept0 | |
146 */ | |
147 protected void accept0(TextEditVisitor visitor) { | |
148 bool visitChildren= visitor.visit(this); | |
149 if (visitChildren) { | |
150 acceptChildren(visitor); | |
151 } | |
152 } | |
153 | |
154 //---- consistency check ---------------------------------------------------------- | |
155 | |
156 /* | |
157 * @see TextEdit#traverseConsistencyCheck | |
158 */ | |
159 int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { | |
160 return super.traverseConsistencyCheck(processor, document, sourceEdits) + 1; | |
161 } | |
162 | |
163 /* | |
164 * @see TextEdit#performConsistencyCheck | |
165 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
166 void performConsistencyCheck(TextEditProcessor processor, IDocument document) { |
129 | 167 if (fSource is null) |
168 throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.no_source")); //$NON-NLS-1$ | |
169 if (fSource.getTargetEdit() !is this) | |
170 throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.different_target")); //$NON-NLS-1$ | |
171 } | |
172 | |
173 //---- document updating ---------------------------------------------------------------- | |
174 | |
175 /* | |
176 * @see TextEdit#performDocumentUpdating | |
177 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
178 int performDocumentUpdating(IDocument document) { |
129 | 179 String source= fSource.getContent(); |
180 document.replace(getOffset(), getLength(), source); | |
181 fDelta= source.length() - getLength(); | |
182 | |
183 MultiTextEdit sourceRoot= fSource.getSourceRoot(); | |
184 if (sourceRoot !is null) { | |
185 sourceRoot.internalMoveTree(getOffset()); | |
186 TextEdit[] sourceChildren= sourceRoot.removeChildren(); | |
187 List children= new ArrayList(sourceChildren.length); | |
188 for (int i= 0; i < sourceChildren.length; i++) { | |
189 TextEdit child= sourceChildren[i]; | |
190 child.internalSetParent(this); | |
191 children.add(child); | |
192 } | |
193 internalSetChildren(children); | |
194 } | |
195 fSource.clearContent(); | |
196 return fDelta; | |
197 } | |
198 | |
199 //---- region updating -------------------------------------------------------------- | |
200 | |
201 /* | |
202 * @see dwtx.text.edits.TextEdit#traversePassThree | |
203 */ | |
150 | 204 int traverseRegionUpdating(TextEditProcessor processor, IDocument document, int accumulatedDelta, bool delete_) { |
129 | 205 // the children got already updated / normalized while they got removed |
206 // from the source edit. So we only have to adjust the offset computed to | |
207 // far. | |
150 | 208 if (delete_) { |
129 | 209 deleteTree(); |
210 } else { | |
211 internalMoveTree(accumulatedDelta); | |
212 } | |
213 return accumulatedDelta + fDelta; | |
214 } | |
215 | |
216 bool deleteChildren() { | |
217 return false; | |
218 } | |
219 } |