KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > expr > Assert


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.expr;
21
22 import java.util.Collection JavaDoc;
23
24 /**
25  * Support class to help assertions and error processing when evaluating an expression.
26  *
27  * @author Maros Sandor
28  */

29 class Assert {
30
31     static Object JavaDoc error(SimpleNode node, String JavaDoc param) throws EvaluationException {
32         return error(node, param, null);
33     }
34
35     static Object JavaDoc error(SimpleNode node, String JavaDoc cause, Object JavaDoc p2) throws EvaluationException {
36         return error(node, cause, new Object JavaDoc [] { p2 });
37     }
38
39     static Object JavaDoc error(SimpleNode node, String JavaDoc cause, Object JavaDoc p2, Object JavaDoc p3) throws EvaluationException {
40         return error(node, cause, new Object JavaDoc [] { p2, p3});
41     }
42
43     static Object JavaDoc error(SimpleNode node, String JavaDoc cause, Object JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3) throws EvaluationException {
44         return error(node, cause, new Object JavaDoc [] { p1, p2, p3});
45     }
46
47     private static Object JavaDoc error (SimpleNode node, String JavaDoc cause, Object JavaDoc [] params) throws EvaluationException {
48         throw new EvaluationException(node, cause, params);
49     }
50
51     static void assertAssignable(Object JavaDoc o, Class JavaDoc aClass, SimpleNode s, String JavaDoc p1, Object JavaDoc p2) {
52         if (o != null && !aClass.isAssignableFrom(o.getClass())) {
53             error(s, p1, p2);
54         }
55     }
56
57     static void assertAssignable(Object JavaDoc o, Class JavaDoc aClass, SimpleNode s, String JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3) {
58         if (o != null && !aClass.isAssignableFrom(o.getClass())) {
59             error(s, p1, p2, p3);
60         }
61     }
62
63     static void assertNotAssignable(Object JavaDoc o, Class JavaDoc aClass, SimpleNode s, String JavaDoc p1, Object JavaDoc p2) {
64         if (aClass.isAssignableFrom(o.getClass())) {
65             error(s, p1, p2);
66         }
67     }
68
69     static void assertNotAssignable(Object JavaDoc o, Class JavaDoc aClass, SimpleNode s, String JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3) {
70         if (aClass.isAssignableFrom(o.getClass())) {
71             error(s, p1, p2, p3);
72         }
73     }
74
75     static void assertNotAssignable(Object JavaDoc o, Class JavaDoc aClass, SimpleNode node, String JavaDoc s) {
76         if (aClass.isAssignableFrom(o.getClass())) {
77             error(node, s);
78         }
79     }
80
81     static void assertLess(int a, int b, SimpleNode s, String JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3) {
82         if (a >= b) {
83             error(s, p1, p2, p3);
84         }
85     }
86
87     static void assertNotNull(Object JavaDoc obj, SimpleNode s, String JavaDoc identifier) {
88         if (obj == null) {
89             error(s, identifier);
90         }
91     }
92
93     static void assertNonEmpty(Collection JavaDoc collection, SimpleNode s, String JavaDoc p1, Object JavaDoc p2) {
94         if (collection == null || collection.size() == 0) {
95             error(s, p1, p2);
96         }
97     }
98
99     static void assertNotNull(Object JavaDoc obj, SimpleNode node, String JavaDoc p1, Object JavaDoc p2) {
100         if (obj == null) {
101             error(node, p1, p2);
102         }
103     }
104
105 }
106
Popular Tags