comparison org.eclipse.text/src/org/eclipse/jface/text/Assert.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children 5feec68b4556
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 org.eclipse.jface.text.Assert;
14
15 import org.eclipse.jface.text.IDocumentPartitioningListener; // packageimport
16 import org.eclipse.jface.text.DefaultTextHover; // packageimport
17 import org.eclipse.jface.text.AbstractInformationControl; // packageimport
18 import org.eclipse.jface.text.TextUtilities; // packageimport
19 import org.eclipse.jface.text.IInformationControlCreatorExtension; // packageimport
20 import org.eclipse.jface.text.AbstractInformationControlManager; // packageimport
21 import org.eclipse.jface.text.ITextViewerExtension2; // packageimport
22 import org.eclipse.jface.text.IDocumentPartitioner; // packageimport
23 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport
24 import org.eclipse.jface.text.ITextSelection; // packageimport
25 import org.eclipse.jface.text.Document; // packageimport
26 import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // packageimport
27 import org.eclipse.jface.text.ITextListener; // packageimport
28 import org.eclipse.jface.text.BadPartitioningException; // packageimport
29 import org.eclipse.jface.text.ITextViewerExtension5; // packageimport
30 import org.eclipse.jface.text.IDocumentPartitionerExtension3; // packageimport
31 import org.eclipse.jface.text.IUndoManager; // packageimport
32 import org.eclipse.jface.text.ITextHoverExtension2; // packageimport
33 import org.eclipse.jface.text.IRepairableDocument; // packageimport
34 import org.eclipse.jface.text.IRewriteTarget; // packageimport
35 import org.eclipse.jface.text.DefaultPositionUpdater; // packageimport
36 import org.eclipse.jface.text.RewriteSessionEditProcessor; // packageimport
37 import org.eclipse.jface.text.TextViewerHoverManager; // packageimport
38 import org.eclipse.jface.text.DocumentRewriteSession; // packageimport
39 import org.eclipse.jface.text.TextViewer; // packageimport
40 import org.eclipse.jface.text.ITextViewerExtension8; // packageimport
41 import org.eclipse.jface.text.RegExMessages; // packageimport
42 import org.eclipse.jface.text.IDelayedInputChangeProvider; // packageimport
43 import org.eclipse.jface.text.ITextOperationTargetExtension; // packageimport
44 import org.eclipse.jface.text.IWidgetTokenOwner; // packageimport
45 import org.eclipse.jface.text.IViewportListener; // packageimport
46 import org.eclipse.jface.text.GapTextStore; // packageimport
47 import org.eclipse.jface.text.MarkSelection; // packageimport
48 import org.eclipse.jface.text.IDocumentPartitioningListenerExtension; // packageimport
49 import org.eclipse.jface.text.IDocumentAdapterExtension; // packageimport
50 import org.eclipse.jface.text.IInformationControlExtension; // packageimport
51 import org.eclipse.jface.text.IDocumentPartitioningListenerExtension2; // packageimport
52 import org.eclipse.jface.text.DefaultDocumentAdapter; // packageimport
53 import org.eclipse.jface.text.ITextViewerExtension3; // packageimport
54 import org.eclipse.jface.text.IInformationControlCreator; // packageimport
55 import org.eclipse.jface.text.TypedRegion; // packageimport
56 import org.eclipse.jface.text.ISynchronizable; // packageimport
57 import org.eclipse.jface.text.IMarkRegionTarget; // packageimport
58 import org.eclipse.jface.text.TextViewerUndoManager; // packageimport
59 import org.eclipse.jface.text.IRegion; // packageimport
60 import org.eclipse.jface.text.IInformationControlExtension2; // packageimport
61 import org.eclipse.jface.text.IDocumentExtension4; // packageimport
62 import org.eclipse.jface.text.IDocumentExtension2; // packageimport
63 import org.eclipse.jface.text.IDocumentPartitionerExtension2; // packageimport
64 import org.eclipse.jface.text.DefaultInformationControl; // packageimport
65 import org.eclipse.jface.text.IWidgetTokenOwnerExtension; // packageimport
66 import org.eclipse.jface.text.DocumentClone; // packageimport
67 import org.eclipse.jface.text.DefaultUndoManager; // packageimport
68 import org.eclipse.jface.text.IFindReplaceTarget; // packageimport
69 import org.eclipse.jface.text.IAutoEditStrategy; // packageimport
70 import org.eclipse.jface.text.ILineTrackerExtension; // packageimport
71 import org.eclipse.jface.text.IUndoManagerExtension; // packageimport
72 import org.eclipse.jface.text.TextSelection; // packageimport
73 import org.eclipse.jface.text.DefaultAutoIndentStrategy; // packageimport
74 import org.eclipse.jface.text.IAutoIndentStrategy; // packageimport
75 import org.eclipse.jface.text.IPainter; // packageimport
76 import org.eclipse.jface.text.IInformationControl; // packageimport
77 import org.eclipse.jface.text.IInformationControlExtension3; // packageimport
78 import org.eclipse.jface.text.ITextViewerExtension6; // packageimport
79 import org.eclipse.jface.text.IInformationControlExtension4; // packageimport
80 import org.eclipse.jface.text.DefaultLineTracker; // packageimport
81 import org.eclipse.jface.text.IDocumentInformationMappingExtension; // packageimport
82 import org.eclipse.jface.text.IRepairableDocumentExtension; // packageimport
83 import org.eclipse.jface.text.ITextHover; // packageimport
84 import org.eclipse.jface.text.FindReplaceDocumentAdapter; // packageimport
85 import org.eclipse.jface.text.ILineTracker; // packageimport
86 import org.eclipse.jface.text.Line; // packageimport
87 import org.eclipse.jface.text.ITextViewerExtension; // packageimport
88 import org.eclipse.jface.text.IDocumentAdapter; // packageimport
89 import org.eclipse.jface.text.TextEvent; // packageimport
90 import org.eclipse.jface.text.BadLocationException; // packageimport
91 import org.eclipse.jface.text.AbstractDocument; // packageimport
92 import org.eclipse.jface.text.AbstractLineTracker; // packageimport
93 import org.eclipse.jface.text.TreeLineTracker; // packageimport
94 import org.eclipse.jface.text.ITextPresentationListener; // packageimport
95 import org.eclipse.jface.text.Region; // packageimport
96 import org.eclipse.jface.text.ITextViewer; // packageimport
97 import org.eclipse.jface.text.IDocumentInformationMapping; // packageimport
98 import org.eclipse.jface.text.MarginPainter; // packageimport
99 import org.eclipse.jface.text.IPaintPositionManager; // packageimport
100 import org.eclipse.jface.text.TextPresentation; // packageimport
101 import org.eclipse.jface.text.IFindReplaceTargetExtension; // packageimport
102 import org.eclipse.jface.text.ISlaveDocumentManagerExtension; // packageimport
103 import org.eclipse.jface.text.ISelectionValidator; // packageimport
104 import org.eclipse.jface.text.IDocumentExtension; // packageimport
105 import org.eclipse.jface.text.PropagatingFontFieldEditor; // packageimport
106 import org.eclipse.jface.text.ConfigurableLineTracker; // packageimport
107 import org.eclipse.jface.text.SlaveDocumentEvent; // packageimport
108 import org.eclipse.jface.text.IDocumentListener; // packageimport
109 import org.eclipse.jface.text.PaintManager; // packageimport
110 import org.eclipse.jface.text.IFindReplaceTargetExtension3; // packageimport
111 import org.eclipse.jface.text.ITextDoubleClickStrategy; // packageimport
112 import org.eclipse.jface.text.IDocumentExtension3; // packageimport
113 import org.eclipse.jface.text.Position; // packageimport
114 import org.eclipse.jface.text.TextMessages; // packageimport
115 import org.eclipse.jface.text.CopyOnWriteTextStore; // packageimport
116 import org.eclipse.jface.text.WhitespaceCharacterPainter; // packageimport
117 import org.eclipse.jface.text.IPositionUpdater; // packageimport
118 import org.eclipse.jface.text.DefaultTextDoubleClickStrategy; // packageimport
119 import org.eclipse.jface.text.ListLineTracker; // packageimport
120 import org.eclipse.jface.text.ITextInputListener; // packageimport
121 import org.eclipse.jface.text.BadPositionCategoryException; // packageimport
122 import org.eclipse.jface.text.IWidgetTokenKeeperExtension; // packageimport
123 import org.eclipse.jface.text.IInputChangedListener; // packageimport
124 import org.eclipse.jface.text.ITextOperationTarget; // packageimport
125 import org.eclipse.jface.text.IDocumentInformationMappingExtension2; // packageimport
126 import org.eclipse.jface.text.ITextViewerExtension7; // packageimport
127 import org.eclipse.jface.text.IInformationControlExtension5; // packageimport
128 import org.eclipse.jface.text.IDocumentRewriteSessionListener; // packageimport
129 import org.eclipse.jface.text.JFaceTextUtil; // packageimport
130 import org.eclipse.jface.text.AbstractReusableInformationControlCreator; // packageimport
131 import org.eclipse.jface.text.TabsToSpacesConverter; // packageimport
132 import org.eclipse.jface.text.CursorLinePainter; // packageimport
133 import org.eclipse.jface.text.ITextHoverExtension; // packageimport
134 import org.eclipse.jface.text.IEventConsumer; // packageimport
135 import org.eclipse.jface.text.IDocument; // packageimport
136 import org.eclipse.jface.text.IWidgetTokenKeeper; // packageimport
137 import org.eclipse.jface.text.DocumentCommand; // packageimport
138 import org.eclipse.jface.text.TypedPosition; // packageimport
139 import org.eclipse.jface.text.IEditingSupportRegistry; // packageimport
140 import org.eclipse.jface.text.IDocumentPartitionerExtension; // packageimport
141 import org.eclipse.jface.text.AbstractHoverInformationControlManager; // packageimport
142 import org.eclipse.jface.text.IEditingSupport; // packageimport
143 import org.eclipse.jface.text.IMarkSelection; // packageimport
144 import org.eclipse.jface.text.ISlaveDocumentManager; // packageimport
145 import org.eclipse.jface.text.DocumentEvent; // packageimport
146 import org.eclipse.jface.text.DocumentPartitioningChangedEvent; // packageimport
147 import org.eclipse.jface.text.ITextStore; // packageimport
148 import org.eclipse.jface.text.JFaceTextMessages; // packageimport
149 import org.eclipse.jface.text.DocumentRewriteSessionEvent; // packageimport
150 import org.eclipse.jface.text.SequentialRewriteTextStore; // packageimport
151 import org.eclipse.jface.text.DocumentRewriteSessionType; // packageimport
152 import org.eclipse.jface.text.TextAttribute; // packageimport
153 import org.eclipse.jface.text.ITextViewerExtension4; // packageimport
154 import org.eclipse.jface.text.ITypedRegion; // packageimport
155
156
157 import java.lang.all;
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>
176 *
177 * @deprecated As of 3.3, replaced by {@link org.eclipse.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 */
203 private static const long serialVersionUID= 3689918374733886002L;
204
205 /**
206 * Constructs a new exception.
207 */
208 public this() {
209 }
210
211 /**
212 * Constructs a new exception with the given message.
213 *
214 * @param detail the detailed message
215 */
216 public this(String detail) {
217 super(detail);
218 }
219 }
220
221 /* This class is not intended to be instantiated. */
222 private this() {
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)
257 throw new IllegalArgumentException("assertion failed; " ~ message); //$NON-NLS-1$
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)
307 throw new AssertionFailedException("null argument;" ~ message);//$NON-NLS-1$
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)
338 throw new AssertionFailedException("Assertion failed: "~message);//$NON-NLS-1$
339 return expression;
340 }
341 }