01: /*
02: * SimpleTypeError.java
03: *
04: * Copyright (C) 2002-2004 Peter Graves
05: * $Id: SimpleTypeError.java,v 1.4 2004/03/10 01:53:21 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.lisp;
23:
24: public final class SimpleTypeError extends TypeError {
25: public SimpleTypeError(LispObject initArgs)
26: throws ConditionThrowable {
27: super (initArgs);
28: }
29:
30: public LispObject typeOf() {
31: return Symbol.SIMPLE_TYPE_ERROR;
32: }
33:
34: public LispClass classOf() {
35: return BuiltInClass.SIMPLE_TYPE_ERROR;
36: }
37:
38: public LispObject typep(LispObject type) throws ConditionThrowable {
39: if (type == Symbol.SIMPLE_TYPE_ERROR)
40: return T;
41: if (type == BuiltInClass.SIMPLE_TYPE_ERROR)
42: return T;
43: if (type == Symbol.SIMPLE_CONDITION)
44: return T;
45: if (type == BuiltInClass.SIMPLE_CONDITION)
46: return T;
47: return super .typep(type);
48: }
49:
50: public String getMessage() {
51: try {
52: LispObject formatControl = getFormatControl();
53: if (formatControl != NIL) {
54: LispObject formatArguments = getFormatArguments();
55: if (formatArguments != NIL) {
56: // (apply 'format (append '(nil format-control) format-arguments))
57: LispObject result = Primitives.APPLY.execute(
58: Symbol.FORMAT, Primitives.APPEND.execute(
59: list2(NIL, formatControl),
60: formatArguments));
61: return result.getStringValue();
62: }
63: }
64: if (datum != null && expectedType != null) {
65: StringBuffer sb = new StringBuffer("The value ");
66: sb.append(String.valueOf(datum));
67: sb.append(" is not of type ");
68: sb.append(String.valueOf(expectedType));
69: sb.append('.');
70: return sb.toString();
71: }
72: } catch (Throwable t) {
73: }
74: return null;
75: }
76: }
|