@Override // method_missing impl public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) { Arity.checkArgumentCount(context.runtime, name, args.length, 1, -1); return callImpl(context, clazz, block, args); }
public void init(RubyModule implementationClass, Arity arity, Visibility visibility, StaticScope staticScope, CallConfiguration callConfig) { this.staticScope = staticScope; this.arity = arity; this.arityValue = arity.getValue(); super.init(implementationClass, visibility, callConfig); }
private static Arity newArity(int value) { Arity result; synchronized (arities) { result = arities.get(value); if (result == null) { result = new Arity(value); arities.put(value, result); } } return result; }
public ReflectedJavaMethod( RubyModule implementationClass, Method method, JRubyMethod annotation) { super(implementationClass, annotation.visibility()); this.method = method; Class<?>[] params = method.getParameterTypes(); this.needsBlock = params.length > 0 && params[params.length - 1] == Block.class; this.isStatic = Modifier.isStatic(method.getModifiers()); Arity arity = Arity.fromAnnotation(annotation, params, this.isStatic); setArity(arity); this.required = arity.getValue() >= 0 ? arity.getValue() : Math.abs(arity.getValue())-1; this.optional = annotation.optional(); this.rest = annotation.rest(); this.needsThreadContext = params.length > 0 && params[0] == ThreadContext.class; this.argsAsIs = ! isStatic && optional == 0 && !rest && !needsBlock && !needsThreadContext; if (rest) { max = -1; } else { max = required + optional; } }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) { ARITY.checkArity(context.runtime, args); return nullPointer; }
private Arity calculateArity() { StaticScope s = scope; if (s.getOptionalArgs() > 0 || s.getRestArg() >= 0) return Arity.required(s.getRequiredArgs()); return Arity.createArity(s.getRequiredArgs()); }
public void addInvokerDescriptor(String rubyName, String newMethodName, int methodArity, StaticScope scope, CallConfiguration callConfig, String filename, int line) { Arity arity = Arity.createArity(methodArity); InvokerDescriptor descriptor = new InvokerDescriptor(rubyName, newMethodName, classname, arity, scope, callConfig, filename, line); invokerDescriptors.add(descriptor); }
/** * Creates a new <tt>AbstractInvoker</tt> instance. * @param arity */ protected AbstractInvoker(Ruby runtime, RubyClass klass, int arity, MemoryIO io) { super(runtime, klass, io, 0); this.arity = Arity.fixed(arity); }
/** * Zero arguments... */ public Arity getArity() { return Arity.noArguments(); }
public static Arity createArity(int value) { switch (value) { case -4: return THREE_REQUIRED; case -3: return TWO_REQUIRED; case -2: return ONE_REQUIRED; case -1: return OPTIONAL; case 0: return NO_ARGUMENTS; case 1: return ONE_ARGUMENT; case 2: return TWO_ARGUMENTS; case 3: return THREE_ARGUMENTS; } return newArity(value); }
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ public void prepareAnnotatedMethod(RubyModule implementationClass, JavaMethod javaMethod, JavaMethodDescriptor desc) { String javaMethodName = desc.name; javaMethod.setArity(Arity.fromAnnotation(desc.anno, desc.actualRequired)); javaMethod.setJavaName(javaMethodName); javaMethod.setSingleton(desc.isStatic); javaMethod.setCallConfig(CallConfiguration.getCallConfigByAnno(desc.anno)); }
public ReflectedJavaMethod( RubyModule implementationClass, Method method, JRubyMethod annotation) { super(implementationClass, annotation.visibility()); this.method = method; Class<?>[] params = method.getParameterTypes(); this.needsBlock = params.length > 0 && params[params.length - 1] == Block.class; this.isStatic = Modifier.isStatic(method.getModifiers()); Arity arity = Arity.fromAnnotation(annotation, params, this.isStatic); setArity(arity); this.required = arity.getValue() >= 0 ? arity.getValue() : Math.abs(arity.getValue())-1; this.optional = annotation.optional(); this.rest = annotation.rest(); this.needsThreadContext = params.length > 0 && params[0] == ThreadContext.class; this.argsAsIs = ! isStatic && optional == 0 && !rest && !needsBlock && !needsThreadContext; if (rest) { max = -1; } else { max = required + optional; } }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) { ARITY.checkArity(context.runtime, args); return nullPointer; }
private Arity calculateArity() { StaticScope s = method.getStaticScope(); if (s.getOptionalArgs() > 0 || s.getRestArg() >= 0) return Arity.required(s.getRequiredArgs()); return Arity.createArity(s.getRequiredArgs()); }
public static Block createSharedScopeBlock(ThreadContext context, IRubyObject self, int arity, CompiledBlockCallback callback, boolean hasMultipleArgsHead, int argsNodeType) { return CompiledSharedScopeBlock.newCompiledSharedScopeClosure(context, self, Arity.createArity(arity), context.getCurrentScope(), callback, hasMultipleArgsHead, argsNodeType); }
/** * Creates a new <tt>AbstractInvoker</tt> instance. * @param arity */ protected AbstractInvoker(Ruby runtime, RubyClass klass, int arity, MemoryIO io) { super(runtime, klass, io, 0); this.arity = Arity.fixed(arity); }