org.jruby.Ruby.newArgumentError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.jruby.Ruby.newArgumentError方法的一些代码示例,展示了Ruby.newArgumentError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newArgumentError方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newArgumentError

Ruby.newArgumentError介绍

暂无

代码示例

代码示例来源:origin: bazelbuild/bazel

protected static void validateTypeClass(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) {
  Ruby runtime = context.runtime;
  if (!(value instanceof RubyModule)) {
    throw runtime.newArgumentError("TypeClass has incorrect type");
  }
  RubyModule klass = (RubyModule) value;
  IRubyObject descriptor = klass.getInstanceVariable(DESCRIPTOR_INSTANCE_VAR);
  if (descriptor.isNil()) {
    throw runtime.newArgumentError("Type class has no descriptor. Please pass a " +
        "class or enum as returned by the DescriptorPool.");
  }
  if (type == Descriptors.FieldDescriptor.Type.MESSAGE) {
    if (! (descriptor instanceof RubyDescriptor)) {
      throw runtime.newArgumentError("Descriptor has an incorrect type");
    }
  } else if (type == Descriptors.FieldDescriptor.Type.ENUM) {
    if (! (descriptor instanceof RubyEnumDescriptor)) {
      throw runtime.newArgumentError("Descriptor has an incorrect type");
    }
  }
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod
public IRubyObject concat(ThreadContext context, IRubyObject list) {
  if (list instanceof RubyArray) {
    checkArrayElementType(context, (RubyArray) list);
    this.storage.addAll((RubyArray) list);
  } else {
    RubyRepeatedField repeatedField = (RubyRepeatedField) list;
    if (! fieldType.equals(repeatedField.fieldType) || (typeClass != null && !
        typeClass.equals(repeatedField.typeClass)))
      throw context.runtime.newArgumentError("Attempt to append RepeatedField with different element type.");
    this.storage.addAll((RubyArray) repeatedField.toArray(context));
  }
  return this.storage;
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(required = 4, optional = 1)
public IRubyObject map(ThreadContext context, IRubyObject[] args) {
  Ruby runtime = context.runtime;
      keyType.equals(RubySymbol.newSymbol(runtime, "enum")) ||
      keyType.equals(RubySymbol.newSymbol(runtime, "message")))
    throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
  valueField.setNumber(context, runtime.newFixnum(2));
  valueField.setType(context, valueType);
  if (! typeClass.isNil()) valueField.setSubmsgName(context, typeClass);
  mapentryDesc.addField(context, valueField);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "digest", required = 1, rest = true, meta = true)
public static IRubyObject s_digest(ThreadContext ctx, IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
  Ruby runtime = recv.getRuntime();
  if (args.length < 1) {
    throw runtime.newArgumentError("no data given");
  }
  RubyString str = args[0].convertToString();
  IRubyObject[] newArgs = new IRubyObject[args.length - 1];
  System.arraycopy(args, 1, newArgs, 0, args.length - 1);
  IRubyObject obj = ((RubyClass)recv).newInstance(ctx, newArgs, Block.NULL_BLOCK);
  return obj.callMethod(ctx, "digest", str);
}

代码示例来源:origin: org.jruby/jruby-complete

public static Encoding toEncoding(ThreadContext context, IRubyObject enc) {
  RubyString encStr = enc.convertToString();
  if (!encStr.getEncoding().isAsciiCompatible()) {
    throw context.runtime.newArgumentError("invalid name encoding (non ASCII)");
  }
  Encoding idx = context.runtime.getEncodingService().getEncodingFromObject(encStr);
  // check for missing encoding is in getEncodingFromObject
  return idx;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private static IRubyObject str_to_r_strict(ThreadContext context, IRubyObject recv) {
    RubyArray a = str_to_r_internal(context, recv);
    if (a.eltInternal(0).isNil() || a.eltInternal(1).convertToString().getByteList().length() > 0) {
      IRubyObject s = recv.callMethod(context, "inspect");
      throw context.runtime.newArgumentError("invalid value for convert(): " + s.convertToString());
    }
    return a.eltInternal(0);
  }    
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(required = 1, optional = 2)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
  Ruby runtime = context.runtime;
  IRubyObject ary = null;
  if (!(args[0] instanceof RubySymbol)) {
    throw runtime.newArgumentError("Expected Symbol for type name");
      || fieldType == Descriptors.FieldDescriptor.Type.ENUM) {
    if (args.length < 2)
      throw runtime.newArgumentError("Expected at least 2 arguments for message/enum");
    typeClass = args[1];
    if (args.length > 2)
  } else {
    if (args.length > 2)
      throw runtime.newArgumentError("Too many arguments: expected 1 or 2");
    if (args.length > 1)
      ary = args[1];

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject clock_gettime(ThreadContext context, IRubyObject self, IRubyObject _clock_id, IRubyObject _unit) {
  Ruby runtime = context.runtime;
  if (!(_unit instanceof RubySymbol) && !_unit.isNil()) {
    throw runtime.newArgumentError("unexpected unit: " + _unit);
  }
  return makeClockResult(runtime, getTimeForClock(_clock_id, runtime), _unit.toString());
}

代码示例来源:origin: bazelbuild/bazel

public static RubyFieldDescriptor msgdefCreateField(ThreadContext context, String label, IRubyObject name,
                 IRubyObject type, IRubyObject number, IRubyObject typeClass, RubyClass cFieldDescriptor) {
  Ruby runtime = context.runtime;
  RubyFieldDescriptor fieldDef = (RubyFieldDescriptor) cFieldDescriptor.newInstance(context, Block.NULL_BLOCK);
  fieldDef.setLabel(context, runtime.newString(label));
  fieldDef.setName(context, name);
  fieldDef.setType(context, type);
  fieldDef.setNumber(context, number);
  if (!typeClass.isNil()) {
    if (!(typeClass instanceof RubyString)) {
      throw runtime.newArgumentError("expected string for type class");
    }
    fieldDef.setSubmsgName(context, typeClass);
  }
  return fieldDef;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "digest", required = 1, rest = true, meta = true)
public static IRubyObject s_digest(ThreadContext ctx, IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
  Ruby runtime = recv.getRuntime();
  if (args.length < 1) {
    throw runtime.newArgumentError("no data given");
  }
  RubyString str = args[0].convertToString();
  IRubyObject[] newArgs = new IRubyObject[args.length - 1];
  System.arraycopy(args, 1, newArgs, 0, args.length - 1);
  IRubyObject obj = ((RubyClass)recv).newInstance(ctx, newArgs, Block.NULL_BLOCK);
  return obj.callMethod(ctx, "digest", str);
}

代码示例来源:origin: org.jruby/jruby-core

private static RubyNumeric str_to_r_strict(ThreadContext context, RubyString str) {
  IRubyObject[] ary = str_to_r_internal(context, str);
  if (ary[0] == context.nil || ary[1].convertToString().getByteList().length() > 0) {
    throw context.runtime.newArgumentError("invalid value for convert(): " + str.inspect(context.runtime));
  }
  return (RubyNumeric) ary[0]; // (RubyRational)
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private static IRubyObject str_to_r_strict(ThreadContext context, IRubyObject recv) {
    RubyArray a = str_to_r_internal(context, recv);
    if (a.eltInternal(0).isNil() || a.eltInternal(1).convertToString().getByteList().length() > 0) {
      IRubyObject s = recv.callMethod(context, "inspect");
      throw context.runtime.newArgumentError("invalid value for convert(): " + s.convertToString());
    }
    return a.eltInternal(0);
  }    
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(name = {"+"})
public IRubyObject plus(ThreadContext context, IRubyObject list) {
  RubyRepeatedField dup = (RubyRepeatedField) dup(context);
  if (list instanceof RubyArray) {
    checkArrayElementType(context, (RubyArray) list);
    dup.storage.addAll((RubyArray) list);
  } else {
    RubyRepeatedField repeatedField = (RubyRepeatedField) list;
    if (! fieldType.equals(repeatedField.fieldType) || (typeClass != null && !
        typeClass.equals(repeatedField.typeClass)))
      throw context.runtime.newArgumentError("Attempt to append RepeatedField with different element type.");
    dup.storage.addAll((RubyArray) repeatedField.toArray(context));
  }
  return dup;
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject clock_getres(ThreadContext context, IRubyObject self, IRubyObject _clock_id, IRubyObject _unit) {
  Ruby runtime = context.runtime;
  if (!(_unit instanceof RubySymbol) && !_unit.isNil()) {
    throw runtime.newArgumentError("unexpected unit: " + _unit);
  }
  return makeClockResolutionResult(runtime, getResolutionForClock(_clock_id, runtime), _unit.toString());
}

代码示例来源:origin: org.jruby/jruby-complete

private void init(ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) {
  if (!(begin instanceof RubyFixnum && end instanceof RubyFixnum)) {
    IRubyObject result = invokedynamic(context, begin, MethodNames.OP_CMP, end);
    if (result.isNil()) {
      throw context.runtime.newArgumentError("bad value for range");
    }
  }
  this.begin = begin;
  this.end = end;
  this.isExclusive = isExclusive;
  this.isInited = true;
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(name = "digest", required = 1, rest = true, meta = true)
public static IRubyObject s_digest(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
  final Ruby runtime = context.runtime;
  if (args.length < 1) {
    throw runtime.newArgumentError("no data given");
  }
  RubyString str = args[0].convertToString();
  args = ArraySupport.newCopy(args, 1, args.length - 1); // skip first arg
  IRubyObject obj = ((RubyClass) recv).newInstance(context, args, Block.NULL_BLOCK);
  return obj.callMethod(context, "digest", str);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static Encoding toEncoding(ThreadContext context, IRubyObject enc) {
  RubyString encStr = enc.convertToString();
  if (!encStr.getEncoding().isAsciiCompatible()) {
    throw context.runtime.newArgumentError("invalid name encoding (non ASCII)");
  }
  Encoding idx = context.runtime.getEncodingService().getEncodingFromObject(enc);
  // check for missing encoding is in getEncodingFromObject
  return idx;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private static IRubyObject str_to_c_strict(ThreadContext context, IRubyObject recv) {
    RubyArray a = str_to_c_internal(context, recv);
    if (a.eltInternal(0).isNil() || a.eltInternal(1).convertToString().getByteList().length() > 0) {
      IRubyObject s = recv.callMethod(context, "inspect");
      throw context.runtime.newArgumentError("invalid value for convert(): " + s.convertToString());
    }
    return a.eltInternal(0);
  }    
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(optional = 1)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
  final Ruby runtime = context.runtime;
  if (args.length == 1) {
    if (!(args[0] instanceof RubyHash)) {
      throw runtime.newArgumentError("expected Hash arguments.");

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject clock_getres(ThreadContext context, IRubyObject self, IRubyObject _clock_id, IRubyObject _unit) {
  Ruby runtime = context.runtime;
  if (!(_unit instanceof RubySymbol) && !_unit.isNil()) {
    throw runtime.newArgumentError("unexpected unit: " + _unit);
  }
  return makeClockResolutionResult(runtime, getResolutionForClock(_clock_id, runtime), _unit.toString());
}

相关文章

Ruby类方法