本文整理汇总了Java中org.jruby.runtime.builtin.IRubyObject.isNil方法的典型用法代码示例。如果您正苦于以下问题:Java IRubyObject.isNil方法的具体用法?Java IRubyObject.isNil怎么用?Java IRubyObject.isNil使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.runtime.builtin.IRubyObject
的用法示例。
在下文中一共展示了IRubyObject.isNil方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueFromView
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
public Object getValueFromView(Object view, String[] path) {
if(view instanceof IRubyObject) {
IRubyObject o = (IRubyObject)view;
for(String key : path) {
if(o == null || o.isNil()) { return null; }
o = o.callMethod(o.getRuntime().getCurrentContext(), "[]",
RubyString.newUnicodeString(o.getRuntime(), key));
}
if(o instanceof ConcreteJavaProxy) {
return ((ConcreteJavaProxy)o).getObject();
}
return ((o == null) || o.isNil()) ? null : o;
} else if(path.length == 0) {
return view; // to allow . value to work
}
return null;
}
示例2: pushTail
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
private Node pushTail(ThreadContext context, int level, Node parent, Node tailnode){
int subidx = ((cnt - 1) >>> level) & 0x01f;
Node ret = new Node(context.runtime, Node).initialize_params_arry(context, parent.edit, parent.array.aryDup());
Node nodeToInsert;
if(level == 5)
{
nodeToInsert = tailnode;
}
else
{
IRubyObject child = parent.array.entry(subidx);
nodeToInsert = (!child.isNil())?
pushTail(context, level-5,(Node) child, tailnode)
:newPath(context, root.edit,level-5, tailnode);
}
ret.array.store(subidx, nodeToInsert);
return ret;
}
示例3: toHash
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
@JRubyMethod(name = {"to_h", "to_hash"})
public IRubyObject toHash(ThreadContext context) {
Ruby runtime = context.runtime;
RubyHash ret = RubyHash.newHash(runtime);
for (Descriptors.FieldDescriptor fdef : this.descriptor.getFields()) {
IRubyObject value = getField(context, fdef);
if (!value.isNil()) {
if (value.respondsTo("to_h")) {
value = Helpers.invoke(context, value, "to_h");
} else if (value.respondsTo("to_a")) {
value = Helpers.invoke(context, value, "to_a");
}
}
ret.fastASet(runtime.newSymbol(fdef.getName()), value);
}
return ret;
}
示例4: msgdefCreateField
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
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;
}
示例5: validateTypeClass
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
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");
}
}
}
示例6: valueToStringRepresentation
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
public String valueToStringRepresentation(Object value) {
if(value instanceof RubyArray || value instanceof RubyHash) {
return null;
}
if(value instanceof IRubyObject) {
IRubyObject o = (IRubyObject)value;;
if(o.isNil()) { return null; }
IRubyObject str = o.callMethod(o.getRuntime().getCurrentContext(), "to_s");
if(!(str instanceof RubyString)) { return null; }
return ((RubyString)str).decodeString();
}
return (value == null) ? null : value.toString();
}
示例7: matchesRegexp
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
protected boolean matchesRegexp(RubyRegexp regexp, String lineContent)
{
if (regexp == null)
return false;
RubyString string = regexp.getRuntime().newString(lineContent);
IRubyObject matcher = regexp.match_m(regexp.getRuntime().getCurrentContext(), string);
return !matcher.isNil();
}
示例8: rubyCompare
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
int rubyCompare(RubyObject l, RubyObject r) {
ThreadContext context = l.getMetaClass().getRuntime().getCurrentContext();
IRubyObject result;
try {
result = l.callMethod(context, "<=>", r);
} catch (RaiseException e) {
// handle objects "lying" about responding to <=>, ie: an Array containing non-comparable keys
if (context.runtime.getNoMethodError().isInstance(e.getException())) {
return 0;
}
throw e;
}
return result.isNil() ? 0 : RubyNumeric.num2int(result.convertToInteger());
}
示例9: toCHM
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
private ConcurrentHashMap<IRubyObject, IRubyObject> toCHM(ThreadContext context, IRubyObject options) {
Ruby runtime = context.getRuntime();
if (!options.isNil() && options.respondsTo("[]")) {
IRubyObject rInitialCapacity = options.callMethod(context, "[]", runtime.newSymbol("initial_capacity"));
IRubyObject rLoadFactor = options.callMethod(context, "[]", runtime.newSymbol("load_factor"));
int initialCapacity = !rInitialCapacity.isNil() ? RubyNumeric.num2int(rInitialCapacity.convertToInteger()) : DEFAULT_INITIAL_CAPACITY;
float loadFactor = !rLoadFactor.isNil() ? (float)RubyNumeric.num2dbl(rLoadFactor.convertToFloat()) : DEFAULT_LOAD_FACTOR;
return newCHM(initialCapacity, loadFactor);
} else {
return newCHM();
}
}
示例10: eventHandler
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
public void eventHandler(ThreadContext context, String eventName, String file, int line, String name, IRubyObject type) {
RubyArray bindings = RubyBindingsCollector.collectCurrentFor(context);
RubyException exception = (RubyException) context.runtime.getGlobalVariables().get("$!");
IRubyObject exceptionBindings = exception.getInstanceVariable("@bindings");
if (exceptionBindings == null || exceptionBindings.isNil()) {
exception.setInstanceVariable("@bindings", bindings);
}
}
示例11: methodMissing
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
@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]);
}
}
示例12: map
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
@JRubyMethod(required = 4, optional = 1)
public IRubyObject map(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
IRubyObject name = args[0];
IRubyObject keyType = args[1];
IRubyObject valueType = args[2];
IRubyObject number = args[3];
IRubyObject typeClass = args.length > 4 ? args[4] : context.runtime.getNil();
// Validate the key type. We can't accept enums, messages, or floats/doubles
// as map keys. (We exclude these explicitly, and the field-descriptor setter
// below then ensures that the type is one of the remaining valid options.)
if (keyType.equals(RubySymbol.newSymbol(runtime, "float")) ||
keyType.equals(RubySymbol.newSymbol(runtime, "double")) ||
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.");
// Create a new message descriptor for the map entry message, and create a
// repeated submessage field here with that type.
RubyDescriptor mapentryDesc = (RubyDescriptor) cDescriptor.newInstance(context, Block.NULL_BLOCK);
IRubyObject mapentryDescName = RubySymbol.newSymbol(runtime, name).id2name(context);
mapentryDesc.setName(context, mapentryDescName);
mapentryDesc.setMapEntry(true);
//optional <type> key = 1;
RubyFieldDescriptor keyField = (RubyFieldDescriptor) cFieldDescriptor.newInstance(context, Block.NULL_BLOCK);
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);
//optional <type> value = 2;
RubyFieldDescriptor valueField = (RubyFieldDescriptor) cFieldDescriptor.newInstance(context, Block.NULL_BLOCK);
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);
// Add the map-entry message type to the current builder, and use the type to
// create the map field itself.
this.builder.pendingList.add(mapentryDesc);
msgdefAddField(context, "repeated", name, runtime.newSymbol("message"), number, mapentryDescName);
return runtime.getNil();
}
示例13: setField
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
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");
}
RubyMap thisMap = (RubyMap) getField(context, fieldDescriptor);
thisMap.mergeIntoSelf(context, value);
} else if (fieldDescriptor.isRepeated()) {
checkRepeatedFieldType(context, value, fieldDescriptor);
if (value instanceof RubyRepeatedField) {
addRepeatedField(fieldDescriptor, (RubyRepeatedField) value);
} else {
RubyArray ary = value.convertToArray();
RubyRepeatedField repeatedField = rubyToRepeatedField(context, fieldDescriptor, ary);
addRepeatedField(fieldDescriptor, repeatedField);
}
} else {
Descriptors.OneofDescriptor oneofDescriptor = fieldDescriptor.getContainingOneof();
if (oneofDescriptor != null) {
Descriptors.FieldDescriptor oneofCase = oneofCases.get(oneofDescriptor);
if (oneofCase != null && oneofCase != fieldDescriptor) {
fields.remove(oneofCase);
}
if (value.isNil()) {
oneofCases.remove(oneofDescriptor);
fields.remove(fieldDescriptor);
} else {
oneofCases.put(oneofDescriptor, fieldDescriptor);
fields.put(fieldDescriptor, value);
}
} else {
Descriptors.FieldDescriptor.Type fieldType = fieldDescriptor.getType();
IRubyObject typeClass = context.runtime.getObject();
boolean addValue = true;
if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE) {
typeClass = ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context);
if (value.isNil()){
addValue = false;
}
} else if (fieldType == Descriptors.FieldDescriptor.Type.ENUM) {
typeClass = ((RubyEnumDescriptor) getDescriptorForField(context, fieldDescriptor)).enummodule(context);
Descriptors.EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType();
if (Utils.isRubyNum(value)) {
Descriptors.EnumValueDescriptor val =
enumDescriptor.findValueByNumberCreatingIfUnknown(RubyNumeric.num2int(value));
if (val.getIndex() != -1) value = context.runtime.newSymbol(val.getName());
}
}
if (addValue) {
value = Utils.checkType(context, fieldType, value, (RubyModule) typeClass);
this.fields.put(fieldDescriptor, value);
} else {
this.fields.remove(fieldDescriptor);
}
}
}
return context.runtime.getNil();
}