Mercurial > projects > dwt-addons
annotate dwtx/jface/text/AbstractDocument.d @ 158:25f1f92fa3df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 26 Aug 2008 02:46:34 +0200 |
parents | f70d9508c95c |
children | 1a5b8f8129df |
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 | |
131 | 14 |
151 | 15 module dwtx.jface.text.AbstractDocument; |
16 | |
131 | 17 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport |
18 import dwtx.jface.text.DefaultTextHover; // packageimport | |
19 import dwtx.jface.text.AbstractInformationControl; // packageimport | |
20 import dwtx.jface.text.TextUtilities; // packageimport | |
21 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport | |
22 import dwtx.jface.text.AbstractInformationControlManager; // packageimport | |
23 import dwtx.jface.text.ITextViewerExtension2; // packageimport | |
24 import dwtx.jface.text.IDocumentPartitioner; // packageimport | |
25 import dwtx.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport | |
26 import dwtx.jface.text.ITextSelection; // packageimport | |
27 import dwtx.jface.text.Document; // packageimport | |
28 import dwtx.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // packageimport | |
29 import dwtx.jface.text.ITextListener; // packageimport | |
30 import dwtx.jface.text.BadPartitioningException; // packageimport | |
31 import dwtx.jface.text.ITextViewerExtension5; // packageimport | |
32 import dwtx.jface.text.IDocumentPartitionerExtension3; // packageimport | |
33 import dwtx.jface.text.IUndoManager; // packageimport | |
34 import dwtx.jface.text.ITextHoverExtension2; // packageimport | |
35 import dwtx.jface.text.IRepairableDocument; // packageimport | |
36 import dwtx.jface.text.IRewriteTarget; // packageimport | |
37 import dwtx.jface.text.DefaultPositionUpdater; // packageimport | |
38 import dwtx.jface.text.RewriteSessionEditProcessor; // packageimport | |
39 import dwtx.jface.text.TextViewerHoverManager; // packageimport | |
40 import dwtx.jface.text.DocumentRewriteSession; // packageimport | |
41 import dwtx.jface.text.TextViewer; // packageimport | |
42 import dwtx.jface.text.ITextViewerExtension8; // packageimport | |
43 import dwtx.jface.text.RegExMessages; // packageimport | |
44 import dwtx.jface.text.IDelayedInputChangeProvider; // packageimport | |
45 import dwtx.jface.text.ITextOperationTargetExtension; // packageimport | |
46 import dwtx.jface.text.IWidgetTokenOwner; // packageimport | |
47 import dwtx.jface.text.IViewportListener; // packageimport | |
48 import dwtx.jface.text.GapTextStore; // packageimport | |
49 import dwtx.jface.text.MarkSelection; // packageimport | |
50 import dwtx.jface.text.IDocumentPartitioningListenerExtension; // packageimport | |
51 import dwtx.jface.text.IDocumentAdapterExtension; // packageimport | |
52 import dwtx.jface.text.IInformationControlExtension; // packageimport | |
53 import dwtx.jface.text.IDocumentPartitioningListenerExtension2; // packageimport | |
54 import dwtx.jface.text.DefaultDocumentAdapter; // packageimport | |
55 import dwtx.jface.text.ITextViewerExtension3; // packageimport | |
56 import dwtx.jface.text.IInformationControlCreator; // packageimport | |
57 import dwtx.jface.text.TypedRegion; // packageimport | |
58 import dwtx.jface.text.ISynchronizable; // packageimport | |
59 import dwtx.jface.text.IMarkRegionTarget; // packageimport | |
60 import dwtx.jface.text.TextViewerUndoManager; // packageimport | |
61 import dwtx.jface.text.IRegion; // packageimport | |
62 import dwtx.jface.text.IInformationControlExtension2; // packageimport | |
63 import dwtx.jface.text.IDocumentExtension4; // packageimport | |
64 import dwtx.jface.text.IDocumentExtension2; // packageimport | |
65 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport | |
66 import dwtx.jface.text.Assert; // packageimport | |
67 import dwtx.jface.text.DefaultInformationControl; // packageimport | |
68 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport | |
69 import dwtx.jface.text.DocumentClone; // packageimport | |
70 import dwtx.jface.text.DefaultUndoManager; // packageimport | |
71 import dwtx.jface.text.IFindReplaceTarget; // packageimport | |
72 import dwtx.jface.text.IAutoEditStrategy; // packageimport | |
73 import dwtx.jface.text.ILineTrackerExtension; // packageimport | |
74 import dwtx.jface.text.IUndoManagerExtension; // packageimport | |
75 import dwtx.jface.text.TextSelection; // packageimport | |
76 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport | |
77 import dwtx.jface.text.IAutoIndentStrategy; // packageimport | |
78 import dwtx.jface.text.IPainter; // packageimport | |
79 import dwtx.jface.text.IInformationControl; // packageimport | |
80 import dwtx.jface.text.IInformationControlExtension3; // packageimport | |
81 import dwtx.jface.text.ITextViewerExtension6; // packageimport | |
82 import dwtx.jface.text.IInformationControlExtension4; // packageimport | |
83 import dwtx.jface.text.DefaultLineTracker; // packageimport | |
84 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport | |
85 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport | |
86 import dwtx.jface.text.ITextHover; // packageimport | |
87 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport | |
88 import dwtx.jface.text.ILineTracker; // packageimport | |
89 import dwtx.jface.text.Line; // packageimport | |
90 import dwtx.jface.text.ITextViewerExtension; // packageimport | |
91 import dwtx.jface.text.IDocumentAdapter; // packageimport | |
92 import dwtx.jface.text.TextEvent; // packageimport | |
93 import dwtx.jface.text.BadLocationException; // packageimport | |
94 import dwtx.jface.text.AbstractLineTracker; // packageimport | |
95 import dwtx.jface.text.TreeLineTracker; // packageimport | |
96 import dwtx.jface.text.ITextPresentationListener; // packageimport | |
97 import dwtx.jface.text.Region; // packageimport | |
98 import dwtx.jface.text.ITextViewer; // packageimport | |
99 import dwtx.jface.text.IDocumentInformationMapping; // packageimport | |
100 import dwtx.jface.text.MarginPainter; // packageimport | |
101 import dwtx.jface.text.IPaintPositionManager; // packageimport | |
102 import dwtx.jface.text.TextPresentation; // packageimport | |
103 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport | |
104 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport | |
105 import dwtx.jface.text.ISelectionValidator; // packageimport | |
106 import dwtx.jface.text.IDocumentExtension; // packageimport | |
107 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport | |
108 import dwtx.jface.text.ConfigurableLineTracker; // packageimport | |
109 import dwtx.jface.text.SlaveDocumentEvent; // packageimport | |
110 import dwtx.jface.text.IDocumentListener; // packageimport | |
111 import dwtx.jface.text.PaintManager; // packageimport | |
112 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport | |
113 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport | |
114 import dwtx.jface.text.IDocumentExtension3; // packageimport | |
115 import dwtx.jface.text.Position; // packageimport | |
116 import dwtx.jface.text.TextMessages; // packageimport | |
117 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport | |
118 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport | |
119 import dwtx.jface.text.IPositionUpdater; // packageimport | |
120 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport | |
121 import dwtx.jface.text.ListLineTracker; // packageimport | |
122 import dwtx.jface.text.ITextInputListener; // packageimport | |
123 import dwtx.jface.text.BadPositionCategoryException; // packageimport | |
124 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport | |
125 import dwtx.jface.text.IInputChangedListener; // packageimport | |
126 import dwtx.jface.text.ITextOperationTarget; // packageimport | |
127 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport | |
128 import dwtx.jface.text.ITextViewerExtension7; // packageimport | |
129 import dwtx.jface.text.IInformationControlExtension5; // packageimport | |
130 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport | |
131 import dwtx.jface.text.JFaceTextUtil; // packageimport | |
132 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport | |
133 import dwtx.jface.text.TabsToSpacesConverter; // packageimport | |
134 import dwtx.jface.text.CursorLinePainter; // packageimport | |
135 import dwtx.jface.text.ITextHoverExtension; // packageimport | |
136 import dwtx.jface.text.IEventConsumer; // packageimport | |
137 import dwtx.jface.text.IDocument; // packageimport | |
138 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport | |
139 import dwtx.jface.text.DocumentCommand; // packageimport | |
140 import dwtx.jface.text.TypedPosition; // packageimport | |
141 import dwtx.jface.text.IEditingSupportRegistry; // packageimport | |
142 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport | |
143 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport | |
144 import dwtx.jface.text.IEditingSupport; // packageimport | |
145 import dwtx.jface.text.IMarkSelection; // packageimport | |
146 import dwtx.jface.text.ISlaveDocumentManager; // packageimport | |
147 import dwtx.jface.text.DocumentEvent; // packageimport | |
148 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport | |
149 import dwtx.jface.text.ITextStore; // packageimport | |
150 import dwtx.jface.text.JFaceTextMessages; // packageimport | |
151 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport | |
152 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport | |
153 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | |
154 import dwtx.jface.text.TextAttribute; // packageimport | |
155 import dwtx.jface.text.ITextViewerExtension4; // packageimport | |
156 import dwtx.jface.text.ITypedRegion; // packageimport | |
157 | |
129 | 158 import dwt.dwthelper.utils; |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
151
diff
changeset
|
159 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
151
diff
changeset
|
160 |
158 | 161 // import java.util.regex.PatternSyntaxException; |
129 | 162 |
163 import dwtx.core.runtime.Assert; | |
164 import dwtx.core.runtime.ListenerList; | |
165 | |
166 | |
167 /** | |
168 * Abstract default implementation of <code>IDocument</code> and its extension | |
169 * interfaces {@link dwtx.jface.text.IDocumentExtension}, | |
170 * {@link dwtx.jface.text.IDocumentExtension2}, | |
171 * {@link dwtx.jface.text.IDocumentExtension3}, | |
172 * {@link dwtx.jface.text.IDocumentExtension4}, as well as | |
173 * {@link dwtx.jface.text.IRepairableDocument}. | |
174 * <p> | |
175 * | |
176 * An <code>AbstractDocument</code> supports the following implementation | |
177 * plug-ins: | |
178 * <ul> | |
179 * <li>a text store implementing {@link dwtx.jface.text.ITextStore} for | |
180 * storing and managing the document's content,</li> | |
181 * <li>a line tracker implementing {@link dwtx.jface.text.ILineTracker} | |
182 * to map character positions to line numbers and vice versa</li> | |
183 * </ul> | |
184 * The document can dynamically change the text store when switching between | |
185 * sequential rewrite mode and normal mode. | |
186 * <p> | |
187 * | |
188 * This class must be subclassed. Subclasses must configure which implementation | |
189 * plug-ins the document instance should use. Subclasses are not intended to | |
190 * overwrite existing methods. | |
191 * | |
192 * @see dwtx.jface.text.ITextStore | |
193 * @see dwtx.jface.text.ILineTracker | |
194 */ | |
195 public abstract class AbstractDocument : IDocument, IDocumentExtension, IDocumentExtension2, IDocumentExtension3, IDocumentExtension4, IRepairableDocument, IRepairableDocumentExtension { | |
196 | |
197 /** | |
198 * Tells whether this class is in debug mode. | |
199 * @since 3.1 | |
200 */ | |
147 | 201 private static const bool DEBUG= false; |
129 | 202 |
203 | |
204 /** | |
205 * Inner class to bundle a registered post notification replace operation together with its | |
206 * owner. | |
207 * | |
208 * @since 2.0 | |
209 */ | |
210 static private class RegisteredReplace { | |
211 /** The owner of this replace operation. */ | |
212 IDocumentListener fOwner; | |
213 /** The replace operation */ | |
214 IDocumentExtension.IReplace fReplace; | |
215 | |
216 /** | |
217 * Creates a new bundle object. | |
218 * @param owner the document listener owning the replace operation | |
219 * @param replace the replace operation | |
220 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
221 this(IDocumentListener owner, IDocumentExtension.IReplace replace) { |
129 | 222 fOwner= owner; |
223 fReplace= replace; | |
224 } | |
225 } | |
226 | |
227 | |
228 /** The document's text store */ | |
229 private ITextStore fStore; | |
230 /** The document's line tracker */ | |
231 private ILineTracker fTracker; | |
232 /** The registered document listeners */ | |
233 private ListenerList fDocumentListeners; | |
234 /** The registered pre-notified document listeners */ | |
235 private ListenerList fPrenotifiedDocumentListeners; | |
236 /** The registered document partitioning listeners */ | |
237 private ListenerList fDocumentPartitioningListeners; | |
238 /** All positions managed by the document ordered by their start positions. */ | |
239 private Map fPositions; | |
240 /** | |
241 * All positions managed by the document ordered by there end positions. | |
242 * @since 3.4 | |
243 */ | |
244 private Map fEndPositions; | |
245 /** All registered document position updaters */ | |
246 private List fPositionUpdaters; | |
247 /** | |
248 * The list of post notification changes | |
249 * @since 2.0 | |
250 */ | |
251 private List fPostNotificationChanges; | |
252 /** | |
253 * The reentrance count for post notification changes. | |
254 * @since 2.0 | |
255 */ | |
256 private int fReentranceCount= 0; | |
257 /** | |
258 * Indicates whether post notification change processing has been stopped. | |
259 * @since 2.0 | |
260 */ | |
261 private int fStoppedCount= 0; | |
262 /** | |
263 * Indicates whether the registration of post notification changes should be ignored. | |
264 * @since 2.1 | |
265 */ | |
266 private bool fAcceptPostNotificationReplaces= true; | |
267 /** | |
268 * Indicates whether the notification of listeners has been stopped. | |
269 * @since 2.1 | |
270 */ | |
271 private int fStoppedListenerNotification= 0; | |
272 /** | |
273 * The document event to be sent after listener notification has been resumed. | |
274 * @since 2.1 | |
275 */ | |
276 private DocumentEvent fDeferredDocumentEvent; | |
277 /** | |
278 * The registered document partitioners. | |
279 * @since 3.0 | |
280 */ | |
281 private Map fDocumentPartitioners; | |
282 /** | |
283 * The partitioning changed event. | |
284 * @since 3.0 | |
285 */ | |
286 private DocumentPartitioningChangedEvent fDocumentPartitioningChangedEvent; | |
287 /** | |
288 * The find/replace document adapter. | |
289 * @since 3.0 | |
290 */ | |
291 private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter; | |
292 /** | |
293 * The active document rewrite session. | |
294 * @since 3.1 | |
295 */ | |
296 private DocumentRewriteSession fDocumentRewriteSession; | |
297 /** | |
298 * The registered document rewrite session listeners. | |
299 * @since 3.1 | |
300 */ | |
301 private List fDocumentRewriteSessionListeners; | |
302 /** | |
303 * The current modification stamp. | |
304 * @since 3.1 | |
305 */ | |
306 private long fModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; | |
307 /** | |
308 * Keeps track of next modification stamp. | |
309 * @since 3.1.1 | |
310 */ | |
311 private long fNextModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; | |
312 /** | |
313 * This document's default line delimiter. | |
314 * @since 3.1 | |
315 */ | |
316 private String fInitialLineDelimiter; | |
317 | |
318 | |
319 /** | |
320 * The default constructor does not perform any configuration | |
321 * but leaves it to the clients who must first initialize the | |
322 * implementation plug-ins and then call <code>completeInitialization</code>. | |
323 * Results in the construction of an empty document. | |
324 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
325 protected this() { |
129 | 326 fModificationStamp= getNextModificationStamp(); |
327 } | |
328 | |
329 | |
330 /** | |
331 * Returns the document's text store. Assumes that the | |
332 * document has been initialized with a text store. | |
333 * | |
334 * @return the document's text store | |
335 */ | |
336 protected ITextStore getStore() { | |
337 Assert.isNotNull(fStore); | |
338 return fStore; | |
339 } | |
340 | |
341 /** | |
342 * Returns the document's line tracker. Assumes that the | |
343 * document has been initialized with a line tracker. | |
344 * | |
345 * @return the document's line tracker | |
346 */ | |
347 protected ILineTracker getTracker() { | |
348 Assert.isNotNull(fTracker); | |
349 return fTracker; | |
350 } | |
351 | |
352 /** | |
353 * Returns the document's document listeners. | |
354 * | |
355 * @return the document's document listeners | |
356 */ | |
357 protected List getDocumentListeners() { | |
358 return Arrays.asList(fDocumentListeners.getListeners()); | |
359 } | |
360 | |
361 /** | |
362 * Returns the document's partitioning listeners. | |
363 * | |
364 * @return the document's partitioning listeners | |
365 */ | |
366 protected List getDocumentPartitioningListeners() { | |
367 return Arrays.asList(fDocumentPartitioningListeners.getListeners()); | |
368 } | |
369 | |
370 /** | |
371 * Returns all positions managed by the document grouped by category. | |
372 * | |
373 * @return the document's positions | |
374 */ | |
375 protected Map getDocumentManagedPositions() { | |
376 return fPositions; | |
377 } | |
378 | |
379 /* | |
380 * @see dwtx.jface.text.IDocument#getDocumentPartitioner() | |
381 */ | |
382 public IDocumentPartitioner getDocumentPartitioner() { | |
383 return getDocumentPartitioner(DEFAULT_PARTITIONING); | |
384 } | |
385 | |
386 | |
387 | |
388 //--- implementation configuration interface ------------ | |
389 | |
390 /** | |
391 * Sets the document's text store. | |
392 * Must be called at the beginning of the constructor. | |
393 * | |
394 * @param store the document's text store | |
395 */ | |
396 protected void setTextStore(ITextStore store) { | |
397 fStore= store; | |
398 } | |
399 | |
400 /** | |
401 * Sets the document's line tracker. | |
402 * Must be called at the beginning of the constructor. | |
403 * | |
404 * @param tracker the document's line tracker | |
405 */ | |
406 protected void setLineTracker(ILineTracker tracker) { | |
407 fTracker= tracker; | |
408 } | |
409 | |
410 /* | |
411 * @see dwtx.jface.text.IDocument#setDocumentPartitioner(dwtx.jface.text.IDocumentPartitioner) | |
412 */ | |
413 public void setDocumentPartitioner(IDocumentPartitioner partitioner) { | |
414 setDocumentPartitioner(DEFAULT_PARTITIONING, partitioner); | |
415 } | |
416 | |
417 /** | |
418 * Initializes document listeners, positions, and position updaters. | |
419 * Must be called inside the constructor after the implementation plug-ins | |
420 * have been set. | |
421 */ | |
422 protected void completeInitialization() { | |
423 | |
424 fPositions= new HashMap(); | |
425 fEndPositions= new HashMap(); | |
426 fPositionUpdaters= new ArrayList(); | |
427 fDocumentListeners= new ListenerList(ListenerList.IDENTITY); | |
428 fPrenotifiedDocumentListeners= new ListenerList(ListenerList.IDENTITY); | |
429 fDocumentPartitioningListeners= new ListenerList(ListenerList.IDENTITY); | |
430 fDocumentRewriteSessionListeners= new ArrayList(); | |
431 | |
432 addPositionCategory(DEFAULT_CATEGORY); | |
433 addPositionUpdater(new DefaultPositionUpdater(DEFAULT_CATEGORY)); | |
434 } | |
435 | |
436 | |
437 //------------------------------------------------------- | |
438 | |
439 /* | |
440 * @see dwtx.jface.text.IDocument#addDocumentListener(dwtx.jface.text.IDocumentListener) | |
441 */ | |
442 public void addDocumentListener(IDocumentListener listener) { | |
443 Assert.isNotNull(listener); | |
444 fDocumentListeners.add(listener); | |
445 } | |
446 | |
447 /* | |
448 * @see dwtx.jface.text.IDocument#removeDocumentListener(dwtx.jface.text.IDocumentListener) | |
449 */ | |
450 public void removeDocumentListener(IDocumentListener listener) { | |
451 Assert.isNotNull(listener); | |
452 fDocumentListeners.remove(listener); | |
453 } | |
454 | |
455 /* | |
456 * @see dwtx.jface.text.IDocument#addPrenotifiedDocumentListener(dwtx.jface.text.IDocumentListener) | |
457 */ | |
458 public void addPrenotifiedDocumentListener(IDocumentListener listener) { | |
459 Assert.isNotNull(listener); | |
460 fPrenotifiedDocumentListeners.add(listener); | |
461 } | |
462 | |
463 /* | |
464 * @see dwtx.jface.text.IDocument#removePrenotifiedDocumentListener(dwtx.jface.text.IDocumentListener) | |
465 */ | |
466 public void removePrenotifiedDocumentListener(IDocumentListener listener) { | |
467 Assert.isNotNull(listener); | |
468 fPrenotifiedDocumentListeners.remove(listener); | |
469 } | |
470 | |
471 /* | |
472 * @see dwtx.jface.text.IDocument#addDocumentPartitioningListener(dwtx.jface.text.IDocumentPartitioningListener) | |
473 */ | |
474 public void addDocumentPartitioningListener(IDocumentPartitioningListener listener) { | |
475 Assert.isNotNull(listener); | |
476 fDocumentPartitioningListeners.add(listener); | |
477 } | |
478 | |
479 /* | |
480 * @see dwtx.jface.text.IDocument#removeDocumentPartitioningListener(dwtx.jface.text.IDocumentPartitioningListener) | |
481 */ | |
482 public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener) { | |
483 Assert.isNotNull(listener); | |
484 fDocumentPartitioningListeners.remove(listener); | |
485 } | |
486 | |
487 /* | |
488 * @see dwtx.jface.text.IDocument#addPosition(java.lang.String, dwtx.jface.text.Position) | |
489 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
490 public void addPosition(String category, Position position) { |
129 | 491 |
492 if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength())) | |
493 throw new BadLocationException(); | |
494 | |
495 if (category is null) | |
496 throw new BadPositionCategoryException(); | |
497 | |
134 | 498 List list= cast(List) fPositions.get(category); |
129 | 499 if (list is null) |
500 throw new BadPositionCategoryException(); | |
501 list.add(computeIndexInPositionList(list, position.offset), position); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
502 |
134 | 503 List endPositions= cast(List) fEndPositions.get(category); |
129 | 504 if (endPositions is null) |
505 throw new BadPositionCategoryException(); | |
506 endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position); | |
507 } | |
508 | |
509 /* | |
510 * @see dwtx.jface.text.IDocument#addPosition(dwtx.jface.text.Position) | |
511 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
512 public void addPosition(Position position) { |
129 | 513 try { |
514 addPosition(DEFAULT_CATEGORY, position); | |
515 } catch (BadPositionCategoryException e) { | |
516 } | |
517 } | |
518 | |
519 /* | |
520 * @see dwtx.jface.text.IDocument#addPositionCategory(java.lang.String) | |
521 */ | |
522 public void addPositionCategory(String category) { | |
523 | |
524 if (category is null) | |
525 return; | |
526 | |
527 if (!containsPositionCategory(category)) { | |
528 fPositions.put(category, new ArrayList()); | |
529 fEndPositions.put(category, new ArrayList()); | |
530 } | |
531 } | |
532 | |
533 /* | |
534 * @see dwtx.jface.text.IDocument#addPositionUpdater(dwtx.jface.text.IPositionUpdater) | |
535 */ | |
536 public void addPositionUpdater(IPositionUpdater updater) { | |
537 insertPositionUpdater(updater, fPositionUpdaters.size()); | |
538 } | |
539 | |
540 /* | |
541 * @see dwtx.jface.text.IDocument#containsPosition(java.lang.String, int, int) | |
542 */ | |
543 public bool containsPosition(String category, int offset, int length) { | |
544 | |
545 if (category is null) | |
546 return false; | |
547 | |
134 | 548 List list= cast(List) fPositions.get(category); |
129 | 549 if (list is null) |
550 return false; | |
551 | |
552 int size= list.size(); | |
553 if (size is 0) | |
554 return false; | |
555 | |
556 int index= computeIndexInPositionList(list, offset); | |
557 if (index < size) { | |
134 | 558 Position p= cast(Position) list.get(index); |
129 | 559 while (p !is null && p.offset is offset) { |
560 if (p.length is length) | |
561 return true; | |
562 ++ index; | |
134 | 563 p= (index < size) ? cast(Position) list.get(index) : null; |
129 | 564 } |
565 } | |
566 | |
567 return false; | |
568 } | |
569 | |
570 /* | |
571 * @see dwtx.jface.text.IDocument#containsPositionCategory(java.lang.String) | |
572 */ | |
573 public bool containsPositionCategory(String category) { | |
574 if (category !is null) | |
575 return fPositions.containsKey(category); | |
576 return false; | |
577 } | |
578 | |
579 | |
580 /** | |
581 * Computes the index in the list of positions at which a position with the given | |
582 * offset would be inserted. The position is supposed to become the first in this list | |
583 * of all positions with the same offset. | |
584 * | |
585 * @param positions the list in which the index is computed | |
586 * @param offset the offset for which the index is computed | |
587 * @return the computed index | |
588 * | |
589 * @see IDocument#computeIndexInCategory(String, int) | |
590 * @deprecated As of 3.4, replaced by {@link #computeIndexInPositionList(List, int, bool)} | |
591 */ | |
592 protected int computeIndexInPositionList(List positions, int offset) { | |
593 return computeIndexInPositionList(positions, offset, true); | |
594 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
595 |
129 | 596 /** |
597 * Computes the index in the list of positions at which a position with the given | |
598 * position would be inserted. The position to insert is supposed to become the first | |
599 * in this list of all positions with the same position. | |
600 * | |
601 * @param positions the list in which the index is computed | |
602 * @param offset the offset for which the index is computed | |
603 * @param orderedByOffset <code>true</code> if ordered by offset, false if ordered by end position | |
604 * @return the computed index | |
605 * @since 3.4 | |
606 */ | |
607 protected int computeIndexInPositionList(List positions, int offset, bool orderedByOffset) { | |
608 if (positions.size() is 0) | |
609 return 0; | |
610 | |
611 int left= 0; | |
612 int right= positions.size() -1; | |
613 int mid= 0; | |
614 Position p= null; | |
615 | |
616 while (left < right) { | |
617 | |
618 mid= (left + right) / 2; | |
619 | |
134 | 620 p= cast(Position) positions.get(mid); |
129 | 621 int pOffset= getOffset(orderedByOffset, p); |
622 if (offset < pOffset) { | |
623 if (left is mid) | |
624 right= left; | |
625 else | |
626 right= mid -1; | |
627 } else if (offset > pOffset) { | |
628 if (right is mid) | |
629 left= right; | |
630 else | |
631 left= mid +1; | |
632 } else if (offset is pOffset) { | |
633 left= right= mid; | |
634 } | |
635 | |
636 } | |
637 | |
638 int pos= left; | |
134 | 639 p= cast(Position) positions.get(pos); |
129 | 640 int pPosition= getOffset(orderedByOffset, p); |
641 if (offset > pPosition) { | |
642 // append to the end | |
643 pos++; | |
644 } else { | |
645 // entry will become the first of all entries with the same offset | |
646 do { | |
647 --pos; | |
648 if (pos < 0) | |
649 break; | |
134 | 650 p= cast(Position) positions.get(pos); |
129 | 651 pPosition= getOffset(orderedByOffset, p); |
652 } while (offset is pPosition); | |
653 ++pos; | |
654 } | |
655 | |
656 Assert.isTrue(0 <= pos && pos <= positions.size()); | |
657 | |
658 return pos; | |
659 } | |
660 | |
661 /* | |
662 * @since 3.4 | |
663 */ | |
664 private int getOffset(bool orderedByOffset, Position position) { | |
665 if (orderedByOffset || position.getLength() is 0) | |
666 return position.getOffset(); | |
667 return position.getOffset() + position.getLength() - 1; | |
668 } | |
669 | |
670 /* | |
671 * @see dwtx.jface.text.IDocument#computeIndexInCategory(java.lang.String, int) | |
672 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
673 public int computeIndexInCategory(String category, int offset) { |
129 | 674 |
675 if (0 > offset || offset > getLength()) | |
676 throw new BadLocationException(); | |
677 | |
134 | 678 List c= cast(List) fPositions.get(category); |
129 | 679 if (c is null) |
680 throw new BadPositionCategoryException(); | |
681 | |
682 return computeIndexInPositionList(c, offset); | |
683 } | |
684 | |
685 /** | |
686 * Fires the document partitioning changed notification to all registered | |
687 * document partitioning listeners. Uses a robust iterator. | |
688 * | |
689 * @deprecated as of 2.0. Use <code>fireDocumentPartitioningChanged(IRegion)</code> instead. | |
690 */ | |
691 protected void fireDocumentPartitioningChanged() { | |
692 if (fDocumentPartitioningListeners is null) | |
693 return; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
694 |
129 | 695 Object[] listeners= fDocumentPartitioningListeners.getListeners(); |
696 for (int i= 0; i < listeners.length; i++) | |
134 | 697 (cast(IDocumentPartitioningListener)listeners[i]).documentPartitioningChanged(this); |
129 | 698 } |
699 | |
700 /** | |
701 * Fires the document partitioning changed notification to all registered | |
702 * document partitioning listeners. Uses a robust iterator. | |
703 * | |
704 * @param region the region in which partitioning has changed | |
705 * | |
706 * @see IDocumentPartitioningListenerExtension | |
707 * @since 2.0 | |
708 * @deprecated as of 3.0. Use | |
709 * <code>fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent)</code> | |
710 * instead. | |
711 */ | |
712 protected void fireDocumentPartitioningChanged(IRegion region) { | |
713 if (fDocumentPartitioningListeners is null) | |
714 return; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
715 |
129 | 716 Object[] listeners= fDocumentPartitioningListeners.getListeners(); |
717 for (int i= 0; i < listeners.length; i++) { | |
134 | 718 IDocumentPartitioningListener l= cast(IDocumentPartitioningListener)listeners[i]; |
138 | 719 if ( cast(IDocumentPartitioningListenerExtension)l ) |
134 | 720 (cast(IDocumentPartitioningListenerExtension) l).documentPartitioningChanged(this, region); |
129 | 721 else |
722 l.documentPartitioningChanged(this); | |
723 } | |
724 } | |
725 | |
726 /** | |
727 * Fires the document partitioning changed notification to all registered | |
728 * document partitioning listeners. Uses a robust iterator. | |
729 * | |
730 * @param event the document partitioning changed event | |
731 * | |
732 * @see IDocumentPartitioningListenerExtension2 | |
733 * @since 3.0 | |
734 */ | |
735 protected void fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent event) { | |
736 if (fDocumentPartitioningListeners is null) | |
737 return; | |
738 | |
739 Object[] listeners= fDocumentPartitioningListeners.getListeners(); | |
740 for (int i= 0; i < listeners.length; i++) { | |
134 | 741 IDocumentPartitioningListener l= cast(IDocumentPartitioningListener)listeners[i]; |
138 | 742 if ( cast(IDocumentPartitioningListenerExtension2)l ) { |
134 | 743 IDocumentPartitioningListenerExtension2 extension2= cast(IDocumentPartitioningListenerExtension2) l; |
129 | 744 extension2.documentPartitioningChanged(event); |
138 | 745 } else if ( cast(IDocumentPartitioningListenerExtension)l ) { |
134 | 746 IDocumentPartitioningListenerExtension extension= cast(IDocumentPartitioningListenerExtension) l; |
129 | 747 extension.documentPartitioningChanged(this, event.getCoverage()); |
748 } else { | |
749 l.documentPartitioningChanged(this); | |
750 } | |
751 } | |
752 } | |
753 | |
754 /** | |
755 * Fires the given document event to all registers document listeners informing them | |
756 * about the forthcoming document manipulation. Uses a robust iterator. | |
757 * | |
758 * @param event the event to be sent out | |
759 */ | |
760 protected void fireDocumentAboutToBeChanged(DocumentEvent event) { | |
761 | |
762 // IDocumentExtension | |
763 if (fReentranceCount is 0) | |
764 flushPostNotificationChanges(); | |
765 | |
766 if (fDocumentPartitioners !is null) { | |
767 Iterator e= fDocumentPartitioners.values().iterator(); | |
768 while (e.hasNext()) { | |
134 | 769 IDocumentPartitioner p= cast(IDocumentPartitioner) e.next(); |
138 | 770 if ( cast(IDocumentPartitionerExtension3)p ) { |
134 | 771 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) p; |
129 | 772 if (extension.getActiveRewriteSession() !is null) |
773 continue; | |
774 } | |
775 p.documentAboutToBeChanged(event); | |
776 } | |
777 } | |
778 | |
779 Object[] listeners= fPrenotifiedDocumentListeners.getListeners(); | |
780 for (int i= 0; i < listeners.length; i++) | |
134 | 781 (cast(IDocumentListener)listeners[i]).documentAboutToBeChanged(event); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
782 |
129 | 783 listeners= fDocumentListeners.getListeners(); |
784 for (int i= 0; i < listeners.length; i++) | |
134 | 785 (cast(IDocumentListener)listeners[i]).documentAboutToBeChanged(event); |
129 | 786 } |
787 | |
788 | |
789 /** | |
790 * Updates document partitioning and document positions according to the | |
791 * specification given by the document event. | |
792 * | |
793 * @param event the document event describing the change to which structures must be adapted | |
794 */ | |
795 protected void updateDocumentStructures(DocumentEvent event) { | |
796 | |
797 if (fDocumentPartitioners !is null) { | |
798 fDocumentPartitioningChangedEvent= new DocumentPartitioningChangedEvent(this); | |
799 Iterator e= fDocumentPartitioners.keySet().iterator(); | |
800 while (e.hasNext()) { | |
134 | 801 String partitioning= cast(String) e.next(); |
802 IDocumentPartitioner partitioner= cast(IDocumentPartitioner) fDocumentPartitioners.get(partitioning); | |
129 | 803 |
138 | 804 if ( cast(IDocumentPartitionerExtension3)partitioner ) { |
134 | 805 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 806 if (extension.getActiveRewriteSession() !is null) |
807 continue; | |
808 } | |
809 | |
138 | 810 if ( cast(IDocumentPartitionerExtension)partitioner ) { |
134 | 811 IDocumentPartitionerExtension extension= cast(IDocumentPartitionerExtension) partitioner; |
129 | 812 IRegion r= extension.documentChanged2(event); |
813 if (r !is null) | |
814 fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, r.getOffset(), r.getLength()); | |
815 } else { | |
816 if (partitioner.documentChanged(event)) | |
817 fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, 0, event.getDocument().getLength()); | |
818 } | |
819 } | |
820 } | |
821 | |
822 if (fPositions.size() > 0) | |
823 updatePositions(event); | |
824 } | |
825 | |
826 /** | |
827 * Notifies all listeners about the given document change. Uses a robust | |
828 * iterator. | |
829 * <p> | |
830 * Executes all registered post notification replace operation. | |
831 * | |
832 * @param event the event to be sent out. | |
833 */ | |
834 protected void doFireDocumentChanged(DocumentEvent event) { | |
835 bool changed= fDocumentPartitioningChangedEvent !is null && !fDocumentPartitioningChangedEvent.isEmpty(); | |
836 IRegion change= changed ? fDocumentPartitioningChangedEvent.getCoverage() : null; | |
837 doFireDocumentChanged(event, changed, change); | |
838 } | |
839 | |
840 /** | |
841 * Notifies all listeners about the given document change. | |
842 * Uses a robust iterator. <p> | |
843 * Executes all registered post notification replace operation. | |
844 * | |
845 * @param event the event to be sent out | |
846 * @param firePartitionChange <code>true</code> if a partition change notification should be sent | |
847 * @param partitionChange the region whose partitioning changed | |
848 * @since 2.0 | |
849 * @deprecated as of 3.0. Use <code>doFireDocumentChanged2(DocumentEvent)</code> instead; this method will be removed. | |
850 */ | |
851 protected void doFireDocumentChanged(DocumentEvent event, bool firePartitionChange, IRegion partitionChange) { | |
852 doFireDocumentChanged2(event); | |
853 } | |
854 | |
855 /** | |
856 * Notifies all listeners about the given document change. Uses a robust | |
857 * iterator. | |
858 * <p> | |
859 * Executes all registered post notification replace operation. | |
860 * <p> | |
861 * This method will be renamed to <code>doFireDocumentChanged</code>. | |
862 * | |
863 * @param event the event to be sent out | |
864 * @since 3.0 | |
865 */ | |
866 protected void doFireDocumentChanged2(DocumentEvent event) { | |
867 | |
868 DocumentPartitioningChangedEvent p= fDocumentPartitioningChangedEvent; | |
869 fDocumentPartitioningChangedEvent= null; | |
870 if (p !is null && !p.isEmpty()) | |
871 fireDocumentPartitioningChanged(p); | |
872 | |
873 Object[] listeners= fPrenotifiedDocumentListeners.getListeners(); | |
874 for (int i= 0; i < listeners.length; i++) | |
134 | 875 (cast(IDocumentListener)listeners[i]).documentChanged(event); |
129 | 876 |
877 listeners= fDocumentListeners.getListeners(); | |
878 for (int i= 0; i < listeners.length; i++) | |
134 | 879 (cast(IDocumentListener)listeners[i]).documentChanged(event); |
129 | 880 |
881 // IDocumentExtension | |
882 ++ fReentranceCount; | |
883 try { | |
884 if (fReentranceCount is 1) | |
885 executePostNotificationChanges(); | |
886 } finally { | |
887 -- fReentranceCount; | |
888 } | |
889 } | |
890 | |
891 /** | |
892 * Updates the internal document structures and informs all document listeners | |
893 * if listener notification has been enabled. Otherwise it remembers the event | |
894 * to be sent to the listeners on resume. | |
895 * | |
896 * @param event the document event to be sent out | |
897 */ | |
898 protected void fireDocumentChanged(DocumentEvent event) { | |
899 updateDocumentStructures(event); | |
900 | |
901 if (fStoppedListenerNotification is 0) | |
902 doFireDocumentChanged(event); | |
903 else | |
904 fDeferredDocumentEvent= event; | |
905 } | |
906 | |
907 /* | |
908 * @see dwtx.jface.text.IDocument#getChar(int) | |
909 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
910 public char getChar(int pos) { |
129 | 911 if ((0 > pos) || (pos >= getLength())) |
912 throw new BadLocationException(); | |
913 return getStore().get(pos); | |
914 } | |
915 | |
916 /* | |
917 * @see dwtx.jface.text.IDocument#getContentType(int) | |
918 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
919 public String getContentType(int offset) { |
129 | 920 String contentType= null; |
921 try { | |
922 contentType= getContentType(DEFAULT_PARTITIONING, offset, false); | |
923 Assert.isNotNull(contentType); | |
924 } catch (BadPartitioningException e) { | |
925 Assert.isTrue(false); | |
926 } | |
927 return contentType; | |
928 } | |
929 | |
930 /* | |
931 * @see dwtx.jface.text.IDocument#getLegalContentTypes() | |
932 */ | |
933 public String[] getLegalContentTypes() { | |
934 String[] contentTypes= null; | |
935 try { | |
936 contentTypes= getLegalContentTypes(DEFAULT_PARTITIONING); | |
937 Assert.isNotNull(contentTypes); | |
938 } catch (BadPartitioningException e) { | |
939 Assert.isTrue(false); | |
940 } | |
941 return contentTypes; | |
942 } | |
943 | |
944 /* | |
945 * @see dwtx.jface.text.IDocument#getLength() | |
946 */ | |
947 public int getLength() { | |
948 return getStore().getLength(); | |
949 } | |
950 | |
951 /* | |
952 * @see dwtx.jface.text.IDocument#getLineDelimiter(int) | |
953 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
954 public String getLineDelimiter(int line) { |
129 | 955 return getTracker().getLineDelimiter(line); |
956 } | |
957 | |
958 /* | |
959 * @see dwtx.jface.text.IDocument#getLegalLineDelimiters() | |
960 */ | |
961 public String[] getLegalLineDelimiters() { | |
962 return getTracker().getLegalLineDelimiters(); | |
963 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
964 |
129 | 965 /* |
966 * @see dwtx.jface.text.IDocumentExtension4#getDefaultLineDelimiter() | |
967 * @since 3.1 | |
968 */ | |
969 public String getDefaultLineDelimiter() { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
970 |
129 | 971 String lineDelimiter= null; |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
972 |
129 | 973 try { |
974 lineDelimiter= getLineDelimiter(0); | |
975 } catch (BadLocationException x) { | |
976 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
977 |
129 | 978 if (lineDelimiter !is null) |
979 return lineDelimiter; | |
980 | |
981 if (fInitialLineDelimiter !is null) | |
982 return fInitialLineDelimiter; | |
983 | |
984 String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$ | |
985 String[] delimiters= getLegalLineDelimiters(); | |
986 Assert.isTrue(delimiters.length > 0); | |
987 for (int i= 0; i < delimiters.length; i++) { | |
988 if (delimiters[i].equals(sysLineDelimiter)) { | |
989 lineDelimiter= sysLineDelimiter; | |
990 break; | |
991 } | |
992 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
993 |
129 | 994 if (lineDelimiter is null) |
995 lineDelimiter= delimiters[0]; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
996 |
129 | 997 return lineDelimiter; |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
998 |
129 | 999 } |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1000 |
129 | 1001 /* |
1002 * @see dwtx.jface.text.IDocumentExtension4#setInitialLineDelimiter(java.lang.String) | |
1003 * @since 3.1 | |
1004 */ | |
1005 public void setInitialLineDelimiter(String lineDelimiter) { | |
1006 Assert.isNotNull(lineDelimiter); | |
1007 fInitialLineDelimiter= lineDelimiter; | |
1008 } | |
1009 | |
1010 /* | |
1011 * @see dwtx.jface.text.IDocument#getLineLength(int) | |
1012 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1013 public int getLineLength(int line) { |
129 | 1014 return getTracker().getLineLength(line); |
1015 } | |
1016 | |
1017 /* | |
1018 * @see dwtx.jface.text.IDocument#getLineOfOffset(int) | |
1019 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1020 public int getLineOfOffset(int pos) { |
129 | 1021 return getTracker().getLineNumberOfOffset(pos); |
1022 } | |
1023 | |
1024 /* | |
1025 * @see dwtx.jface.text.IDocument#getLineOffset(int) | |
1026 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1027 public int getLineOffset(int line) { |
129 | 1028 return getTracker().getLineOffset(line); |
1029 } | |
1030 | |
1031 /* | |
1032 * @see dwtx.jface.text.IDocument#getLineInformation(int) | |
1033 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1034 public IRegion getLineInformation(int line) { |
129 | 1035 return getTracker().getLineInformation(line); |
1036 } | |
1037 | |
1038 /* | |
1039 * @see dwtx.jface.text.IDocument#getLineInformationOfOffset(int) | |
1040 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1041 public IRegion getLineInformationOfOffset(int offset) { |
129 | 1042 return getTracker().getLineInformationOfOffset(offset); |
1043 } | |
1044 | |
1045 /* | |
1046 * @see dwtx.jface.text.IDocument#getNumberOfLines() | |
1047 */ | |
1048 public int getNumberOfLines() { | |
1049 return getTracker().getNumberOfLines(); | |
1050 } | |
1051 | |
1052 /* | |
1053 * @see dwtx.jface.text.IDocument#getNumberOfLines(int, int) | |
1054 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1055 public int getNumberOfLines(int offset, int length) { |
129 | 1056 return getTracker().getNumberOfLines(offset, length); |
1057 } | |
1058 | |
1059 /* | |
1060 * @see dwtx.jface.text.IDocument#computeNumberOfLines(java.lang.String) | |
1061 */ | |
1062 public int computeNumberOfLines(String text) { | |
1063 return getTracker().computeNumberOfLines(text); | |
1064 } | |
1065 | |
1066 /* | |
1067 * @see dwtx.jface.text.IDocument#getPartition(int) | |
1068 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1069 public ITypedRegion getPartition(int offset) { |
129 | 1070 ITypedRegion partition= null; |
1071 try { | |
1072 partition= getPartition(DEFAULT_PARTITIONING, offset, false); | |
1073 Assert.isNotNull(partition); | |
1074 } catch (BadPartitioningException e) { | |
1075 Assert.isTrue(false); | |
1076 } | |
1077 return partition; | |
1078 } | |
1079 | |
1080 /* | |
1081 * @see dwtx.jface.text.IDocument#computePartitioning(int, int) | |
1082 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1083 public ITypedRegion[] computePartitioning(int offset, int length) { |
129 | 1084 ITypedRegion[] partitioning= null; |
1085 try { | |
1086 partitioning= computePartitioning(DEFAULT_PARTITIONING, offset, length, false); | |
1087 Assert.isNotNull(partitioning); | |
1088 } catch (BadPartitioningException e) { | |
1089 Assert.isTrue(false); | |
1090 } | |
1091 return partitioning; | |
1092 } | |
1093 | |
1094 /* | |
1095 * @see dwtx.jface.text.IDocument#getPositions(java.lang.String) | |
1096 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1097 public Position[] getPositions(String category) { |
129 | 1098 |
1099 if (category is null) | |
1100 throw new BadPositionCategoryException(); | |
1101 | |
134 | 1102 List c= cast(List) fPositions.get(category); |
129 | 1103 if (c is null) |
1104 throw new BadPositionCategoryException(); | |
1105 | |
1106 Position[] positions= new Position[c.size()]; | |
1107 c.toArray(positions); | |
1108 return positions; | |
1109 } | |
1110 | |
1111 /* | |
1112 * @see dwtx.jface.text.IDocument#getPositionCategories() | |
1113 */ | |
1114 public String[] getPositionCategories() { | |
1115 String[] categories= new String[fPositions.size()]; | |
1116 Iterator keys= fPositions.keySet().iterator(); | |
1117 for (int i= 0; i < categories.length; i++) | |
134 | 1118 categories[i]= cast(String) keys.next(); |
129 | 1119 return categories; |
1120 } | |
1121 | |
1122 /* | |
1123 * @see dwtx.jface.text.IDocument#getPositionUpdaters() | |
1124 */ | |
1125 public IPositionUpdater[] getPositionUpdaters() { | |
1126 IPositionUpdater[] updaters= new IPositionUpdater[fPositionUpdaters.size()]; | |
1127 fPositionUpdaters.toArray(updaters); | |
1128 return updaters; | |
1129 } | |
1130 | |
1131 /* | |
1132 * @see dwtx.jface.text.IDocument#get() | |
1133 */ | |
1134 public String get() { | |
1135 return getStore().get(0, getLength()); | |
1136 } | |
1137 | |
1138 /* | |
1139 * @see dwtx.jface.text.IDocument#get(int, int) | |
1140 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1141 public String get(int pos, int length) { |
129 | 1142 int myLength= getLength(); |
1143 if ((0 > pos) || (0 > length) || (pos + length > myLength)) | |
1144 throw new BadLocationException(); | |
1145 return getStore().get(pos, length); | |
1146 } | |
1147 | |
1148 /* | |
1149 * @see dwtx.jface.text.IDocument#insertPositionUpdater(dwtx.jface.text.IPositionUpdater, int) | |
1150 */ | |
1151 public void insertPositionUpdater(IPositionUpdater updater, int index) { | |
1152 | |
1153 for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { | |
1154 if (fPositionUpdaters.get(i) is updater) | |
1155 return; | |
1156 } | |
1157 | |
1158 if (index is fPositionUpdaters.size()) | |
1159 fPositionUpdaters.add(updater); | |
1160 else | |
1161 fPositionUpdaters.add(index, updater); | |
1162 } | |
1163 | |
1164 /* | |
1165 * @see dwtx.jface.text.IDocument#removePosition(java.lang.String, dwtx.jface.text.Position) | |
1166 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1167 public void removePosition(String category, Position position) { |
129 | 1168 |
1169 if (position is null) | |
1170 return; | |
1171 | |
1172 if (category is null) | |
1173 throw new BadPositionCategoryException(); | |
1174 | |
134 | 1175 List c= cast(List) fPositions.get(category); |
129 | 1176 if (c is null) |
1177 throw new BadPositionCategoryException(); | |
1178 removeFromPositionsList(c, position, true); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1179 |
134 | 1180 List endPositions= cast(List) fEndPositions.get(category); |
129 | 1181 if (endPositions is null) |
1182 throw new BadPositionCategoryException(); | |
1183 removeFromPositionsList(endPositions, position, false); | |
1184 } | |
1185 | |
1186 /** | |
1187 * Remove the given position form the given list of positions based on identity not equality. | |
1188 * | |
1189 * @param positions a list of positions | |
1190 * @param position the position to remove | |
1191 * @param orderedByOffset true if <code>positions</code> is ordered by offset, false if ordered by end position | |
1192 * @since 3.4 | |
1193 */ | |
1194 private void removeFromPositionsList(List positions, Position position, bool orderedByOffset) { | |
1195 int size= positions.size(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1196 |
129 | 1197 //Assume position is somewhere near it was before |
1198 int index= computeIndexInPositionList(positions, orderedByOffset ? position.offset : position.offset + position.length - 1, orderedByOffset); | |
1199 if (index < size && positions.get(index) is position) { | |
1200 positions.remove(index); | |
1201 return; | |
1202 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1203 |
129 | 1204 int back= index - 1; |
1205 int forth= index + 1; | |
1206 while (back >= 0 || forth < size) { | |
1207 if (back >= 0) { | |
1208 if (position is positions.get(back)) { | |
1209 positions.remove(back); | |
1210 return; | |
1211 } | |
1212 back--; | |
1213 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1214 |
129 | 1215 if (forth < size) { |
1216 if (position is positions.get(forth)) { | |
1217 positions.remove(forth); | |
1218 return; | |
1219 } | |
1220 forth++; | |
1221 } | |
1222 } | |
1223 } | |
1224 | |
1225 /* | |
1226 * @see dwtx.jface.text.IDocument#removePosition(dwtx.jface.text.Position) | |
1227 */ | |
1228 public void removePosition(Position position) { | |
1229 try { | |
1230 removePosition(DEFAULT_CATEGORY, position); | |
1231 } catch (BadPositionCategoryException e) { | |
1232 } | |
1233 } | |
1234 | |
1235 /* | |
1236 * @see dwtx.jface.text.IDocument#removePositionCategory(java.lang.String) | |
1237 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1238 public void removePositionCategory(String category) { |
129 | 1239 |
1240 if (category is null) | |
1241 return; | |
1242 | |
1243 if ( !containsPositionCategory(category)) | |
1244 throw new BadPositionCategoryException(); | |
1245 | |
1246 fPositions.remove(category); | |
1247 fEndPositions.remove(category); | |
1248 } | |
1249 | |
1250 /* | |
1251 * @see dwtx.jface.text.IDocument#removePositionUpdater(dwtx.jface.text.IPositionUpdater) | |
1252 */ | |
1253 public void removePositionUpdater(IPositionUpdater updater) { | |
1254 for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { | |
1255 if (fPositionUpdaters.get(i) is updater) { | |
1256 fPositionUpdaters.remove(i); | |
1257 return; | |
1258 } | |
1259 } | |
1260 } | |
1261 | |
1262 private long getNextModificationStamp() { | |
1263 if (fNextModificationStamp is Long.MAX_VALUE || fNextModificationStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) | |
1264 fNextModificationStamp= 0; | |
1265 else | |
1266 fNextModificationStamp= fNextModificationStamp + 1; | |
1267 | |
1268 return fNextModificationStamp; | |
1269 } | |
1270 | |
1271 /* | |
1272 * @see dwtx.jface.text.IDocumentExtension4#getModificationStamp() | |
1273 * @since 3.1 | |
1274 */ | |
1275 public long getModificationStamp() { | |
1276 return fModificationStamp; | |
1277 } | |
1278 | |
1279 /* | |
1280 * @see dwtx.jface.text.IDocument#replace(int, int, java.lang.String) | |
1281 * @since 3.1 | |
1282 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1283 public void replace(int pos, int length, String text, long modificationStamp) { |
129 | 1284 if ((0 > pos) || (0 > length) || (pos + length > getLength())) |
1285 throw new BadLocationException(); | |
1286 | |
1287 DocumentEvent e= new DocumentEvent(this, pos, length, text); | |
1288 fireDocumentAboutToBeChanged(e); | |
1289 | |
1290 getStore().replace(pos, length, text); | |
1291 getTracker().replace(pos, length, text); | |
1292 | |
1293 fModificationStamp= modificationStamp; | |
1294 fNextModificationStamp= Math.max(fModificationStamp, fNextModificationStamp); | |
1295 e.fModificationStamp= fModificationStamp; | |
1296 | |
1297 fireDocumentChanged(e); | |
1298 } | |
1299 | |
1300 /** | |
1301 * {@inheritDoc} | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1302 * |
129 | 1303 * @since 3.4 |
1304 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1305 public bool isLineInformationRepairNeeded(int offset, int length, String text) { |
129 | 1306 return false; |
1307 } | |
1308 | |
1309 /* | |
1310 * @see dwtx.jface.text.IDocument#replace(int, int, java.lang.String) | |
1311 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1312 public void replace(int pos, int length, String text) { |
129 | 1313 if (length is 0 && (text is null || text.length() is 0)) |
1314 replace(pos, length, text, getModificationStamp()); | |
1315 else | |
1316 replace(pos, length, text, getNextModificationStamp()); | |
1317 } | |
1318 | |
1319 /* | |
1320 * @see dwtx.jface.text.IDocument#set(java.lang.String) | |
1321 */ | |
1322 public void set(String text) { | |
1323 set(text, getNextModificationStamp()); | |
1324 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1325 |
129 | 1326 /* |
1327 * @see dwtx.jface.text.IDocumentExtension4#set(java.lang.String, long) | |
1328 * @since 3.1 | |
1329 */ | |
1330 public void set(String text, long modificationStamp) { | |
1331 int length= getStore().getLength(); | |
1332 | |
1333 DocumentEvent e= new DocumentEvent(this, 0, length, text); | |
1334 fireDocumentAboutToBeChanged(e); | |
1335 | |
1336 getStore().set(text); | |
1337 getTracker().set(text); | |
1338 | |
1339 fModificationStamp= modificationStamp; | |
1340 fNextModificationStamp= Math.max(fModificationStamp, fNextModificationStamp); | |
1341 e.fModificationStamp= fModificationStamp; | |
1342 | |
1343 fireDocumentChanged(e); | |
1344 } | |
1345 | |
1346 /** | |
1347 * Updates all positions of all categories to the change described by the | |
1348 * document event. All registered document updaters are called in the | |
1349 * sequence they have been arranged. Uses a robust iterator. | |
1350 * | |
1351 * @param event the document event describing the change to which to adapt | |
1352 * the positions | |
1353 */ | |
1354 protected void updatePositions(DocumentEvent event) { | |
1355 List list= new ArrayList(fPositionUpdaters); | |
1356 Iterator e= list.iterator(); | |
1357 while (e.hasNext()) { | |
134 | 1358 IPositionUpdater u= cast(IPositionUpdater) e.next(); |
129 | 1359 u.update(event); |
1360 } | |
1361 } | |
1362 | |
1363 /* | |
1364 * @see dwtx.jface.text.IDocument#search(int, java.lang.String, bool, bool, bool) | |
1365 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1366 public int search(int startPosition, String findString, bool forwardSearch, bool caseSensitive, bool wholeWord) { |
129 | 1367 try { |
1368 IRegion region= getFindReplaceDocumentAdapter().find(startPosition, findString, forwardSearch, caseSensitive, wholeWord, false); | |
1369 return region is null ? -1 : region.getOffset(); | |
1370 } catch (IllegalStateException ex) { | |
1371 return -1; | |
1372 } catch (PatternSyntaxException ex) { | |
1373 return -1; | |
1374 } | |
1375 } | |
1376 | |
1377 /** | |
1378 * Returns the find/replace adapter for this document. | |
1379 * | |
1380 * @return this document's find/replace document adapter | |
1381 * @since 3.0 | |
1382 */ | |
1383 private FindReplaceDocumentAdapter getFindReplaceDocumentAdapter() { | |
1384 if (fFindReplaceDocumentAdapter is null) | |
1385 fFindReplaceDocumentAdapter= new FindReplaceDocumentAdapter(this); | |
1386 | |
1387 return fFindReplaceDocumentAdapter; | |
1388 } | |
1389 | |
1390 /** | |
1391 * Flushes all registered post notification changes. | |
1392 * | |
1393 * @since 2.0 | |
1394 */ | |
1395 private void flushPostNotificationChanges() { | |
1396 if (fPostNotificationChanges !is null) | |
1397 fPostNotificationChanges.clear(); | |
1398 } | |
1399 | |
1400 /** | |
1401 * Executes all registered post notification changes. The process is | |
1402 * repeated until no new post notification changes are added. | |
1403 * | |
1404 * @since 2.0 | |
1405 */ | |
1406 private void executePostNotificationChanges() { | |
1407 | |
1408 if (fStoppedCount > 0) | |
1409 return; | |
1410 | |
1411 while (fPostNotificationChanges !is null) { | |
1412 List changes= fPostNotificationChanges; | |
1413 fPostNotificationChanges= null; | |
1414 | |
1415 Iterator e= changes.iterator(); | |
1416 while (e.hasNext()) { | |
134 | 1417 RegisteredReplace replace= cast(RegisteredReplace) e.next(); |
129 | 1418 replace.fReplace.perform(this, replace.fOwner); |
1419 } | |
1420 } | |
1421 } | |
1422 | |
1423 /* | |
1424 * @see dwtx.jface.text.IDocumentExtension2#acceptPostNotificationReplaces() | |
1425 * @since 2.1 | |
1426 */ | |
1427 public void acceptPostNotificationReplaces() { | |
1428 fAcceptPostNotificationReplaces= true; | |
1429 } | |
1430 | |
1431 /* | |
1432 * @see dwtx.jface.text.IDocumentExtension2#ignorePostNotificationReplaces() | |
1433 * @since 2.1 | |
1434 */ | |
1435 public void ignorePostNotificationReplaces() { | |
1436 fAcceptPostNotificationReplaces= false; | |
1437 } | |
1438 | |
1439 /* | |
1440 * @see dwtx.jface.text.IDocumentExtension#registerPostNotificationReplace(dwtx.jface.text.IDocumentListener, dwtx.jface.text.IDocumentExtension.IReplace) | |
1441 * @since 2.0 | |
1442 */ | |
1443 public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { | |
1444 if (fAcceptPostNotificationReplaces) { | |
1445 if (fPostNotificationChanges is null) | |
1446 fPostNotificationChanges= new ArrayList(1); | |
1447 fPostNotificationChanges.add(new RegisteredReplace(owner, replace)); | |
1448 } | |
1449 } | |
1450 | |
1451 /* | |
1452 * @see dwtx.jface.text.IDocumentExtension#stopPostNotificationProcessing() | |
1453 * @since 2.0 | |
1454 */ | |
1455 public void stopPostNotificationProcessing() { | |
1456 ++ fStoppedCount; | |
1457 } | |
1458 | |
1459 /* | |
1460 * @see dwtx.jface.text.IDocumentExtension#resumePostNotificationProcessing() | |
1461 * @since 2.0 | |
1462 */ | |
1463 public void resumePostNotificationProcessing() { | |
1464 -- fStoppedCount; | |
1465 if (fStoppedCount is 0 && fReentranceCount is 0) | |
1466 executePostNotificationChanges(); | |
1467 } | |
1468 | |
1469 /* | |
1470 * @see dwtx.jface.text.IDocumentExtension#startSequentialRewrite(bool) | |
1471 * @since 2.0 | |
1472 */ | |
1473 public void startSequentialRewrite(bool normalized) { | |
1474 } | |
1475 | |
1476 /* | |
1477 * @see dwtx.jface.text.IDocumentExtension#stopSequentialRewrite() | |
1478 * @since 2.0 | |
1479 */ | |
1480 public void stopSequentialRewrite() { | |
1481 } | |
1482 | |
1483 /* | |
1484 * @see dwtx.jface.text.IDocumentExtension2#resumeListenerNotification() | |
1485 * @since 2.1 | |
1486 */ | |
1487 public void resumeListenerNotification() { | |
1488 -- fStoppedListenerNotification; | |
1489 if (fStoppedListenerNotification is 0) { | |
1490 resumeDocumentListenerNotification(); | |
1491 } | |
1492 } | |
1493 | |
1494 /* | |
1495 * @see dwtx.jface.text.IDocumentExtension2#stopListenerNotification() | |
1496 * @since 2.1 | |
1497 */ | |
1498 public void stopListenerNotification() { | |
1499 ++ fStoppedListenerNotification; | |
1500 } | |
1501 | |
1502 /** | |
1503 * Resumes the document listener notification by sending out the remembered | |
1504 * partition changed and document event. | |
1505 * | |
1506 * @since 2.1 | |
1507 */ | |
1508 private void resumeDocumentListenerNotification() { | |
1509 if (fDeferredDocumentEvent !is null) { | |
1510 DocumentEvent event= fDeferredDocumentEvent; | |
1511 fDeferredDocumentEvent= null; | |
1512 doFireDocumentChanged(event); | |
1513 } | |
1514 } | |
1515 | |
1516 /* | |
1517 * @see dwtx.jface.text.IDocumentExtension3#computeZeroLengthPartitioning(java.lang.String, int, int) | |
1518 * @since 3.0 | |
1519 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1520 public ITypedRegion[] computePartitioning(String partitioning, int offset, int length, bool includeZeroLengthPartitions) { |
129 | 1521 if ((0 > offset) || (0 > length) || (offset + length > getLength())) |
1522 throw new BadLocationException(); | |
1523 | |
1524 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); | |
1525 | |
138 | 1526 if ( cast(IDocumentPartitionerExtension2)partitioner ) { |
129 | 1527 checkStateOfPartitioner(partitioner, partitioning); |
134 | 1528 return (cast(IDocumentPartitionerExtension2) partitioner).computePartitioning(offset, length, includeZeroLengthPartitions); |
129 | 1529 } else if (partitioner !is null) { |
1530 checkStateOfPartitioner(partitioner, partitioning); | |
1531 return partitioner.computePartitioning(offset, length); | |
1532 } else if (DEFAULT_PARTITIONING.equals(partitioning)) | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1533 return [ new TypedRegion(offset, length, DEFAULT_CONTENT_TYPE) ]; |
129 | 1534 else |
1535 throw new BadPartitioningException(); | |
1536 } | |
1537 | |
1538 /* | |
1539 * @see dwtx.jface.text.IDocumentExtension3#getZeroLengthContentType(java.lang.String, int) | |
1540 * @since 3.0 | |
1541 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1542 public String getContentType(String partitioning, int offset, bool preferOpenPartitions) { |
129 | 1543 if ((0 > offset) || (offset > getLength())) |
1544 throw new BadLocationException(); | |
1545 | |
1546 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); | |
1547 | |
138 | 1548 if ( cast(IDocumentPartitionerExtension2)partitioner ) { |
129 | 1549 checkStateOfPartitioner(partitioner, partitioning); |
134 | 1550 return (cast(IDocumentPartitionerExtension2) partitioner).getContentType(offset, preferOpenPartitions); |
129 | 1551 } else if (partitioner !is null) { |
1552 checkStateOfPartitioner(partitioner, partitioning); | |
1553 return partitioner.getContentType(offset); | |
1554 } else if (DEFAULT_PARTITIONING.equals(partitioning)) | |
1555 return DEFAULT_CONTENT_TYPE; | |
1556 else | |
1557 throw new BadPartitioningException(); | |
1558 } | |
1559 | |
1560 /* | |
1561 * @see dwtx.jface.text.IDocumentExtension3#getDocumentPartitioner(java.lang.String) | |
1562 * @since 3.0 | |
1563 */ | |
1564 public IDocumentPartitioner getDocumentPartitioner(String partitioning) { | |
134 | 1565 return fDocumentPartitioners !is null ? cast(IDocumentPartitioner) fDocumentPartitioners.get(partitioning) : null; |
129 | 1566 } |
1567 | |
1568 /* | |
1569 * @see dwtx.jface.text.IDocumentExtension3#getLegalContentTypes(java.lang.String) | |
1570 * @since 3.0 | |
1571 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1572 public String[] getLegalContentTypes(String partitioning) { |
129 | 1573 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); |
1574 if (partitioner !is null) | |
1575 return partitioner.getLegalContentTypes(); | |
1576 if (DEFAULT_PARTITIONING.equals(partitioning)) | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1577 return [ DEFAULT_CONTENT_TYPE ]; |
129 | 1578 throw new BadPartitioningException(); |
1579 } | |
1580 | |
1581 /* | |
1582 * @see dwtx.jface.text.IDocumentExtension3#getZeroLengthPartition(java.lang.String, int) | |
1583 * @since 3.0 | |
1584 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1585 public ITypedRegion getPartition(String partitioning, int offset, bool preferOpenPartitions) { |
129 | 1586 if ((0 > offset) || (offset > getLength())) |
1587 throw new BadLocationException(); | |
1588 | |
1589 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); | |
1590 | |
138 | 1591 if ( cast(IDocumentPartitionerExtension2)partitioner ) { |
129 | 1592 checkStateOfPartitioner(partitioner, partitioning); |
134 | 1593 return (cast(IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions); |
129 | 1594 } else if (partitioner !is null) { |
1595 checkStateOfPartitioner(partitioner, partitioning); | |
1596 return partitioner.getPartition(offset); | |
1597 } else if (DEFAULT_PARTITIONING.equals(partitioning)) | |
1598 return new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE); | |
1599 else | |
1600 throw new BadPartitioningException(); | |
1601 } | |
1602 | |
1603 /* | |
1604 * @see dwtx.jface.text.IDocumentExtension3#getPartitionings() | |
1605 * @since 3.0 | |
1606 */ | |
1607 public String[] getPartitionings() { | |
1608 if (fDocumentPartitioners is null) | |
1609 return new String[0]; | |
1610 String[] partitionings= new String[fDocumentPartitioners.size()]; | |
1611 fDocumentPartitioners.keySet().toArray(partitionings); | |
1612 return partitionings; | |
1613 } | |
1614 | |
1615 /* | |
1616 * @see dwtx.jface.text.IDocumentExtension3#setDocumentPartitioner(java.lang.String, dwtx.jface.text.IDocumentPartitioner) | |
1617 * @since 3.0 | |
1618 */ | |
1619 public void setDocumentPartitioner(String partitioning, IDocumentPartitioner partitioner) { | |
1620 if (partitioner is null) { | |
1621 if (fDocumentPartitioners !is null) { | |
1622 fDocumentPartitioners.remove(partitioning); | |
1623 if (fDocumentPartitioners.size() is 0) | |
1624 fDocumentPartitioners= null; | |
1625 } | |
1626 } else { | |
1627 if (fDocumentPartitioners is null) | |
1628 fDocumentPartitioners= new HashMap(); | |
1629 fDocumentPartitioners.put(partitioning, partitioner); | |
1630 } | |
1631 DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); | |
1632 event.setPartitionChange(partitioning, 0, getLength()); | |
1633 fireDocumentPartitioningChanged(event); | |
1634 } | |
1635 | |
1636 /* | |
1637 * @see dwtx.jface.text.IRepairableDocument#repairLineInformation() | |
1638 * @since 3.0 | |
1639 */ | |
1640 public void repairLineInformation() { | |
1641 getTracker().set(get()); | |
1642 } | |
1643 | |
1644 /** | |
1645 * Fires the given event to all registered rewrite session listeners. Uses robust iterators. | |
1646 * | |
1647 * @param event the event to be fired | |
1648 * @since 3.1 | |
1649 */ | |
1650 protected void fireRewriteSessionChanged(DocumentRewriteSessionEvent event) { | |
1651 if (fDocumentRewriteSessionListeners.size() > 0) { | |
1652 List list= new ArrayList(fDocumentRewriteSessionListeners); | |
1653 Iterator e= list.iterator(); | |
1654 while (e.hasNext()) { | |
134 | 1655 IDocumentRewriteSessionListener l= cast(IDocumentRewriteSessionListener) e.next(); |
129 | 1656 l.documentRewriteSessionChanged(event); |
1657 } | |
1658 } | |
1659 } | |
1660 | |
1661 /* | |
1662 * @see dwtx.jface.text.IDocumentExtension4#getActiveRewriteSession() | |
1663 */ | |
1664 public final DocumentRewriteSession getActiveRewriteSession() { | |
1665 return fDocumentRewriteSession; | |
1666 } | |
1667 | |
1668 /* | |
1669 * @see dwtx.jface.text.IDocumentExtension4#startRewriteSession(dwtx.jface.text.DocumentRewriteSessionType) | |
1670 * @since 3.1 | |
1671 */ | |
1672 public DocumentRewriteSession startRewriteSession(DocumentRewriteSessionType sessionType) { | |
1673 | |
1674 if (getActiveRewriteSession() !is null) | |
1675 throw new IllegalStateException(); | |
1676 | |
1677 | |
1678 fDocumentRewriteSession= new DocumentRewriteSession(sessionType); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1679 if (DEBUG) |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1680 System.out_.println("AbstractDocument: Starting rewrite session: " + fDocumentRewriteSession); //$NON-NLS-1$ |
129 | 1681 |
1682 fireRewriteSessionChanged(new DocumentRewriteSessionEvent(this, fDocumentRewriteSession, DocumentRewriteSessionEvent.SESSION_START)); | |
1683 | |
1684 startRewriteSessionOnPartitioners(fDocumentRewriteSession); | |
1685 | |
1686 ILineTracker tracker= getTracker(); | |
138 | 1687 if ( cast(ILineTrackerExtension)tracker ) { |
134 | 1688 ILineTrackerExtension extension= cast(ILineTrackerExtension) tracker; |
129 | 1689 extension.startRewriteSession(fDocumentRewriteSession); |
1690 } | |
1691 | |
1692 if (DocumentRewriteSessionType.SEQUENTIAL is sessionType) | |
1693 startSequentialRewrite(false); | |
1694 else if (DocumentRewriteSessionType.STRICTLY_SEQUENTIAL is sessionType) | |
1695 startSequentialRewrite(true); | |
1696 | |
1697 return fDocumentRewriteSession; | |
1698 } | |
1699 | |
1700 /** | |
1701 * Starts the given rewrite session. | |
1702 * | |
1703 * @param session the rewrite session | |
1704 * @since 3.1 | |
1705 */ | |
1706 protected final void startRewriteSessionOnPartitioners(DocumentRewriteSession session) { | |
1707 if (fDocumentPartitioners !is null) { | |
1708 Iterator e= fDocumentPartitioners.values().iterator(); | |
1709 while (e.hasNext()) { | |
1710 Object partitioner= e.next(); | |
138 | 1711 if ( cast(IDocumentPartitionerExtension3)partitioner ) { |
134 | 1712 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 1713 extension.startRewriteSession(session); |
1714 } | |
1715 } | |
1716 } | |
1717 } | |
1718 | |
1719 /* | |
1720 * @see dwtx.jface.text.IDocumentExtension4#stopRewriteSession(dwtx.jface.text.DocumentRewriteSession) | |
1721 * @since 3.1 | |
1722 */ | |
1723 public void stopRewriteSession(DocumentRewriteSession session) { | |
1724 if (fDocumentRewriteSession is session) { | |
1725 | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1726 if (DEBUG) |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1727 System.out_.println("AbstractDocument: Stopping rewrite session: " + session); //$NON-NLS-1$ |
129 | 1728 |
1729 DocumentRewriteSessionType sessionType= session.getSessionType(); | |
1730 if (DocumentRewriteSessionType.SEQUENTIAL is sessionType || DocumentRewriteSessionType.STRICTLY_SEQUENTIAL is sessionType) | |
1731 stopSequentialRewrite(); | |
1732 | |
1733 ILineTracker tracker= getTracker(); | |
138 | 1734 if ( cast(ILineTrackerExtension)tracker ) { |
134 | 1735 ILineTrackerExtension extension= cast(ILineTrackerExtension) tracker; |
129 | 1736 extension.stopRewriteSession(session, get()); |
1737 } | |
1738 | |
1739 stopRewriteSessionOnPartitioners(fDocumentRewriteSession); | |
1740 | |
1741 fDocumentRewriteSession= null; | |
1742 fireRewriteSessionChanged(new DocumentRewriteSessionEvent(this, session, DocumentRewriteSessionEvent.SESSION_STOP)); | |
1743 } | |
1744 } | |
1745 | |
1746 /** | |
1747 * Stops the given rewrite session. | |
1748 * | |
1749 * @param session the rewrite session | |
1750 * @since 3.1 | |
1751 */ | |
1752 protected final void stopRewriteSessionOnPartitioners(DocumentRewriteSession session) { | |
1753 if (fDocumentPartitioners !is null) { | |
1754 DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); | |
1755 Iterator e= fDocumentPartitioners.keySet().iterator(); | |
1756 while (e.hasNext()) { | |
134 | 1757 String partitioning= cast(String) e.next(); |
1758 IDocumentPartitioner partitioner= cast(IDocumentPartitioner) fDocumentPartitioners.get(partitioning); | |
138 | 1759 if ( cast(IDocumentPartitionerExtension3)partitioner ) { |
134 | 1760 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 1761 extension.stopRewriteSession(session); |
1762 event.setPartitionChange(partitioning, 0, getLength()); | |
1763 } | |
1764 } | |
1765 if (!event.isEmpty()) | |
1766 fireDocumentPartitioningChanged(event); | |
1767 } | |
1768 } | |
1769 | |
1770 /* | |
1771 * @see dwtx.jface.text.IDocumentExtension4#addDocumentRewriteSessionListener(dwtx.jface.text.IDocumentRewriteSessionListener) | |
1772 * @since 3.1 | |
1773 */ | |
1774 public void addDocumentRewriteSessionListener(IDocumentRewriteSessionListener listener) { | |
1775 Assert.isNotNull(listener); | |
1776 if (! fDocumentRewriteSessionListeners.contains(listener)) | |
1777 fDocumentRewriteSessionListeners.add(listener); | |
1778 } | |
1779 | |
1780 /* | |
1781 * @see dwtx.jface.text.IDocumentExtension4#removeDocumentRewriteSessionListener(dwtx.jface.text.IDocumentRewriteSessionListener) | |
1782 * @since 3.1 | |
1783 */ | |
1784 public void removeDocumentRewriteSessionListener(IDocumentRewriteSessionListener listener) { | |
1785 Assert.isNotNull(listener); | |
1786 fDocumentRewriteSessionListeners.remove(listener); | |
1787 } | |
1788 | |
1789 /** | |
1790 * Checks the state for the given partitioner and stops the | |
1791 * active rewrite session. | |
1792 * | |
1793 * @param partitioner the document partitioner to be checked | |
1794 * @param partitioning the document partitioning the partitioner is registered for | |
1795 * @since 3.1 | |
1796 */ | |
1797 protected final void checkStateOfPartitioner(IDocumentPartitioner partitioner, String partitioning) { | |
138 | 1798 if (!( cast(IDocumentPartitionerExtension3)partitioner )) |
129 | 1799 return; |
1800 | |
134 | 1801 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 1802 DocumentRewriteSession session= extension.getActiveRewriteSession(); |
1803 if (session !is null) { | |
1804 extension.stopRewriteSession(session); | |
1805 | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1806 if (DEBUG) |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1807 System.out_.println("AbstractDocument: Flushing rewrite session for partition type: " + partitioning); //$NON-NLS-1$ |
129 | 1808 |
1809 DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); | |
1810 event.setPartitionChange(partitioning, 0, getLength()); | |
1811 fireDocumentPartitioningChanged(event); | |
1812 } | |
1813 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1814 |
129 | 1815 /** |
1816 * Returns all positions of the given category that are inside the given region. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1817 * |
129 | 1818 * @param category the position category |
1819 * @param offset the start position of the region, must be >= 0 | |
1820 * @param length the length of the region, must be >= 0 | |
1821 * @param canStartBefore if <code>true</code> then positions are included | |
1822 * which start before the region if they end at or after the regions start | |
1823 * @param canEndAfter if <code>true</code> then positions are included | |
1824 * which end after the region if they start at or before the regions end | |
1825 * @return all positions inside the region of the given category | |
1826 * @throws BadPositionCategoryException if category is undefined in this document | |
1827 * @since 3.4 | |
1828 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1829 public Position[] getPositions(String category, int offset, int length, bool canStartBefore, bool canEndAfter) { |
129 | 1830 if (canStartBefore && canEndAfter || (!canStartBefore && !canEndAfter)) { |
1831 List documentPositions; | |
1832 if (canStartBefore && canEndAfter) { | |
1833 if (offset < getLength() / 2) { | |
1834 documentPositions= getStartingPositions(category, 0, offset + length); | |
1835 } else { | |
1836 documentPositions= getEndingPositions(category, offset, getLength() - offset + 1); | |
1837 } | |
1838 } else { | |
1839 documentPositions= getStartingPositions(category, offset, length); | |
1840 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1841 |
129 | 1842 ArrayList list= new ArrayList(documentPositions.size()); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1843 |
129 | 1844 Position region= new Position(offset, length); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1845 |
129 | 1846 for (Iterator iterator= documentPositions.iterator(); iterator.hasNext();) { |
134 | 1847 Position position= cast(Position) iterator.next(); |
129 | 1848 if (isWithinRegion(region, position, canStartBefore, canEndAfter)) { |
1849 list.add(position); | |
1850 } | |
1851 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1852 |
129 | 1853 Position[] positions= new Position[list.size()]; |
1854 list.toArray(positions); | |
1855 return positions; | |
1856 } else if (canStartBefore) { | |
1857 List list= getEndingPositions(category, offset, length); | |
1858 Position[] positions= new Position[list.size()]; | |
1859 list.toArray(positions); | |
1860 return positions; | |
1861 } else { | |
1862 Assert.isLegal(canEndAfter && !canStartBefore); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1863 |
129 | 1864 List list= getStartingPositions(category, offset, length); |
1865 Position[] positions= new Position[list.size()]; | |
1866 list.toArray(positions); | |
1867 return positions; | |
1868 } | |
1869 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1870 |
129 | 1871 /* |
1872 * @since 3.4 | |
1873 */ | |
1874 private bool isWithinRegion(Position region, Position position, bool canStartBefore, bool canEndAfter) { | |
1875 if (canStartBefore && canEndAfter) { | |
1876 return region.overlapsWith(position.getOffset(), position.getLength()); | |
1877 } else if (canStartBefore) { | |
1878 return region.includes(position.getOffset() + position.getLength() - 1); | |
1879 } else if (canEndAfter) { | |
1880 return region.includes(position.getOffset()); | |
1881 } else { | |
1882 int start= position.getOffset(); | |
1883 return region.includes(start) && region.includes(start + position.getLength() - 1); | |
1884 } | |
1885 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1886 |
129 | 1887 /** |
1888 * A list of positions in the given category with an offset inside the given | |
1889 * region. The order of the positions is arbitrary. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1890 * |
129 | 1891 * @param category the position category |
1892 * @param offset the offset of the region | |
1893 * @param length the length of the region | |
1894 * @return a list of the positions in the region | |
1895 * @throws BadPositionCategoryException if category is undefined in this document | |
1896 * @since 3.4 | |
1897 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1898 private List getStartingPositions(String category, int offset, int length) { |
134 | 1899 List positions= cast(List) fPositions.get(category); |
129 | 1900 if (positions is null) |
1901 throw new BadPositionCategoryException(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1902 |
129 | 1903 int indexStart= computeIndexInPositionList(positions, offset, true); |
1904 int indexEnd= computeIndexInPositionList(positions, offset + length, true); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1905 |
129 | 1906 return positions.subList(indexStart, indexEnd); |
1907 } | |
1908 | |
1909 /** | |
1910 * A list of positions in the given category with an end position inside | |
1911 * the given region. The order of the positions is arbitrary. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1912 * |
129 | 1913 * @param category the position category |
1914 * @param offset the offset of the region | |
1915 * @param length the length of the region | |
1916 * @return a list of the positions in the region | |
1917 * @throws BadPositionCategoryException if category is undefined in this document | |
1918 * @since 3.4 | |
1919 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1920 private List getEndingPositions(String category, int offset, int length) { |
134 | 1921 List positions= cast(List) fEndPositions.get(category); |
129 | 1922 if (positions is null) |
1923 throw new BadPositionCategoryException(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1924 |
129 | 1925 int indexStart= computeIndexInPositionList(positions, offset, false); |
1926 int indexEnd= computeIndexInPositionList(positions, offset + length, false); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1927 |
129 | 1928 return positions.subList(indexStart, indexEnd); |
1929 } | |
1930 | |
1931 | |
1932 } |