Changeset 4006


Ignore:
Timestamp:
09/22/03 17:26:40 (19 years ago)
Author:
piso
Message:

initArgs constructor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/TypeError.java

    r3984 r4006  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: TypeError.java,v 1.8 2003-09-22 02:17:35 piso Exp $
     5 * $Id: TypeError.java,v 1.9 2003-09-22 17:26:40 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2222package org.armedbear.lisp;
    2323
    24 public final class TypeError extends LispError
     24public class TypeError extends LispError
    2525{
    26     private final LispObject object;
    27     private final String expectedType;
     26    protected LispObject datum;
     27    protected LispObject expectedType;
     28    private String typeString;
    2829
    2930    public TypeError()
    3031    {
    31         this(null, null);
     32    }
     33
     34    public TypeError(LispObject initArgs) throws ConditionThrowable
     35    {
     36        LispObject datum = NIL;
     37        LispObject expectedType = NIL;
     38        LispObject first, second;
     39        while (initArgs != NIL) {
     40            first = initArgs.car();
     41            initArgs = initArgs.cdr();
     42            second = initArgs.car();
     43            initArgs = initArgs.cdr();
     44            if (first == Keyword.DATUM)
     45                datum = second;
     46            else if (first == Keyword.EXPECTED_TYPE)
     47                expectedType = second;
     48        }
     49        this.datum = datum;
     50        this.expectedType = expectedType;
     51        this.typeString = String.valueOf(expectedType);
    3252    }
    3353
     
    3555    {
    3656        super(message);
    37         object = null;
    38         expectedType = null;
    3957    }
    4058
    41     public TypeError(LispObject object)
     59    public TypeError(LispObject datum, String typeString)
    4260    {
    43         this(object, null);
    44     }
    45 
    46     public TypeError(LispObject object, String expectedType)
    47     {
    48         this.object = object;
    49         this.expectedType = expectedType;
     61        this.datum = datum;
     62        this.typeString = typeString;
    5063    }
    5164
     
    7588            return s;
    7689        StringBuffer sb = new StringBuffer("wrong type");
    77         String name = object != null ? String.valueOf(object) : null;
    78         if (expectedType != null) {
     90        String name = datum != null ? String.valueOf(datum) : null;
     91        if (typeString != null) {
    7992            if (name == null)
    80                 name = "object";
     93                name = "datum";
    8194            sb.append(": ");
    8295            sb.append(name);
    8396            sb.append(" is not a");
    84             if ("aeiou".indexOf(expectedType.charAt(0)) >= 0)
     97            if ("aeiou".indexOf(typeString.charAt(0)) >= 0)
    8598                sb.append('n');
    8699            sb.append(' ');
    87             sb.append(expectedType);
     100            sb.append(typeString);
    88101        } else if (name != null) {
    89102            sb.append(": ");
Note: See TracChangeset for help on using the changeset viewer.