comparison dwtx/jface/text/link/LinkedPositionGroup.d @ 134:51e6e63f930e

Regex fix for casts
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 01:46:20 +0200
parents c4fb132a086c
children 6dcb0baaa031
comparison
equal deleted inserted replaced
133:7d818bd32d63 134:51e6e63f930e
136 * @param position the position to check 136 * @param position the position to check
137 * @throws BadLocationException if the equal content check fails 137 * @throws BadLocationException if the equal content check fails
138 */ 138 */
139 private void enforceEqualContent(LinkedPosition position) throws BadLocationException { 139 private void enforceEqualContent(LinkedPosition position) throws BadLocationException {
140 if (fPositions.size() > 0) { 140 if (fPositions.size() > 0) {
141 LinkedPosition groupPosition= (LinkedPosition) fPositions.get(0); 141 LinkedPosition groupPosition= cast(LinkedPosition) fPositions.get(0);
142 String groupContent= groupPosition.getContent(); 142 String groupContent= groupPosition.getContent();
143 String positionContent= position.getContent(); 143 String positionContent= position.getContent();
144 if (!groupContent.equals(positionContent)) 144 if (!groupContent.equals(positionContent))
145 throw new BadLocationException( 145 throw new BadLocationException(
146 "First position: '" + groupContent + "' at " + groupPosition.getOffset() + //$NON-NLS-1$ //$NON-NLS-2$ 146 "First position: '" + groupContent + "' at " + groupPosition.getOffset() + //$NON-NLS-1$ //$NON-NLS-2$
154 * @param position the position to check 154 * @param position the position to check
155 * @throws BadLocationException if the disjointness check fails 155 * @throws BadLocationException if the disjointness check fails
156 */ 156 */
157 private void enforceDisjoint(LinkedPosition position) throws BadLocationException { 157 private void enforceDisjoint(LinkedPosition position) throws BadLocationException {
158 for (Iterator it= fPositions.iterator(); it.hasNext(); ) { 158 for (Iterator it= fPositions.iterator(); it.hasNext(); ) {
159 LinkedPosition p= (LinkedPosition) it.next(); 159 LinkedPosition p= cast(LinkedPosition) it.next();
160 if (p.overlapsWith(position)) 160 if (p.overlapsWith(position))
161 throw new BadLocationException(); 161 throw new BadLocationException();
162 } 162 }
163 } 163 }
164 164
169 * @throws BadLocationException if the disjointness check fails 169 * @throws BadLocationException if the disjointness check fails
170 */ 170 */
171 void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException { 171 void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException {
172 Assert.isNotNull(group); 172 Assert.isNotNull(group);
173 for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) { 173 for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) {
174 LinkedPosition p= (LinkedPosition) it.next(); 174 LinkedPosition p= cast(LinkedPosition) it.next();
175 enforceDisjoint(p); 175 enforceDisjoint(p);
176 } 176 }
177 } 177 }
178 178
179 /** 179 /**
187 bool isLegalEvent(DocumentEvent event) { 187 bool isLegalEvent(DocumentEvent event) {
188 fLastPosition= null; 188 fLastPosition= null;
189 fLastRegion= null; 189 fLastRegion= null;
190 190
191 for (Iterator it= fPositions.iterator(); it.hasNext(); ) { 191 for (Iterator it= fPositions.iterator(); it.hasNext(); ) {
192 LinkedPosition pos= (LinkedPosition) it.next(); 192 LinkedPosition pos= cast(LinkedPosition) it.next();
193 if (overlapsOrTouches(pos, event)) { 193 if (overlapsOrTouches(pos, event)) {
194 if (fLastPosition !is null) { 194 if (fLastPosition !is null) {
195 fLastPosition= null; 195 fLastPosition= null;
196 fLastRegion= null; 196 fLastRegion= null;
197 return false; 197 return false;
251 String text= event.getText(); 251 String text= event.getText();
252 if (text is null) 252 if (text is null)
253 text= ""; //$NON-NLS-1$ 253 text= ""; //$NON-NLS-1$
254 254
255 for (Iterator it= fPositions.iterator(); it.hasNext(); ) { 255 for (Iterator it= fPositions.iterator(); it.hasNext(); ) {
256 LinkedPosition p= (LinkedPosition) it.next(); 256 LinkedPosition p= cast(LinkedPosition) it.next();
257 if (p is fLastPosition || p.isDeleted()) 257 if (p is fLastPosition || p.isDeleted())
258 continue; // don't re-update the origin of the change 258 continue; // don't re-update the origin of the change
259 259
260 List edits= (List) map.get(p.getDocument()); 260 List edits= cast(List) map.get(p.getDocument());
261 if (edits is null) { 261 if (edits is null) {
262 edits= new ArrayList(); 262 edits= new ArrayList();
263 map.put(p.getDocument(), edits); 263 map.put(p.getDocument(), edits);
264 } 264 }
265 265
266 edits.add(new ReplaceEdit(p.getOffset() + relativeOffset, length, text)); 266 edits.add(new ReplaceEdit(p.getOffset() + relativeOffset, length, text));
267 } 267 }
268 268
269 try { 269 try {
270 for (Iterator it= map.keySet().iterator(); it.hasNext();) { 270 for (Iterator it= map.keySet().iterator(); it.hasNext();) {
271 IDocument d= (IDocument) it.next(); 271 IDocument d= cast(IDocument) it.next();
272 TextEdit edit= new MultiTextEdit(0, d.getLength()); 272 TextEdit edit= new MultiTextEdit(0, d.getLength());
273 edit.addChildren((TextEdit[]) ((List) map.get(d)).toArray(new TextEdit[0])); 273 edit.addChildren((TextEdit[]) (cast(List) map.get(d)).toArray(new TextEdit[0]));
274 map.put(d, edit); 274 map.put(d, edit);
275 } 275 }
276 276
277 return map; 277 return map;
278 } catch (MalformedTreeException x) { 278 } catch (MalformedTreeException x) {
296 void seal() { 296 void seal() {
297 Assert.isTrue(!fIsSealed); 297 Assert.isTrue(!fIsSealed);
298 fIsSealed= true; 298 fIsSealed= true;
299 299
300 if (fHasCustomIteration is false && fPositions.size() > 0) { 300 if (fHasCustomIteration is false && fPositions.size() > 0) {
301 ((LinkedPosition) fPositions.get(0)).setSequenceNumber(0); 301 (cast(LinkedPosition) fPositions.get(0)).setSequenceNumber(0);
302 } 302 }
303 } 303 }
304 304
305 IDocument[] getDocuments() { 305 IDocument[] getDocuments() {
306 IDocument[] docs= new IDocument[fPositions.size()]; 306 IDocument[] docs= new IDocument[fPositions.size()];
307 int i= 0; 307 int i= 0;
308 for (Iterator it= fPositions.iterator(); it.hasNext(); i++) { 308 for (Iterator it= fPositions.iterator(); it.hasNext(); i++) {
309 LinkedPosition pos= (LinkedPosition) it.next(); 309 LinkedPosition pos= cast(LinkedPosition) it.next();
310 docs[i]= pos.getDocument(); 310 docs[i]= pos.getDocument();
311 } 311 }
312 return docs; 312 return docs;
313 } 313 }
314 314
315 void register(LinkedModeModel model) throws BadLocationException { 315 void register(LinkedModeModel model) throws BadLocationException {
316 for (Iterator it= fPositions.iterator(); it.hasNext(); ) { 316 for (Iterator it= fPositions.iterator(); it.hasNext(); ) {
317 LinkedPosition pos= (LinkedPosition) it.next(); 317 LinkedPosition pos= cast(LinkedPosition) it.next();
318 model.register(pos); 318 model.register(pos);
319 } 319 }
320 } 320 }
321 321
322 /** 322 /**
330 * <code>group</code> 330 * <code>group</code>
331 */ 331 */
332 LinkedPosition adopt(LinkedPositionGroup group) throws BadLocationException { 332 LinkedPosition adopt(LinkedPositionGroup group) throws BadLocationException {
333 LinkedPosition found= null; 333 LinkedPosition found= null;
334 for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) { 334 for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) {
335 LinkedPosition pos= (LinkedPosition) it.next(); 335 LinkedPosition pos= cast(LinkedPosition) it.next();
336 LinkedPosition localFound= null; 336 LinkedPosition localFound= null;
337 for (Iterator it2= fPositions.iterator(); it2.hasNext(); ) { 337 for (Iterator it2= fPositions.iterator(); it2.hasNext(); ) {
338 LinkedPosition myPos= (LinkedPosition) it2.next(); 338 LinkedPosition myPos= cast(LinkedPosition) it2.next();
339 if (myPos.includes(pos)) { 339 if (myPos.includes(pos)) {
340 if (found is null) 340 if (found is null)
341 found= myPos; 341 found= myPos;
342 else if (found !is myPos) 342 else if (found !is myPos)
343 throw new BadLocationException(); 343 throw new BadLocationException();
358 * @param toFind the linked position for which to find the closest position 358 * @param toFind the linked position for which to find the closest position
359 * @return the closest position to <code>toFind</code>. 359 * @return the closest position to <code>toFind</code>.
360 */ 360 */
361 LinkedPosition getPosition(LinkedPosition toFind) { 361 LinkedPosition getPosition(LinkedPosition toFind) {
362 for (Iterator it= fPositions.iterator(); it.hasNext(); ) { 362 for (Iterator it= fPositions.iterator(); it.hasNext(); ) {
363 LinkedPosition p= (LinkedPosition) it.next(); 363 LinkedPosition p= cast(LinkedPosition) it.next();
364 if (p.includes(toFind)) 364 if (p.includes(toFind))
365 return p; 365 return p;
366 } 366 }
367 return null; 367 return null;
368 } 368 }
374 * @param offset the offset to check 374 * @param offset the offset to check
375 * @return <code>true</code> if offset is contained by this group 375 * @return <code>true</code> if offset is contained by this group
376 */ 376 */
377 bool contains(int offset) { 377 bool contains(int offset) {
378 for (Iterator it= fPositions.iterator(); it.hasNext(); ) { 378 for (Iterator it= fPositions.iterator(); it.hasNext(); ) {
379 LinkedPosition pos= (LinkedPosition) it.next(); 379 LinkedPosition pos= cast(LinkedPosition) it.next();
380 if (pos.includes(offset)) { 380 if (pos.includes(offset)) {
381 return true; 381 return true;
382 } 382 }
383 } 383 }
384 return false; 384 return false;
421 * @param position the position to check 421 * @param position the position to check
422 * @return <code>true</code> if the receiver contains <code>position</code> 422 * @return <code>true</code> if the receiver contains <code>position</code>
423 */ 423 */
424 bool contains(Position position) { 424 bool contains(Position position) {
425 for (Iterator it= fPositions.iterator(); it.hasNext(); ) { 425 for (Iterator it= fPositions.iterator(); it.hasNext(); ) {
426 LinkedPosition p= (LinkedPosition) it.next(); 426 LinkedPosition p= cast(LinkedPosition) it.next();
427 if (position.equals(p)) 427 if (position.equals(p))
428 return true; 428 return true;
429 } 429 }
430 return false; 430 return false;
431 } 431 }