@JRubyMethod public IRubyObject clear(ThreadContext context) { table.clear(); return context.runtime.getNil(); }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { Ruby runtime = context.runtime; for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) { block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()), runtime.newFixnum(enumValueDescriptor.getNumber()))); } return runtime.getNil(); }
@JRubyMethod(rest = true) public static IRubyObject java_implements(IRubyObject recv, IRubyObject[] args) { // empty stub for now return recv.getRuntime().getNil(); }
@JRubyMethod(name = "method_missing", rest = true) public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) { if (args.length == 1) { RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass); IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]); if (oneofDescriptor.isNil()) { if (!hasField(args[0])) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return index(context, args[0]); } RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor; Descriptors.FieldDescriptor fieldDescriptor = oneofCases.get(rubyOneofDescriptor.getOneofDescriptor()); if (fieldDescriptor == null) return context.runtime.getNil(); return context.runtime.newSymbol(fieldDescriptor.getName()); } else { // fieldName is RubySymbol RubyString field = args[0].asString(); RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN); if (field.end_with_p(context, equalSign).isTrue()) { field.chomp_bang(context, equalSign); } if (!hasField(field)) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return indexSet(context, field, args[1]); } }
@JRubyMethod(required = 4, optional = 1) public IRubyObject map(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; IRubyObject valueType = args[2]; IRubyObject number = args[3]; IRubyObject typeClass = args.length > 4 ? args[4] : context.runtime.getNil(); keyField.setName(context, runtime.newString("key")); keyField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); keyField.setNumber(context, runtime.newFixnum(1)); keyField.setType(context, keyType); mapentryDesc.addField(context, keyField); valueField.setName(context, runtime.newString("value")); valueField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); valueField.setNumber(context, runtime.newFixnum(2)); valueField.setType(context, valueType); if (! typeClass.isNil()) valueField.setSubmsgName(context, typeClass); mapentryDesc.addField(context, valueField); return runtime.getNil();
@Override public IRubyObject get() { IRubyObject errorInfo = runtime.getGlobalVariables().get("$!"); IRubyObject backtrace = errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(errorInfo.getRuntime().getCurrentContext(), "backtrace"); //$@ returns nil if $!.backtrace is not an array if (!(backtrace instanceof RubyArray)) { backtrace = runtime.getNil(); } return backtrace; }
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; return context.runtime.getNil();
@JRubyMethod(rest = true) public static IRubyObject java_annotation(IRubyObject recv, IRubyObject[] args) { // empty stub for now return recv.getRuntime().getNil(); }
@JRubyMethod(meta = true) public static IRubyObject resolve(ThreadContext context, IRubyObject recv, IRubyObject name) { RubyEnumDescriptor rubyEnumDescriptorescriptor = (RubyEnumDescriptor) getDescriptor(context, recv); Descriptors.EnumDescriptor descriptor = rubyEnumDescriptorescriptor.getDescriptor(); Descriptors.EnumValueDescriptor value = descriptor.findValueByName(name.asJavaString()); if (value == null) return context.runtime.getNil(); return context.runtime.newFixnum(value.getNumber()); }
@JRubyMethod public IRubyObject lookup(ThreadContext context, IRubyObject name) { IRubyObject descriptor = this.symtab.get(name); if (descriptor == null) { return context.runtime.getNil(); } return descriptor; }
@JRubyMethod(name = "strip!", compat = RUBY1_9) public IRubyObject strip_bang19(ThreadContext context) { modifyCheck(); IRubyObject left = lstrip_bang19(context); IRubyObject right = rstrip_bang19(context); return left.isNil() && right.isNil() ? context.runtime.getNil() : this; }
@Override public IRubyObject get() { IRubyObject errorInfo = runtime.getGlobalVariables().get("$!"); IRubyObject backtrace = errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(errorInfo.getRuntime().getCurrentContext(), "backtrace"); //$@ returns nil if $!.backtrace is not an array if (!(backtrace instanceof RubyArray)) { backtrace = runtime.getNil(); } return backtrace; }
private IRubyObject wrapField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor, Object value) { if (value == null) { return context.runtime.getNil(); } Ruby runtime = context.runtime; switch (fieldDescriptor.getType()) { case INT32: case INT64: case UINT32: case UINT64: case FLOAT: case DOUBLE: case BOOL: case BYTES: case STRING: return Utils.wrapPrimaryValue(context, fieldDescriptor.getType(), value); case MESSAGE: RubyClass typeClass = (RubyClass) ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context); RubyMessage msg = (RubyMessage) typeClass.newInstance(context, Block.NULL_BLOCK); return msg.buildFrom(context, (DynamicMessage) value); case ENUM: Descriptors.EnumValueDescriptor enumValueDescriptor = (Descriptors.EnumValueDescriptor) value; if (enumValueDescriptor.getIndex() == -1) { // UNKNOWN ENUM VALUE return runtime.newFixnum(enumValueDescriptor.getNumber()); } return runtime.newSymbol(enumValueDescriptor.getName()); default: return runtime.newString(value.toString()); } }
/** rb_reg_match_pre * */ public static IRubyObject match_pre(IRubyObject match) { if (match.isNil()) return match; RubyMatchData m = (RubyMatchData)match; m.check(); Ruby runtime = m.getRuntime(); if (m.begin == -1) return runtime.getNil(); return m.str.makeShared(runtime, 0, m.begin).infectBy(m); }
@JRubyMethod(rest = true) public static IRubyObject java_require(IRubyObject recv, IRubyObject[] args) { // empty stub for now return recv.getRuntime().getNil(); }
@JRubyMethod(name = "<=>", required = 1, compat = CompatVersion.RUBY1_8) @Override public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { if (other instanceof RubyTime) { return context.runtime.newFixnum(cmp((RubyTime) other)); } return context.runtime.getNil(); }
@JRubyMethod(required = 3, optional = 1) public IRubyObject optional(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; IRubyObject typeClass = runtime.getNil(); if (args.length > 3) typeClass = args[3]; msgdefAddField(context, "optional", args[0], args[1], args[2], typeClass); return context.runtime.getNil(); }
@JRubyMethod public IRubyObject ungetbyte(IRubyObject b) { if (b.isNil()) return b; try { bufferedStream.unread(b.convertToInteger().getIntValue()); position--; } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } return getRuntime().getNil(); }
@Override public IRubyObject get() { IRubyObject errorInfo = runtime.getGlobalVariables().get("$!"); IRubyObject backtrace = errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(errorInfo.getRuntime().getCurrentContext(), "backtrace"); //$@ returns nil if $!.backtrace is not an array if (!(backtrace instanceof RubyArray)) { backtrace = runtime.getNil(); } return backtrace; }