Mercurial > projects > dwt-addons
annotate dwtx/jface/text/reconciler/DirtyRegionQueue.d @ 134:51e6e63f930e
Regex fix for casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 01:46:20 +0200 |
parents | 7d818bd32d63 |
children | f70d9508c95c |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 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.jface.text.reconciler.DirtyRegionQueue; | |
14 | |
131 | 15 import dwtx.jface.text.reconciler.IReconciler; // packageimport |
16 import dwtx.jface.text.reconciler.IReconcilingStrategy; // packageimport | |
17 import dwtx.jface.text.reconciler.AbstractReconcileStep; // packageimport | |
18 import dwtx.jface.text.reconciler.IReconcilingStrategyExtension; // packageimport | |
19 import dwtx.jface.text.reconciler.MonoReconciler; // packageimport | |
20 import dwtx.jface.text.reconciler.IReconcileStep; // packageimport | |
21 import dwtx.jface.text.reconciler.AbstractReconciler; // packageimport | |
22 import dwtx.jface.text.reconciler.Reconciler; // packageimport | |
23 import dwtx.jface.text.reconciler.IReconcilableModel; // packageimport | |
24 import dwtx.jface.text.reconciler.DirtyRegion; // packageimport | |
25 import dwtx.jface.text.reconciler.IReconcileResult; // packageimport | |
26 import dwtx.jface.text.reconciler.IReconcilerExtension; // packageimport | |
27 | |
28 | |
129 | 29 import dwt.dwthelper.utils; |
30 | |
31 import java.util.ArrayList; | |
32 import java.util.List; | |
33 | |
34 | |
35 /** | |
36 * Queue used by {@link dwtx.jface.text.reconciler.AbstractReconciler} to manage | |
37 * dirty regions. When a dirty region is inserted into the queue, the queue tries | |
38 * to fold it into the neighboring dirty region. | |
39 * | |
40 * @see dwtx.jface.text.reconciler.AbstractReconciler | |
41 * @see dwtx.jface.text.reconciler.DirtyRegion | |
42 */ | |
43 class DirtyRegionQueue { | |
44 | |
45 /** The list of dirty regions. */ | |
46 private List fDirtyRegions= new ArrayList(); | |
47 | |
48 /** | |
49 * Creates a new empty dirty region. | |
50 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
51 public this() { |
129 | 52 super(); |
53 } | |
54 | |
55 /** | |
56 * Adds a dirty region to the end of the dirty-region queue. | |
57 * | |
58 * @param dr the dirty region to add | |
59 */ | |
60 public void addDirtyRegion(DirtyRegion dr) { | |
61 // If the dirty region being added is directly after the last dirty | |
62 // region on the queue then merge the two dirty regions together. | |
63 DirtyRegion lastDR= getLastDirtyRegion(); | |
64 bool wasMerged= false; | |
65 if (lastDR !is null) | |
66 if (lastDR.getType() is dr.getType()) | |
67 if (lastDR.getType() is DirtyRegion.INSERT) { | |
68 if (lastDR.getOffset() + lastDR.getLength() is dr.getOffset()) { | |
69 lastDR.mergeWith(dr); | |
70 wasMerged= true; | |
71 } | |
72 } else if (lastDR.getType() is DirtyRegion.REMOVE) { | |
73 if (dr.getOffset() + dr.getLength() is lastDR.getOffset()) { | |
74 lastDR.mergeWith(dr); | |
75 wasMerged= true; | |
76 } | |
77 } | |
78 | |
79 if (!wasMerged) | |
80 // Don't merge- just add the new one onto the queue. | |
81 fDirtyRegions.add(dr); | |
82 } | |
83 | |
84 /** | |
85 * Returns the last dirty region that was added to the queue. | |
86 * | |
87 * @return the last DirtyRegion on the queue | |
88 */ | |
89 private DirtyRegion getLastDirtyRegion() { | |
90 int size= fDirtyRegions.size(); | |
134 | 91 return (size is 0 ? null : cast(DirtyRegion) fDirtyRegions.get(size - 1)); |
129 | 92 } |
93 | |
94 /** | |
95 * Returns the number of regions in the queue. | |
96 * | |
97 * @return the dirty-region queue-size | |
98 */ | |
99 public int getSize() { | |
100 return fDirtyRegions.size(); | |
101 } | |
102 | |
103 /** | |
104 * Throws away all entries in the queue. | |
105 */ | |
106 public void purgeQueue() { | |
107 fDirtyRegions.clear(); | |
108 } | |
109 | |
110 /** | |
111 * Removes and returns the first dirty region in the queue | |
112 * | |
113 * @return the next dirty region on the queue | |
114 */ | |
115 public DirtyRegion removeNextDirtyRegion() { | |
116 if (fDirtyRegions.size() is 0) | |
117 return null; | |
134 | 118 DirtyRegion dr= cast(DirtyRegion) fDirtyRegions.get(0); |
129 | 119 fDirtyRegions.remove(0); |
120 return dr; | |
121 } | |
122 } |