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
19 /** Asserts that an argument is legal. If the given boolean is
20 * not <code>true</code>, an <code>IllegalArgumentException</code>
23 * @param expression the outcode of the check
24 * @return <code>true</code> if the check passes (does not return
26 * @exception IllegalArgumentException if the legality test failed
28 public static boolean isLegal(boolean expression) {
29 return isLegal(expression, ""); //$NON-NLS-1$
31 /** Asserts that an argument is legal. If the given boolean is
32 * not <code>true</code>, an <code>IllegalArgumentException</code>
34 * The given message is included in that exception, to aid debugging.
36 * @param expression the outcode of the check
37 * @param message the message to include in the exception
38 * @return <code>true</code> if the check passes (does not return
40 * @exception IllegalArgumentException if the legality test failed
42 public static boolean isLegal(boolean expression, String message) {
44 throw new IllegalArgumentException(message);
47 /** Asserts that the given object is not <code>null</code>. If this
48 * is not the case, some kind of unchecked exception is thrown.
50 * @param object the value to test
51 * @exception IllegalArgumentException if the object is <code>null</code>
53 public static void isNotNull(Object object) {
54 isNotNull(object, ""); //$NON-NLS-1$
56 /** Asserts that the given object is not <code>null</code>. If this
57 * is not the case, some kind of unchecked exception is thrown.
58 * The given message is included in that exception, to aid debugging.
60 * @param object the value to test
61 * @param message the message to include in the exception
62 * @exception IllegalArgumentException if the object is <code>null</code>
64 public static void isNotNull(Object object, String message) {
66 throw new AssertionFailedException("null argument; " + message); //$NON-NLS-1$
68 /** Asserts that the given boolean is <code>true</code>. If this
69 * is not the case, some kind of unchecked exception is thrown.
71 * @param expression the outcode of the check
72 * @return <code>true</code> if the check passes (does not return
75 public static boolean isTrue(boolean expression) {
76 return isTrue(expression, ""); //$NON-NLS-1$
78 /** Asserts that the given boolean is <code>true</code>. If this
79 * is not the case, some kind of unchecked exception is thrown.
80 * The given message is included in that exception, to aid debugging.
82 * @param expression the outcode of the check
83 * @param message the message to include in the exception
84 * @return <code>true</code> if the check passes (does not return
87 public static boolean isTrue(boolean expression, String message) {
89 throw new AssertionFailedException("Assertion failed; " + message); //$NON-NLS-1$
93 public static class AssertionFailedException extends RuntimeException {
94 public AssertionFailedException(String detail) {