Mercurial > projects > dwt2
comparison org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.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.CopyTargetEdit; | |
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.TextEditCopier; // 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.Set; | |
41 | |
42 | |
43 import org.eclipse.core.runtime.Assert; | |
44 import org.eclipse.jface.text.BadLocationException; | |
45 import org.eclipse.jface.text.IDocument; | |
46 | |
47 /** | |
48 * A copy target edit denotes the target of a copy operation. Copy | |
49 * target edits are only valid inside an edit tree if they have a | |
50 * corresponding source edit. Furthermore a target edit can't | |
51 * can't be a direct or indirect child of the associated source edit. | |
52 * Violating one of two requirements will result in a <code> | |
53 * MalformedTreeException</code> when executing the edit tree. | |
54 * <p> | |
55 * Copy target edits can't be used as a parent for other edits. | |
56 * Trying to add an edit to a copy target edit results in a <code> | |
57 * MalformedTreeException</code> as well. | |
58 * | |
59 * @see org.eclipse.text.edits.CopySourceEdit | |
60 * | |
61 * @since 3.0 | |
62 */ | |
63 public final class CopyTargetEdit : TextEdit { | |
64 | |
65 private CopySourceEdit fSource; | |
66 | |
67 /** | |
68 * Constructs a new copy target edit | |
69 * | |
70 * @param offset the edit's offset | |
71 */ | |
72 public this(int offset) { | |
73 super(offset, 0); | |
74 } | |
75 | |
76 /** | |
77 * Constructs an new copy target edit | |
78 * | |
79 * @param offset the edit's offset | |
80 * @param source the corresponding source edit | |
81 */ | |
82 public this(int offset, CopySourceEdit source) { | |
83 this(offset); | |
84 setSourceEdit(source); | |
85 } | |
86 | |
87 /* | |
88 * Copy constructor | |
89 */ | |
90 private this(CopyTargetEdit other) { | |
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 */ | |
100 public CopySourceEdit getSourceEdit() { | |
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(CopySourceEdit edit) { | |
113 Assert.isNotNull(edit); | |
114 if (fSource !is edit) { | |
115 fSource= edit; | |
116 fSource.setTargetEdit(this); | |
117 TextEdit parent= getParent(); | |
118 while (parent !is null) { | |
119 if (parent is fSource) | |
120 throw new MalformedTreeException(parent, this, TextEditMessages.getString("CopyTargetEdit.wrong_parent")); //$NON-NLS-1$ | |
121 parent= parent.getParent(); | |
122 } | |
123 } | |
124 } | |
125 | |
126 /* | |
127 * @see TextEdit#doCopy | |
128 */ | |
129 protected TextEdit doCopy() { | |
130 return new CopyTargetEdit(this); | |
131 } | |
132 | |
133 /* | |
134 * @see TextEdit#postProcessCopy | |
135 */ | |
136 protected void postProcessCopy(TextEditCopier copier) { | |
137 if (fSource !is null) { | |
138 CopyTargetEdit target= cast(CopyTargetEdit)copier.getCopy(this); | |
139 CopySourceEdit source= cast(CopySourceEdit)copier.getCopy(fSource); | |
140 if (target !is null && source !is null) | |
141 target.setSourceEdit(source); | |
142 } | |
143 } | |
144 | |
145 /* | |
146 * @see TextEdit#accept0 | |
147 */ | |
148 protected void accept0(TextEditVisitor visitor) { | |
149 bool visitChildren= visitor.visit(this); | |
150 if (visitChildren) { | |
151 acceptChildren(visitor); | |
152 } | |
153 } | |
154 | |
155 /* | |
156 * @see TextEdit#traverseConsistencyCheck | |
157 */ | |
158 int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { | |
159 return super.traverseConsistencyCheck(processor, document, sourceEdits) + 1; | |
160 } | |
161 | |
162 /* | |
163 * @see TextEdit#performConsistencyCheck | |
164 */ | |
165 void performConsistencyCheck(TextEditProcessor processor, IDocument document) { | |
166 if (fSource is null) | |
167 throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.no_source")); //$NON-NLS-1$ | |
168 if (fSource.getTargetEdit() !is this) | |
169 throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.different_target")); //$NON-NLS-1$ | |
170 } | |
171 | |
172 /* | |
173 * @see TextEdit#performDocumentUpdating | |
174 */ | |
175 int performDocumentUpdating(IDocument document) { | |
176 String source= fSource.getContent(); | |
177 document.replace(getOffset(), getLength(), source); | |
178 fDelta= source.length() - getLength(); | |
179 fSource.clearContent(); | |
180 return fDelta; | |
181 } | |
182 | |
183 /* | |
184 * @see TextEdit#deleteChildren | |
185 */ | |
186 bool deleteChildren() { | |
187 return false; | |
188 } | |
189 } |