public IRubyObject invokeDirect(ThreadContext context, Object javaInvokee, Object[] args) { checkArity(args.length); checkInstanceof(javaInvokee); if (mightBeProxy(javaInvokee)) { return tryProxyInvocation(context, javaInvokee, args); } return invokeDirectWithExceptionHandling(context, method, javaInvokee, args); }
@JRubyMethod(rest = true) public IRubyObject invoke_static(ThreadContext context, IRubyObject[] args) { checkArity(args.length); final Object[] arguments = convertArguments(args, 0); return invokeWithExceptionHandling(context, method, null, arguments); }
private IRubyObject invokeDirectWithExceptionHandling(ThreadContext context, Method method, Object javaInvokee, Object arg0, Object arg1, Object arg2, Object arg3) { try { Object result = method.invoke(javaInvokee, arg0, arg1, arg2, arg3); return convertReturn(result); } catch (IllegalArgumentException iae) { return handlelIllegalArgumentEx(iae, method, arg0, arg1, arg2, arg3); } catch (IllegalAccessException iae) { return handleIllegalAccessEx(iae, method); } catch (InvocationTargetException ite) { return handleInvocationTargetEx(context, ite); } catch (Throwable t) { return handleThrowable(context, t); } }
@JRubyMethod(rest = true) public IRubyObject invoke(IRubyObject[] args) { checkArity(args.length - 1); Object[] arguments = new Object[args.length - 1]; convertArguments(args, arguments, 1); return invokeWithExceptionHandling(method, null, arguments); if (!isStatic()) { javaInvokee = JavaUtil.unwrapJavaValue(getRuntime(), invokee, "invokee not a java object"); throw getRuntime().newTypeError("invokee not instance of method's class (" + "got" + javaInvokee.getClass().getName() + " wanted " + method.getDeclaringClass().getName() + ")"); if ((jpm = jpc.getMethod(method.getName(), parameterTypes)) != null && jpm.hasSuperImplementation()) { return invokeWithExceptionHandling(jpm.getSuperMethod(), javaInvokee, arguments); return invokeWithExceptionHandling(method, javaInvokee, arguments);
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) { if (javaVarargsCallables != null) return call(context, self, clazz, name, new IRubyObject[] {arg0, arg1}); JavaMethod method = (JavaMethod)findCallableArityTwo(self, name, arg0, arg1); final Class<?>[] paramTypes = method.getParameterTypes(); Object cArg0 = arg0.toJava(paramTypes[0]); Object cArg1 = arg1.toJava(paramTypes[1]); return method.invokeDirect(context, singleton, cArg0, cArg1); }
@JRubyMethod public IRubyObject java_send(ThreadContext context, IRubyObject rubyName) { String name = rubyName.asJavaString(); Ruby runtime = context.runtime; JavaMethod method = new JavaMethod(runtime, getMethod(context, name)); return method.invokeDirect(context, getObject()); }
@JRubyMethod(meta = true) public static IRubyObject java_send(ThreadContext context, IRubyObject recv, IRubyObject rubyName) { String name = rubyName.asJavaString(); final Ruby runtime = context.runtime; JavaMethod method = new JavaMethod(runtime, getMethodFromClass(context, recv, name)); return method.invokeStaticDirect(context); }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) { if (javaVarargsCallables != null) return call(context, self, clazz, name, new IRubyObject[] {arg0}); JavaMethod method = (JavaMethod) findCallableArityOne(self, name, arg0); if (method.isVarArgs()) return call(context, self, clazz, name, new IRubyObject[] {arg0}); final Class<?>[] paramTypes = method.getParameterTypes(); Object cArg0 = arg0.toJava(paramTypes[0]); return method.invokeDirect(context, singleton, cArg0); }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) { if (javaVarargsCallables != null) return call(context, self, clazz, name, new IRubyObject[] {arg0}); JavaMethod method = (JavaMethod) findCallableArityOne(self, name, arg0); if (method.isVarArgs()) return call(context, self, clazz, name, new IRubyObject[] {arg0}); final Class<?>[] paramTypes = method.getParameterTypes(); Object cArg0 = arg0.toJava(paramTypes[0]); return method.invokeStaticDirect(context, cArg0); }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) { if (javaVarargsCallables != null) return call(context, self, clazz, name, new IRubyObject[] {arg0, arg1}); JavaMethod method = (JavaMethod) findCallableArityTwo(self, name, arg0, arg1); final Class<?>[] paramTypes = method.getParameterTypes(); Object cArg0 = arg0.toJava(paramTypes[0]); Object cArg1 = arg1.toJava(paramTypes[1]); return method.invokeStaticDirect(context, cArg0, cArg1); }
protected JavaCallable createCallable(Ruby ruby, Member member) { return JavaMethod.create(ruby, (Method)member); }
@JRubyMethod public RubyString inspect() { StringBuilder str = new StringBuilder(); str.append("#<"); str.append( getType().toString() ).append('/').append(method.getName()); inspectParameterTypes(str, this); str.append('>'); return RubyString.newString(getRuntime(), str); }
private void checkInstanceof(Object javaInvokee) throws RaiseException { if (!method.getDeclaringClass().isInstance(javaInvokee)) { throw getRuntime().newTypeError("invokee not instance of method's class (" + "got" + javaInvokee.getClass().getName() + " wanted " + method.getDeclaringClass().getName() + ")"); } }
public static JavaCallable getMatchingCallable(Ruby runtime, Class<?> javaClass, String methodName, Class<?>[] argumentTypes) { if ( methodName.length() == 6 && "<init>".equals(methodName) ) { return JavaConstructor.getMatchingConstructor(runtime, javaClass, argumentTypes); } // FIXME: do we really want 'declared' methods? includes private/protected, and does _not_ // include superclass methods return JavaMethod.getMatchingDeclaredMethod(runtime, javaClass, methodName, argumentTypes); }
private RubyArray toJavaMethods(final Method[] methods, final boolean isStatic) { final Ruby runtime = getRuntime(); final RubyArray result = runtime.newArray(methods.length); for ( int i = 0; i < methods.length; i++ ) { final Method method = methods[i]; if ( isStatic == Modifier.isStatic(method.getModifiers()) ) { result.append( new JavaMethod(runtime, method) ); } } return result; }
JavaArray.createJavaArrayClass(runtime, javaModule); JavaClass.createJavaClassClass(runtime, javaModule); JavaMethod.createJavaMethodClass(runtime, javaModule); JavaConstructor.createJavaConstructorClass(runtime, javaModule); JavaField.createJavaFieldClass(runtime, javaModule);
@JRubyMethod(rest = true) public IRubyObject invoke(IRubyObject[] args) { checkArity(args.length - 1); Object[] arguments = new Object[args.length - 1]; convertArguments(args, arguments, 1); return invokeWithExceptionHandling(method, null, arguments); if (!isStatic()) { javaInvokee = JavaUtil.unwrapJavaValue(getRuntime(), invokee, "invokee not a java object"); throw getRuntime().newTypeError("invokee not instance of method's class (" + "got" + javaInvokee.getClass().getName() + " wanted " + method.getDeclaringClass().getName() + ")"); if ((jpm = jpc.getMethod(method.getName(), parameterTypes)) != null && jpm.hasSuperImplementation()) { return invokeWithExceptionHandling(jpm.getSuperMethod(), javaInvokee, arguments); return invokeWithExceptionHandling(method, javaInvokee, arguments);
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) { if (javaVarargsCallables != null) return call(context, self, clazz, name, new IRubyObject[] {arg0, arg1, arg2}); JavaMethod method = (JavaMethod) findCallableArityThree(self, name, arg0, arg1, arg2); final Class<?>[] paramTypes = method.getParameterTypes(); Object cArg0 = arg0.toJava(paramTypes[0]); Object cArg1 = arg1.toJava(paramTypes[1]); Object cArg2 = arg2.toJava(paramTypes[2]); return method.invokeDirect(context, singleton, cArg0, cArg1, cArg2); }
@JRubyMethod public IRubyObject java_send(ThreadContext context, IRubyObject rubyName) { String name = rubyName.asJavaString(); Ruby runtime = context.runtime; JavaMethod method = new JavaMethod(runtime, getMethod(context, name)); return method.invokeDirect(context, getObject()); }
@JRubyMethod(meta = true) public static IRubyObject java_send(ThreadContext context, IRubyObject recv, IRubyObject rubyName) { String name = rubyName.asJavaString(); final Ruby runtime = context.runtime; JavaMethod method = new JavaMethod(runtime, getMethodFromClass(context, recv, name)); return method.invokeStaticDirect(context); }