1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 /* This class is not intended to be instantiated. */
14 public final class Assert {
17 // cannot be instantiated
21 * Asserts that an argument is legal. If the given boolean is not
22 * <code>true</code>, an <code>IllegalArgumentException</code> is
26 * the outcode of the check
27 * @return <code>true</code> if the check passes (does not return if the
29 * @exception IllegalArgumentException
30 * if the legality test failed
32 public static boolean isLegal(boolean expression) {
33 return isLegal(expression, ""); //$NON-NLS-1$
37 * Asserts that an argument is legal. If the given boolean is not
38 * <code>true</code>, an <code>IllegalArgumentException</code> is
39 * thrown. The given message is included in that exception, to aid
43 * the outcode of the check
45 * the message to include in the exception
46 * @return <code>true</code> if the check passes (does not return if the
48 * @exception IllegalArgumentException
49 * if the legality test failed
51 public static boolean isLegal(boolean expression, String message) {
53 throw new IllegalArgumentException(message);
58 * Asserts that the given object is not <code>null</code>. If this is not
59 * the case, some kind of unchecked exception is thrown.
63 * @exception IllegalArgumentException
64 * if the object is <code>null</code>
66 public static void isNotNull(Object object) {
67 isNotNull(object, ""); //$NON-NLS-1$
71 * Asserts that the given object is not <code>null</code>. If this is not
72 * the case, some kind of unchecked exception is thrown. The given message
73 * is included in that exception, to aid debugging.
78 * the message to include in the exception
79 * @exception IllegalArgumentException
80 * if the object is <code>null</code>
82 public static void isNotNull(Object object, String message) {
84 throw new AssertionFailedException("null argument; " + message); //$NON-NLS-1$
88 * Asserts that the given boolean is <code>true</code>. If this is not
89 * the case, some kind of unchecked exception is thrown.
92 * the outcode of the check
93 * @return <code>true</code> if the check passes (does not return if the
96 public static boolean isTrue(boolean expression) {
97 return isTrue(expression, ""); //$NON-NLS-1$
101 * Asserts that the given boolean is <code>true</code>. If this is not
102 * the case, some kind of unchecked exception is thrown. The given message
103 * is included in that exception, to aid debugging.
106 * the outcode of the check
108 * the message to include in the exception
109 * @return <code>true</code> if the check passes (does not return if the
112 public static boolean isTrue(boolean expression, String message) {
114 throw new AssertionFailedException("Assertion failed; " + message); //$NON-NLS-1$
118 public static class AssertionFailedException extends RuntimeException {
119 public AssertionFailedException(String detail) {