本文整理了Java中org.jruby.Ruby.newTypeError
方法的一些代码示例,展示了Ruby.newTypeError
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newTypeError
方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newTypeError
暂无
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod(name = "get")
public IRubyObject getValue(ThreadContext context, IRubyObject msgRb) {
RubyMessage message = (RubyMessage) msgRb;
if (message.getDescriptor() != fieldDef.getContainingType()) {
throw context.runtime.newTypeError("set method called on wrong message type");
}
return message.getField(context, fieldDef);
}
代码示例来源:origin: bazelbuild/bazel
case UINT64:
if (!isRubyNum(value)) {
throw runtime.newTypeError("Expected number type for integral field.");
case FLOAT:
if (!isRubyNum(value))
throw runtime.newTypeError("Expected number type for float field.");
break;
case DOUBLE:
if (!isRubyNum(value))
throw runtime.newTypeError("Expected number type for double field.");
break;
case BOOL:
if (!(value instanceof RubyBoolean))
throw runtime.newTypeError("Invalid argument for boolean field.");
break;
case BYTES:
break;
case MESSAGE:
if (value.getMetaClass() != typeClass) {
throw runtime.newTypeError(value, typeClass);
throw runtime.newRangeError("Enum value " + value + " is not found.");
} else if(!isRubyNum(value)) {
throw runtime.newTypeError("Expected number or symbol type for enum field.");
代码示例来源:origin: bazelbuild/bazel
protected IRubyObject setField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor, IRubyObject value) {
if (Utils.isMapEntry(fieldDescriptor)) {
if (!(value instanceof RubyMap)) {
throw context.runtime.newTypeError("Expected Map instance");
fields.remove(oneofCase);
if (value.isNil()) {
oneofCases.remove(oneofDescriptor);
fields.remove(fieldDescriptor);
if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE) {
typeClass = ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context);
if (value.isNil()){
addValue = false;
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(name = "new", meta = true)
public static final IRubyObject newStructByReference(ThreadContext context, IRubyObject klass, IRubyObject structClass) {
if (!(structClass instanceof RubyClass)) {
throw context.runtime.newTypeError("wrong argument type "
+ structClass.getMetaClass().getName() + " (expected Class)");
}
if (!((RubyClass) structClass).isKindOfModule(context.runtime.getFFI().structClass)) {
throw context.runtime.newTypeError("wrong argument type "
+ structClass.getMetaClass().getName() + " (expected subclass of FFI::Struct)");
}
return new StructByReference(context.runtime, (RubyClass) klass,
(RubyClass) structClass, null);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject set_trace_func(ThreadContext context, IRubyObject recv, IRubyObject trace_func, Block block) {
if (trace_func.isNil()) {
context.runtime.setTraceFunction(null);
} else if (!(trace_func instanceof RubyProc)) {
throw context.runtime.newTypeError("trace_func needs to be Proc.");
} else {
context.runtime.setTraceFunction((RubyProc) trace_func);
}
return trace_func;
}
代码示例来源:origin: org.jruby/jruby-complete
/** rb_flo_induced_from
*
*/
@Deprecated
public static IRubyObject induced_from(ThreadContext context, IRubyObject recv, IRubyObject number) {
if (number instanceof RubyFixnum || number instanceof RubyBignum || number instanceof RubyRational) {
return number.callMethod(context, "to_f");
} else if (number instanceof RubyFloat) {
return number;
}
throw recv.getRuntime().newTypeError("failed to convert " + number.getMetaClass() + " into Float");
}
代码示例来源:origin: org.jruby/jruby-complete
private static void checkArrayType(Ruby runtime, IRubyObject obj) {
if (!(obj instanceof RubyArray)) {
throw runtime.newTypeError("wrong argument type "
+ obj.getMetaClass().getName() + " (expected Array)");
}
}
代码示例来源:origin: org.jruby/jruby-complete
private static RubyString getStringForPattern(Ruby runtime, IRubyObject obj) {
if (obj instanceof RubyString) return (RubyString) obj;
IRubyObject val = obj.checkStringType();
if (val.isNil()) throw runtime.newTypeError("wrong argument type " + obj.getMetaClass() + " (expected Regexp)");
return (RubyString) val;
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(required = 1, meta = true)
public static IRubyObject kill(IRubyObject receiver, IRubyObject rubyThread, Block block) {
if (!(rubyThread instanceof RubyThread)) throw receiver.getRuntime().newTypeError(rubyThread, receiver.getRuntime().getThread());
return ((RubyThread)rubyThread).kill();
}
代码示例来源:origin: org.jruby/jruby-complete
@Deprecated
public static IRubyObject convertToTypeWithCheck(IRubyObject obj, RubyClass target, int convertMethodIndex, String convertMethod) {
if (target.isInstance(obj)) return obj;
IRubyObject val = TypeConverter.convertToType(obj, target, convertMethod, false);
if (val.isNil()) return val;
if (!target.isInstance(val)) {
Ruby runtime = obj.getRuntime();
throw runtime.newTypeError(str(runtime, types(runtime, obj.getMetaClass()), "#" + convertMethod + " should return ", types(runtime, target)));
}
return val;
}
代码示例来源:origin: org.jruby/jruby-complete
private static long other2long(IRubyObject arg) throws RaiseException {
if (arg instanceof RubyFloat) return float2long((RubyFloat) arg);
if (arg instanceof RubyBignum) return RubyBignum.big2long((RubyBignum) arg);
if (arg.isNil()) {
throw arg.getRuntime().newTypeError("no implicit conversion from nil to integer");
}
return arg.convertToInteger().getLongValue();
}
代码示例来源:origin: org.jruby/jruby-complete
RandomType(IRubyObject seed) {
this.seed = seed.convertToInteger();
if (this.seed instanceof RubyFixnum) {
this.impl = randomFromFixnum((RubyFixnum) this.seed);
} else if (this.seed instanceof RubyBignum) {
this.impl = randomFromBignum((RubyBignum) this.seed);
} else {
throw seed.getRuntime().newTypeError(
String.format("failed to convert %s into Integer", seed.getMetaClass().getName()));
}
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
/** num_init_copy
*
*/
@Override
@JRubyMethod(name = "initialize_copy", visibility = Visibility.PRIVATE)
public IRubyObject initialize_copy(IRubyObject arg) {
throw getRuntime().newTypeError("can't copy " + getType().getName());
}
代码示例来源:origin: org.jruby/jruby-complete
/** nucomp_coerce
*
*/
@JRubyMethod(name = "coerce")
public IRubyObject coerce(ThreadContext context, IRubyObject other) {
if (other instanceof RubyNumeric && f_real_p(context, other)) {
return context.runtime.newArray(newComplexBang(context, getMetaClass(), (RubyNumeric) other), this);
}
if (other instanceof RubyComplex) return context.runtime.newArray(other, this);
Ruby runtime = context.runtime;
throw runtime.newTypeError(str(runtime, types(runtime, other.getMetaClass()), " can't be coerced into ", types(runtime, getMetaClass())));
}
代码示例来源:origin: org.jruby/jruby-complete
public void writeUserClass(IRubyObject obj, RubyClass type) throws IOException {
write(TYPE_UCLASS);
// w_unique
if (type.getName().charAt(0) == '#') {
Ruby runtime = obj.getRuntime();
throw runtime.newTypeError(str(runtime, "can't dump anonymous class ", types(runtime, type)));
}
// w_symbol
writeAndRegisterSymbol(RubySymbol.newSymbol(runtime, type.getName()).getBytes());
}
代码示例来源:origin: org.jruby/jruby-complete
private static RubyModule module(IRubyObject obj) {
if (!(obj instanceof RubyModule)) {
throw obj.getRuntime().newTypeError("not a module");
}
return (RubyModule) obj;
}
代码示例来源:origin: org.jruby/jruby-complete
public static IRubyObject[] toAry(ThreadContext context, IRubyObject[] args) {
IRubyObject ary;
if (args.length == 1 && (ary = Helpers.aryOrToAry(context, args[0])) != context.nil) {
if (ary instanceof RubyArray) {
args = ((RubyArray) ary).toJavaArray();
} else {
throw context.runtime.newTypeError(args[0].getType().getName() + "#to_ary should return Array");
}
}
return args;
}
代码示例来源:origin: org.jruby/jruby-core
@JRubyMethod(name = "new", meta = true)
public static final IRubyObject newStructByReference(ThreadContext context, IRubyObject klass, IRubyObject structClass) {
if (!(structClass instanceof RubyClass)) {
throw context.runtime.newTypeError("wrong argument type "
+ structClass.getMetaClass().getName() + " (expected Class)");
}
if (!((RubyClass) structClass).isKindOfModule(context.runtime.getFFI().structClass)) {
throw context.runtime.newTypeError("wrong argument type "
+ structClass.getMetaClass().getName() + " (expected subclass of FFI::Struct)");
}
return new StructByReference(context.runtime, (RubyClass) klass,
(RubyClass) structClass, null);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod
public synchronized IRubyObject feed(ThreadContext context, IRubyObject val) {
final Nexter nexter = ensureNexter(context.runtime);
if (!feedValue.isNil()) {
throw context.runtime.newTypeError("feed value already set");
}
feedValue = val;
nexter.setFeedValue(val);
return context.nil;
}
代码示例来源:origin: org.jruby/jruby-core
/** rb_flo_induced_from
*
*/
@Deprecated
public static IRubyObject induced_from(ThreadContext context, IRubyObject recv, IRubyObject number) {
if (number instanceof RubyFixnum || number instanceof RubyBignum || number instanceof RubyRational) {
return number.callMethod(context, "to_f");
} else if (number instanceof RubyFloat) {
return number;
}
throw recv.getRuntime().newTypeError("failed to convert " + number.getMetaClass() + " into Float");
}
内容来源于网络,如有侵权,请联系作者删除!