Mercurial > projects > dwt2
comparison org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconcileStep.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 |
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.jface.text.reconciler.AbstractReconcileStep; | |
14 | |
15 import org.eclipse.jface.text.reconciler.IReconciler; // packageimport | |
16 import org.eclipse.jface.text.reconciler.DirtyRegionQueue; // packageimport | |
17 import org.eclipse.jface.text.reconciler.IReconcilingStrategy; // packageimport | |
18 import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension; // packageimport | |
19 import org.eclipse.jface.text.reconciler.MonoReconciler; // packageimport | |
20 import org.eclipse.jface.text.reconciler.IReconcileStep; // packageimport | |
21 import org.eclipse.jface.text.reconciler.AbstractReconciler; // packageimport | |
22 import org.eclipse.jface.text.reconciler.Reconciler; // packageimport | |
23 import org.eclipse.jface.text.reconciler.IReconcilableModel; // packageimport | |
24 import org.eclipse.jface.text.reconciler.DirtyRegion; // packageimport | |
25 import org.eclipse.jface.text.reconciler.IReconcileResult; // packageimport | |
26 import org.eclipse.jface.text.reconciler.IReconcilerExtension; // packageimport | |
27 | |
28 | |
29 import java.lang.all; | |
30 import java.util.Arrays; | |
31 import java.util.Collection; | |
32 import java.util.ArrayList; | |
33 import java.util.Set; | |
34 | |
35 | |
36 | |
37 | |
38 import org.eclipse.core.runtime.Assert; | |
39 import org.eclipse.core.runtime.IProgressMonitor; | |
40 import org.eclipse.jface.text.IRegion; | |
41 | |
42 | |
43 /** | |
44 * Abstract implementation of a reconcile step. | |
45 * | |
46 * @since 3.0 | |
47 */ | |
48 public abstract class AbstractReconcileStep : IReconcileStep { | |
49 | |
50 private IReconcileStep fNextStep; | |
51 private IReconcileStep fPreviousStep; | |
52 private IProgressMonitor fProgressMonitor; | |
53 protected IReconcilableModel fInputModel; | |
54 | |
55 /** | |
56 * Creates an intermediate reconcile step which adds | |
57 * the given step to the pipe. | |
58 * | |
59 * @param step the reconcile step | |
60 */ | |
61 public this(IReconcileStep step) { | |
62 Assert.isNotNull(cast(Object)step); | |
63 fNextStep= step; | |
64 fNextStep.setPreviousStep(this); | |
65 } | |
66 | |
67 /** | |
68 * Creates the last reconcile step of the pipe. | |
69 */ | |
70 public this() { | |
71 } | |
72 | |
73 public bool isLastStep() { | |
74 return fNextStep is null; | |
75 } | |
76 | |
77 public bool isFirstStep() { | |
78 return fPreviousStep is null; | |
79 } | |
80 | |
81 /* | |
82 * @see org.eclipse.text.reconcilerpipe.IReconcilerResultCollector#setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) | |
83 */ | |
84 public void setProgressMonitor(IProgressMonitor monitor) { | |
85 fProgressMonitor= monitor; | |
86 | |
87 if (!isLastStep()) | |
88 fNextStep.setProgressMonitor(monitor); | |
89 } | |
90 | |
91 /* | |
92 * @see org.eclipse.jface.text.reconciler.IReconcileStep#getProgressMonitor() | |
93 */ | |
94 public IProgressMonitor getProgressMonitor() { | |
95 return fProgressMonitor; | |
96 } | |
97 | |
98 /* | |
99 * @see IReconcileStep#reconcile(IRegion) | |
100 */ | |
101 public final IReconcileResult[] reconcile(IRegion partition) { | |
102 IReconcileResult[] result= reconcileModel(null, partition); | |
103 if (!isLastStep()) { | |
104 fNextStep.setInputModel(getModel()); | |
105 IReconcileResult[] nextResult= fNextStep.reconcile(partition); | |
106 return merge(result, convertToInputModel(nextResult)); | |
107 } | |
108 return result; | |
109 } | |
110 | |
111 /* | |
112 * @see IReconcileStep#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion) | |
113 */ | |
114 public final IReconcileResult[] reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { | |
115 IReconcileResult[] result= reconcileModel(dirtyRegion, subRegion); | |
116 if (!isLastStep()) { | |
117 fNextStep.setInputModel(getModel()); | |
118 IReconcileResult[] nextResult= fNextStep.reconcile(dirtyRegion, subRegion); | |
119 return merge(result, convertToInputModel(nextResult)); | |
120 } | |
121 return result; | |
122 } | |
123 | |
124 | |
125 /** | |
126 * Reconciles the model of this reconcile step. The | |
127 * result is based on the input model. | |
128 * | |
129 * @param dirtyRegion the document region which has been changed | |
130 * @param subRegion the sub region in the dirty region which should be reconciled | |
131 * @return an array with reconcile results | |
132 */ | |
133 abstract protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion); | |
134 | |
135 /** | |
136 * Adapts the given an array with reconcile results to | |
137 * this step's input model and returns it. | |
138 * | |
139 * @param inputResults an array with reconcile results | |
140 * @return an array with the reconcile results adapted to the input model | |
141 */ | |
142 protected IReconcileResult[] convertToInputModel(IReconcileResult[] inputResults) { | |
143 return inputResults; | |
144 } | |
145 | |
146 /** | |
147 * Merges the two reconcile result arrays. | |
148 * | |
149 * @param results1 an array with reconcile results | |
150 * @param results2 an array with reconcile results | |
151 * @return an array with the merged reconcile results | |
152 */ | |
153 private IReconcileResult[] merge(IReconcileResult[] results1, IReconcileResult[] results2) { | |
154 if (results1 is null) | |
155 return results2; | |
156 | |
157 if (results2 is null) | |
158 return results1; | |
159 | |
160 // XXX: not yet performance optimized | |
161 Collection collection= new ArrayList(Arrays.asList(arraycast!(Object)(results1))); | |
162 collection.addAll(Arrays.asList(arraycast!(Object)(results2))); | |
163 return arraycast!(IReconcileResult)(collection.toArray()); | |
164 } | |
165 | |
166 /* | |
167 * @see IProgressMonitor#isCanceled() | |
168 */ | |
169 protected final bool isCanceled() { | |
170 return fProgressMonitor !is null && fProgressMonitor.isCanceled(); | |
171 } | |
172 | |
173 /* | |
174 * @see IReconcileStep#setPreviousStep(IReconcileStep) | |
175 */ | |
176 public void setPreviousStep(IReconcileStep step) { | |
177 Assert.isNotNull(cast(Object)step); | |
178 Assert.isTrue(fPreviousStep is null); | |
179 fPreviousStep= step; | |
180 } | |
181 | |
182 /* | |
183 * @see IReconcileStep#setInputModel(Object) | |
184 */ | |
185 public void setInputModel(IReconcilableModel inputModel) { | |
186 fInputModel= inputModel; | |
187 | |
188 if (!isLastStep()) | |
189 fNextStep.setInputModel(getModel()); | |
190 } | |
191 | |
192 /** | |
193 * Returns the reconcilable input model. | |
194 * | |
195 * @return the reconcilable input model. | |
196 */ | |
197 public IReconcilableModel getInputModel() { | |
198 return fInputModel; | |
199 } | |
200 | |
201 /** | |
202 * Returns the reconcilable model. | |
203 * | |
204 * @return the reconcilable model | |
205 */ | |
206 abstract public IReconcilableModel getModel(); | |
207 } |