@JIT @Interp public static IRubyObject isDefinedInstanceVar(ThreadContext context, IRubyObject receiver, String name, IRubyObject definedMessage) { return receiver.getInstanceVariables().hasInstanceVariable(name) ? definedMessage : context.nil; }
@JIT @Interp public static IRubyObject isDefinedInstanceVar(ThreadContext context, IRubyObject receiver, String name, IRubyObject definedMessage) { return receiver.getInstanceVariables().hasInstanceVariable(name) ? definedMessage : context.nil; }
private static boolean initInterfaceModules(final IRubyObject self, final IRubyObject module) { if ( ! module.getInstanceVariables().hasInstanceVariable("@java_interface_mods") ) { final RubyArray interfaceMods = RubyArray.newArray(self.getRuntime(), self); module.getInstanceVariables().setInstanceVariable("@java_interface_mods", interfaceMods); return true; } return false; }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) { IRubyObject receiver = (IRubyObject) getObject().retrieve(context, self, currDynScope, temp); return context.runtime.newBoolean(receiver.getInstanceVariables().hasInstanceVariable(getName().string)); }
private static boolean initInterfaceModules(final IRubyObject self, final IRubyObject module) { if ( ! module.getInstanceVariables().hasInstanceVariable("@java_interface_mods") ) { final RubyArray interfaceMods = RubyArray.newArray(self.getRuntime(), self); module.getInstanceVariables().setInstanceVariable("@java_interface_mods", interfaceMods); return true; } return false; }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) { IRubyObject receiver = (IRubyObject) getObject().retrieve(context, self, currDynScope, temp); return context.runtime.newBoolean(receiver.getInstanceVariables().hasInstanceVariable(getName().string)); }
if (!ancestor.getInstanceVariables().hasInstanceVariable("@java_proxy_class")) { skipRemainingClasses = true; continue;
if (!ancestor.getInstanceVariables().hasInstanceVariable("@java_proxy_class")) { skipRemainingClasses = true; continue;
private boolean exceptionHandled(ThreadContext context, IRubyObject excType, Object excObj) { Ruby runtime = context.runtime; if (excObj instanceof IRubyObject) { // regular ruby exception if (!(excType instanceof RubyModule)) throw runtime.newTypeError("class or module required for rescue clause. Found: " + excType); return excType.callMethod(context, "===", (IRubyObject)excObj).isTrue(); } else if (runtime.getException().op_ge(excType).isTrue() || runtime.getObject() == excType) { // convert java obj to a ruby object and try again return excType.callMethod(context, "===", JavaUtil.convertJavaToUsableRubyObject(runtime, excObj)).isTrue(); } else if (excType instanceof RubyClass && excType.getInstanceVariables().hasInstanceVariable("@java_class")) { // java exception where the rescue clause has an embedded java class that could catch it RubyClass rubyClass = (RubyClass)excType; JavaClass javaClass = (JavaClass)rubyClass.getInstanceVariable("@java_class"); if (javaClass != null) { Class cls = javaClass.javaClass(); if (cls.isInstance(excObj)) return true; } } return false; }
private boolean exceptionHandled(ThreadContext context, IRubyObject excType, Object excObj) { Ruby runtime = context.runtime; if (excObj instanceof IRubyObject) { // regular ruby exception if (!(excType instanceof RubyModule)) throw runtime.newTypeError("class or module required for rescue clause. Found: " + excType); return excType.callMethod(context, "===", (IRubyObject)excObj).isTrue(); } else if (runtime.getException().op_ge(excType).isTrue() || runtime.getObject() == excType) { // convert java obj to a ruby object and try again return excType.callMethod(context, "===", JavaUtil.convertJavaToUsableRubyObject(runtime, excObj)).isTrue(); } else if (excType instanceof RubyClass && excType.getInstanceVariables().hasInstanceVariable("@java_class")) { // java exception where the rescue clause has an embedded java class that could catch it RubyClass rubyClass = (RubyClass)excType; JavaClass javaClass = (JavaClass)rubyClass.getInstanceVariable("@java_class"); if (javaClass != null) { Class cls = javaClass.javaClass(); if (cls.isInstance(excObj)) return true; } } return false; }
if (module.getInstanceVariables().hasInstanceVariable("@java_class") && module.getInstanceVariables().getInstanceVariable("@java_class").isTrue()) { throw runtime.newTypeError("can not add Java interface to existing Java interface"); if (!module.getInstanceVariables().hasInstanceVariable("@java_interface_mods")) { RubyArray javaInterfaceMods = RubyArray.newArray(runtime, self); module.getInstanceVariables().setInstanceVariable("@java_interface_mods", javaInterfaceMods);
if (module.getInstanceVariables().hasInstanceVariable("@java_class") && module.getInstanceVariables().getInstanceVariable("@java_class").isTrue()) { throw runtime.newTypeError("can not add Java interface to existing Java interface"); if (!module.getInstanceVariables().hasInstanceVariable("@java_interface_mods")) { RubyArray javaInterfaceMods = RubyArray.newArray(runtime, self); module.getInstanceVariables().setInstanceVariable("@java_interface_mods", javaInterfaceMods);
if (!ancestor.getInstanceVariables().hasInstanceVariable("@java_proxy_class")) { skipRemainingClasses = true; continue;
if (!ancestor.getInstanceVariables().hasInstanceVariable("@java_proxy_class")) { skipRemainingClasses = true; continue;
private static boolean checkJavaException(Throwable throwable, IRubyObject catchable, ThreadContext context) { Ruby runtime = context.runtime; if ( // rescue exception needs to catch Java exceptions runtime.getException() == catchable || // rescue Object needs to catch Java exceptions runtime.getObject() == catchable || // rescue StandardError needs t= catch Java exceptions runtime.getStandardError() == catchable) { if (throwable instanceof RaiseException) { return isExceptionHandled(((RaiseException)throwable).getException(), catchable, context).isTrue(); } // let Ruby exceptions decide if they handle it return isExceptionHandled(JavaUtil.convertJavaToUsableRubyObject(runtime, throwable), catchable, context).isTrue(); } else if (runtime.getNativeException() == catchable) { // NativeException catches Java exceptions, lazily creating the wrapper return true; } else if (catchable instanceof RubyClass && catchable.getInstanceVariables().hasInstanceVariable("@java_class")) { RubyClass rubyClass = (RubyClass)catchable; JavaClass javaClass = (JavaClass)rubyClass.getInstanceVariable("@java_class"); if (javaClass != null) { Class cls = javaClass.javaClass(); if (cls.isInstance(throwable)) { return true; } } } return false; }
private static boolean checkJavaException(Throwable throwable, IRubyObject catchable, ThreadContext context) { Ruby runtime = context.runtime; if ( // rescue exception needs to catch Java exceptions runtime.getException() == catchable || // rescue Object needs to catch Java exceptions runtime.getObject() == catchable || // rescue StandardError needs t= catch Java exceptions runtime.getStandardError() == catchable) { if (throwable instanceof RaiseException) { return isExceptionHandled(((RaiseException)throwable).getException(), catchable, context).isTrue(); } // let Ruby exceptions decide if they handle it return isExceptionHandled(JavaUtil.convertJavaToUsableRubyObject(runtime, throwable), catchable, context).isTrue(); } else if (runtime.getNativeException() == catchable) { // NativeException catches Java exceptions, lazily creating the wrapper return true; } else if (catchable instanceof RubyClass && catchable.getInstanceVariables().hasInstanceVariable("@java_class")) { RubyClass rubyClass = (RubyClass)catchable; JavaClass javaClass = (JavaClass)rubyClass.getInstanceVariable("@java_class"); if (javaClass != null) { Class cls = javaClass.javaClass(); if (cls.isInstance(throwable)) { return true; } } } return false; }