Mercurial > projects > dwt2
comparison org.eclipse.equinox.common/src/org/eclipse/core/runtime/Assert.d @ 105:bbe49769ec18
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 08 Nov 2009 12:42:30 +0100 |
parents | 12b890a6392a |
children |
comparison
equal
deleted
inserted
replaced
104:88652073d1c2 | 105:bbe49769ec18 |
---|---|
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | 10 *******************************************************************************/ |
13 module org.eclipse.core.runtime.Assert; | 11 // Port to the D programming language: |
14 | 12 // Frank Benoit <benoit@tionex.de> |
15 import org.eclipse.core.runtime.AssertionFailedException; | 13 module org.eclipse.core.runtimeAssert; |
16 | 14 |
17 import java.lang.all; | 15 import java.lang.all; |
16 | |
17 import org.eclipse.core.runtimeAssertionFailedException; // packageimport | |
18 | 18 |
19 /** | 19 /** |
20 * <code>Assert</code> is useful for for embedding runtime sanity checks | 20 * <code>Assert</code> is useful for for embedding runtime sanity checks |
21 * in code. The predicate methods all test a condition and throw some | 21 * in code. The predicate methods all test a condition and throw some |
22 * type of unchecked exception if the condition does not hold. | 22 * type of unchecked exception if the condition does not hold. |
71 return expression; | 71 return expression; |
72 } | 72 } |
73 | 73 |
74 /** Asserts that the given object is not <code>null</code>. If this | 74 /** Asserts that the given object is not <code>null</code>. If this |
75 * is not the case, some kind of unchecked exception is thrown. | 75 * is not the case, some kind of unchecked exception is thrown. |
76 * | 76 * |
77 * @param object the value to test | 77 * @param object the value to test |
78 */ | 78 */ |
79 public static void isNotNull(Object object) { | 79 public static void isNotNull(Object object) { |
80 isNotNull(object, ""); //$NON-NLS-1$ | 80 isNotNull(object, ""); //$NON-NLS-1$ |
81 } | |
82 public static void isNotNull(String str) { | |
83 isTrue(str.ptr !is null); //$NON-NLS-1$ | |
84 } | |
85 public static void isNotNull(void* ptr) { | |
86 isTrue(ptr !is null); //$NON-NLS-1$ | |
87 } | 81 } |
88 | 82 |
89 /** Asserts that the given object is not <code>null</code>. If this | 83 /** Asserts that the given object is not <code>null</code>. If this |
90 * is not the case, some kind of unchecked exception is thrown. | 84 * is not the case, some kind of unchecked exception is thrown. |
91 * The given message is included in that exception, to aid debugging. | 85 * The given message is included in that exception, to aid debugging. |
93 * @param object the value to test | 87 * @param object the value to test |
94 * @param message the message to include in the exception | 88 * @param message the message to include in the exception |
95 */ | 89 */ |
96 public static void isNotNull(Object object, String message) { | 90 public static void isNotNull(Object object, String message) { |
97 if (object is null) | 91 if (object is null) |
98 throw new AssertionFailedException("null argument:" ~ message); //$NON-NLS-1$ | 92 throw new AssertionFailedException("null argument:" + message); //$NON-NLS-1$ |
99 } | |
100 public static void isNotNull(String str, String message) { | |
101 isTrue(str.ptr !is null, message ); //$NON-NLS-1$ | |
102 } | |
103 public static void isNotNull(void* ptr, String message) { | |
104 isTrue(ptr !is null, message ); //$NON-NLS-1$ | |
105 } | 93 } |
106 | 94 |
107 /** Asserts that the given bool is <code>true</code>. If this | 95 /** Asserts that the given bool is <code>true</code>. If this |
108 * is not the case, some kind of unchecked exception is thrown. | 96 * is not the case, some kind of unchecked exception is thrown. |
109 * | 97 * |
124 * @return <code>true</code> if the check passes (does not return | 112 * @return <code>true</code> if the check passes (does not return |
125 * if the check fails) | 113 * if the check fails) |
126 */ | 114 */ |
127 public static bool isTrue(bool expression, String message) { | 115 public static bool isTrue(bool expression, String message) { |
128 if (!expression) | 116 if (!expression) |
129 throw new AssertionFailedException("assertion failed: " ~ message); //$NON-NLS-1$ | 117 throw new AssertionFailedException("assertion failed: " + message); //$NON-NLS-1$ |
130 return expression; | 118 return expression; |
131 } | 119 } |
132 } | 120 } |