Beispiel #1
0
  /** Create a new exception API object. */
  public static Value __construct(
      Env env, @This ObjectValue value, @Optional StringValue message, @Optional("0") int code) {
    value.putField(env, "message", message);
    value.putField(env, "code", LongValue.create(code));

    Location location = env.getLocation();

    if (location != null) {
      if (location.getFileName() != null) {
        value.putField(env, "file", env.createString(location.getFileName()));
      } else {
        value.putField(env, "file", env.createString("unknown"));
      }

      value.putField(env, "line", LongValue.create(location.getLineNumber()));
    }

    value.putField(env, "trace", ErrorModule.debug_backtrace(env, false));
    BiancaException e = new BiancaException();
    e.fillInStackTrace();

    value.putField(env, "_biancaException", env.wrapJava(e));

    return value;
  }
Beispiel #2
0
  public static Value objectToValue(Object obj) {
    if (obj == null) {
      return NullValue.NULL;
    } else if (Byte.class.equals(obj.getClass())
        || Short.class.equals(obj.getClass())
        || Integer.class.equals(obj.getClass())
        || Long.class.equals(obj.getClass())) {
      return LongValue.create(((Number) obj).longValue());
    } else if (Float.class.equals(obj.getClass()) || Double.class.equals(obj.getClass())) {
      return DoubleValue.create(((Number) obj).doubleValue());
    } else if (String.class.equals(obj.getClass())) {
      // TODO: i18n
      return new StringValue((String) obj);
    } else {
      // TODO: unknown types, e.g. Character?

      return null;
    }
  }