Mercurial > projects > dwt-addons
annotate dwtx/jface/text/Assert.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 000f9136b8f7 |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.Assert; | |
14 | |
131 | 15 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport |
16 import dwtx.jface.text.DefaultTextHover; // packageimport | |
17 import dwtx.jface.text.AbstractInformationControl; // packageimport | |
18 import dwtx.jface.text.TextUtilities; // packageimport | |
19 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport | |
20 import dwtx.jface.text.AbstractInformationControlManager; // packageimport | |
21 import dwtx.jface.text.ITextViewerExtension2; // packageimport | |
22 import dwtx.jface.text.IDocumentPartitioner; // packageimport | |
23 import dwtx.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport | |
24 import dwtx.jface.text.ITextSelection; // packageimport | |
25 import dwtx.jface.text.Document; // packageimport | |
26 import dwtx.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // packageimport | |
27 import dwtx.jface.text.ITextListener; // packageimport | |
28 import dwtx.jface.text.BadPartitioningException; // packageimport | |
29 import dwtx.jface.text.ITextViewerExtension5; // packageimport | |
30 import dwtx.jface.text.IDocumentPartitionerExtension3; // packageimport | |
31 import dwtx.jface.text.IUndoManager; // packageimport | |
32 import dwtx.jface.text.ITextHoverExtension2; // packageimport | |
33 import dwtx.jface.text.IRepairableDocument; // packageimport | |
34 import dwtx.jface.text.IRewriteTarget; // packageimport | |
35 import dwtx.jface.text.DefaultPositionUpdater; // packageimport | |
36 import dwtx.jface.text.RewriteSessionEditProcessor; // packageimport | |
37 import dwtx.jface.text.TextViewerHoverManager; // packageimport | |
38 import dwtx.jface.text.DocumentRewriteSession; // packageimport | |
39 import dwtx.jface.text.TextViewer; // packageimport | |
40 import dwtx.jface.text.ITextViewerExtension8; // packageimport | |
41 import dwtx.jface.text.RegExMessages; // packageimport | |
42 import dwtx.jface.text.IDelayedInputChangeProvider; // packageimport | |
43 import dwtx.jface.text.ITextOperationTargetExtension; // packageimport | |
44 import dwtx.jface.text.IWidgetTokenOwner; // packageimport | |
45 import dwtx.jface.text.IViewportListener; // packageimport | |
46 import dwtx.jface.text.GapTextStore; // packageimport | |
47 import dwtx.jface.text.MarkSelection; // packageimport | |
48 import dwtx.jface.text.IDocumentPartitioningListenerExtension; // packageimport | |
49 import dwtx.jface.text.IDocumentAdapterExtension; // packageimport | |
50 import dwtx.jface.text.IInformationControlExtension; // packageimport | |
51 import dwtx.jface.text.IDocumentPartitioningListenerExtension2; // packageimport | |
52 import dwtx.jface.text.DefaultDocumentAdapter; // packageimport | |
53 import dwtx.jface.text.ITextViewerExtension3; // packageimport | |
54 import dwtx.jface.text.IInformationControlCreator; // packageimport | |
55 import dwtx.jface.text.TypedRegion; // packageimport | |
56 import dwtx.jface.text.ISynchronizable; // packageimport | |
57 import dwtx.jface.text.IMarkRegionTarget; // packageimport | |
58 import dwtx.jface.text.TextViewerUndoManager; // packageimport | |
59 import dwtx.jface.text.IRegion; // packageimport | |
60 import dwtx.jface.text.IInformationControlExtension2; // packageimport | |
61 import dwtx.jface.text.IDocumentExtension4; // packageimport | |
62 import dwtx.jface.text.IDocumentExtension2; // packageimport | |
63 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport | |
64 import dwtx.jface.text.DefaultInformationControl; // packageimport | |
65 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport | |
66 import dwtx.jface.text.DocumentClone; // packageimport | |
67 import dwtx.jface.text.DefaultUndoManager; // packageimport | |
68 import dwtx.jface.text.IFindReplaceTarget; // packageimport | |
69 import dwtx.jface.text.IAutoEditStrategy; // packageimport | |
70 import dwtx.jface.text.ILineTrackerExtension; // packageimport | |
71 import dwtx.jface.text.IUndoManagerExtension; // packageimport | |
72 import dwtx.jface.text.TextSelection; // packageimport | |
73 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport | |
74 import dwtx.jface.text.IAutoIndentStrategy; // packageimport | |
75 import dwtx.jface.text.IPainter; // packageimport | |
76 import dwtx.jface.text.IInformationControl; // packageimport | |
77 import dwtx.jface.text.IInformationControlExtension3; // packageimport | |
78 import dwtx.jface.text.ITextViewerExtension6; // packageimport | |
79 import dwtx.jface.text.IInformationControlExtension4; // packageimport | |
80 import dwtx.jface.text.DefaultLineTracker; // packageimport | |
81 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport | |
82 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport | |
83 import dwtx.jface.text.ITextHover; // packageimport | |
84 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport | |
85 import dwtx.jface.text.ILineTracker; // packageimport | |
86 import dwtx.jface.text.Line; // packageimport | |
87 import dwtx.jface.text.ITextViewerExtension; // packageimport | |
88 import dwtx.jface.text.IDocumentAdapter; // packageimport | |
89 import dwtx.jface.text.TextEvent; // packageimport | |
90 import dwtx.jface.text.BadLocationException; // packageimport | |
91 import dwtx.jface.text.AbstractDocument; // packageimport | |
92 import dwtx.jface.text.AbstractLineTracker; // packageimport | |
93 import dwtx.jface.text.TreeLineTracker; // packageimport | |
94 import dwtx.jface.text.ITextPresentationListener; // packageimport | |
95 import dwtx.jface.text.Region; // packageimport | |
96 import dwtx.jface.text.ITextViewer; // packageimport | |
97 import dwtx.jface.text.IDocumentInformationMapping; // packageimport | |
98 import dwtx.jface.text.MarginPainter; // packageimport | |
99 import dwtx.jface.text.IPaintPositionManager; // packageimport | |
100 import dwtx.jface.text.TextPresentation; // packageimport | |
101 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport | |
102 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport | |
103 import dwtx.jface.text.ISelectionValidator; // packageimport | |
104 import dwtx.jface.text.IDocumentExtension; // packageimport | |
105 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport | |
106 import dwtx.jface.text.ConfigurableLineTracker; // packageimport | |
107 import dwtx.jface.text.SlaveDocumentEvent; // packageimport | |
108 import dwtx.jface.text.IDocumentListener; // packageimport | |
109 import dwtx.jface.text.PaintManager; // packageimport | |
110 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport | |
111 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport | |
112 import dwtx.jface.text.IDocumentExtension3; // packageimport | |
113 import dwtx.jface.text.Position; // packageimport | |
114 import dwtx.jface.text.TextMessages; // packageimport | |
115 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport | |
116 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport | |
117 import dwtx.jface.text.IPositionUpdater; // packageimport | |
118 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport | |
119 import dwtx.jface.text.ListLineTracker; // packageimport | |
120 import dwtx.jface.text.ITextInputListener; // packageimport | |
121 import dwtx.jface.text.BadPositionCategoryException; // packageimport | |
122 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport | |
123 import dwtx.jface.text.IInputChangedListener; // packageimport | |
124 import dwtx.jface.text.ITextOperationTarget; // packageimport | |
125 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport | |
126 import dwtx.jface.text.ITextViewerExtension7; // packageimport | |
127 import dwtx.jface.text.IInformationControlExtension5; // packageimport | |
128 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport | |
129 import dwtx.jface.text.JFaceTextUtil; // packageimport | |
130 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport | |
131 import dwtx.jface.text.TabsToSpacesConverter; // packageimport | |
132 import dwtx.jface.text.CursorLinePainter; // packageimport | |
133 import dwtx.jface.text.ITextHoverExtension; // packageimport | |
134 import dwtx.jface.text.IEventConsumer; // packageimport | |
135 import dwtx.jface.text.IDocument; // packageimport | |
136 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport | |
137 import dwtx.jface.text.DocumentCommand; // packageimport | |
138 import dwtx.jface.text.TypedPosition; // packageimport | |
139 import dwtx.jface.text.IEditingSupportRegistry; // packageimport | |
140 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport | |
141 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport | |
142 import dwtx.jface.text.IEditingSupport; // packageimport | |
143 import dwtx.jface.text.IMarkSelection; // packageimport | |
144 import dwtx.jface.text.ISlaveDocumentManager; // packageimport | |
145 import dwtx.jface.text.DocumentEvent; // packageimport | |
146 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport | |
147 import dwtx.jface.text.ITextStore; // packageimport | |
148 import dwtx.jface.text.JFaceTextMessages; // packageimport | |
149 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport | |
150 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport | |
151 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | |
152 import dwtx.jface.text.TextAttribute; // packageimport | |
153 import dwtx.jface.text.ITextViewerExtension4; // packageimport | |
154 import dwtx.jface.text.ITypedRegion; // packageimport | |
155 | |
156 | |
129 | 157 import dwt.dwthelper.utils; |
158 | |
159 | |
160 /** | |
161 * <code>Assert</code> is useful for for embedding runtime sanity checks | |
162 * in code. The static predicate methods all test a condition and throw some | |
163 * type of unchecked exception if the condition does not hold. | |
164 * <p> | |
165 * Assertion failure exceptions, like most runtime exceptions, are | |
166 * thrown when something is misbehaving. Assertion failures are invariably | |
167 * unspecified behavior; consequently, clients should never rely on | |
168 * these being thrown (or not thrown). <b>If you find yourself in the | |
169 * position where you need to catch an assertion failure, you have most | |
170 * certainly written your program incorrectly.</b> | |
171 * </p> | |
172 * <p> | |
173 * Note that an <code>assert</code> statement is slated to be added to the | |
174 * Java language in JDK 1.4, rending this class obsolete. | |
175 * </p> | |
162 | 176 * |
129 | 177 * @deprecated As of 3.3, replaced by {@link dwtx.core.runtime.Assert} |
178 * @noinstantiate This class is not intended to be instantiated by clients. | |
179 */ | |
180 public final class Assert { | |
181 | |
182 /** | |
183 * <code>AssertionFailedException</code> is a runtime exception thrown | |
184 * by some of the methods in <code>Assert</code>. | |
185 * <p> | |
186 * This class is not declared public to prevent some misuses; programs that catch | |
187 * or otherwise depend on assertion failures are susceptible to unexpected | |
188 * breakage when assertions in the code are added or removed. | |
189 * </p> | |
190 * <p> | |
191 * This class is not intended to be serialized. | |
192 * </p> | |
193 */ | |
194 private static class AssertionFailedException : RuntimeException { | |
195 | |
196 /** | |
197 * Serial version UID for this class. | |
198 * <p> | |
199 * Note: This class is not intended to be serialized. | |
200 * </p> | |
201 * @since 3.1 | |
202 */ | |
147 | 203 private static const long serialVersionUID= 3689918374733886002L; |
129 | 204 |
205 /** | |
206 * Constructs a new exception. | |
207 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
208 public this() { |
129 | 209 } |
210 | |
211 /** | |
212 * Constructs a new exception with the given message. | |
213 * | |
214 * @param detail the detailed message | |
215 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
216 public this(String detail) { |
129 | 217 super(detail); |
218 } | |
219 } | |
220 | |
221 /* This class is not intended to be instantiated. */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
222 private this() { |
129 | 223 } |
224 | |
225 /** | |
226 * Asserts that an argument is legal. If the given bool is | |
227 * not <code>true</code>, an <code>IllegalArgumentException</code> | |
228 * is thrown. | |
229 * | |
230 * @param expression the outcome of the check | |
231 * @return <code>true</code> if the check passes (does not return | |
232 * if the check fails) | |
233 * @exception IllegalArgumentException if the legality test failed | |
234 */ | |
235 public static bool isLegal(bool expression) { | |
236 // succeed as quickly as possible | |
237 if (expression) { | |
238 return true; | |
239 } | |
240 return isLegal(expression, "");//$NON-NLS-1$ | |
241 } | |
242 | |
243 /** | |
244 * Asserts that an argument is legal. If the given bool is | |
245 * not <code>true</code>, an <code>IllegalArgumentException</code> | |
246 * is thrown. | |
247 * The given message is included in that exception, to aid debugging. | |
248 * | |
249 * @param expression the outcome of the check | |
250 * @param message the message to include in the exception | |
251 * @return <code>true</code> if the check passes (does not return | |
252 * if the check fails) | |
253 * @exception IllegalArgumentException if the legality test failed | |
254 */ | |
255 public static bool isLegal(bool expression, String message) { | |
256 if (!expression) | |
162 | 257 throw new IllegalArgumentException("assertion failed; " ~ message); //$NON-NLS-1$ |
129 | 258 return expression; |
259 } | |
260 | |
261 /** | |
262 * Asserts that the given object is not <code>null</code>. If this | |
263 * is not the case, some kind of unchecked exception is thrown. | |
264 * <p> | |
265 * As a general rule, parameters passed to API methods must not be | |
266 * <code>null</code> unless <b>explicitly</b> allowed in the method's | |
267 * specification. Similarly, results returned from API methods are never | |
268 * <code>null</code> unless <b>explicitly</b> allowed in the method's | |
269 * specification. Implementations are encouraged to make regular use of | |
270 * <code>Assert.isNotNull</code> to ensure that <code>null</code> | |
271 * parameters are detected as early as possible. | |
272 * </p> | |
273 * | |
274 * @param object the value to test | |
275 * @exception RuntimeException an unspecified unchecked exception if the object | |
276 * is <code>null</code> | |
277 */ | |
278 public static void isNotNull(Object object) { | |
279 // succeed as quickly as possible | |
280 if (object !is null) { | |
281 return; | |
282 } | |
283 isNotNull(object, "");//$NON-NLS-1$ | |
284 } | |
285 | |
286 /** | |
287 * Asserts that the given object is not <code>null</code>. If this | |
288 * is not the case, some kind of unchecked exception is thrown. | |
289 * The given message is included in that exception, to aid debugging. | |
290 * <p> | |
291 * As a general rule, parameters passed to API methods must not be | |
292 * <code>null</code> unless <b>explicitly</b> allowed in the method's | |
293 * specification. Similarly, results returned from API methods are never | |
294 * <code>null</code> unless <b>explicitly</b> allowed in the method's | |
295 * specification. Implementations are encouraged to make regular use of | |
296 * <code>Assert.isNotNull</code> to ensure that <code>null</code> | |
297 * parameters are detected as early as possible. | |
298 * </p> | |
299 * | |
300 * @param object the value to test | |
301 * @param message the message to include in the exception | |
302 * @exception RuntimeException an unspecified unchecked exception if the object | |
303 * is <code>null</code> | |
304 */ | |
305 public static void isNotNull(Object object, String message) { | |
306 if (object is null) | |
162 | 307 throw new AssertionFailedException("null argument;" ~ message);//$NON-NLS-1$ |
129 | 308 } |
309 | |
310 /** | |
311 * Asserts that the given bool is <code>true</code>. If this | |
312 * is not the case, some kind of unchecked exception is thrown. | |
313 * | |
314 * @param expression the outcome of the check | |
315 * @return <code>true</code> if the check passes (does not return | |
316 * if the check fails) | |
317 */ | |
318 public static bool isTrue(bool expression) { | |
319 // succeed as quickly as possible | |
320 if (expression) { | |
321 return true; | |
322 } | |
323 return isTrue(expression, "");//$NON-NLS-1$ | |
324 } | |
325 | |
326 /** | |
327 * Asserts that the given bool is <code>true</code>. If this | |
328 * is not the case, some kind of unchecked exception is thrown. | |
329 * The given message is included in that exception, to aid debugging. | |
330 * | |
331 * @param expression the outcome of the check | |
332 * @param message the message to include in the exception | |
333 * @return <code>true</code> if the check passes (does not return | |
334 * if the check fails) | |
335 */ | |
336 public static bool isTrue(bool expression, String message) { | |
337 if (!expression) | |
162 | 338 throw new AssertionFailedException("Assertion failed: "~message);//$NON-NLS-1$ |
129 | 339 return expression; |
340 } | |
341 } |