Package org.jruby.runtime

Examples of org.jruby.runtime.Arity


        StaticScope scope = block.getBody().getStaticScope();

        // for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope
        scope.setArgumentScope(true);

        Arity arity = block.arity();
        // just using required is broken...but no more broken than before zsuper refactoring
        scope.setRequiredArgs(arity.required());

        if(!arity.isFixed()) {
            scope.setRestArg(arity.required());
        }

        return new ProcMethod(this, proc, visibility);
    }
View Full Code Here


       
        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;
View Full Code Here

        }
    }

    public void addInvokerDescriptor(String newMethodName, int methodArity, StaticScope scope, CallConfiguration callConfig, String filename, int line) {
        String classPath = classname.replaceAll("/", "_");
        Arity arity = Arity.createArity(methodArity);
        String invokerName = classPath + "Invoker" + newMethodName + arity;
        InvokerDescriptor descriptor = new InvokerDescriptor(newMethodName, classname, invokerName, arity, scope, callConfig, filename, line);

        invokerDescriptors.add(descriptor);
    }
View Full Code Here

        StaticScope scope = block.getBody().getStaticScope();

        // for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope
        scope.makeArgumentScope();

        Arity arity = block.arity();
        // just using required is broken...but no more broken than before zsuper refactoring
        scope.setRequiredArgs(arity.required());

        if(!arity.isFixed()) {
            scope.setRestArg(arity.required());
        }

        return new ProcMethod(this, proc, visibility);
    }
View Full Code Here

       
        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;
View Full Code Here

        StaticScope scope = block.getBody().getStaticScope();

        // for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope
        scope.makeArgumentScope();

        Arity arity = block.arity();
        // just using required is broken...but no more broken than before zsuper refactoring
        scope.setRequiredArgs(arity.required());

        if(!arity.isFixed()) {
            scope.setRestArg(arity.required());
        }

        return new ProcMethod(this, proc, visibility);
    }
View Full Code Here

    public IRubyObject call(ThreadContext context, IRubyObject[] args) {
        return call(context, args, null, Block.NULL_BLOCK);
    }
   
    private IRubyObject[] prepareProcArgs(ThreadContext context, IRubyObject[] args) {
        Arity arity = block.arity();
       
        // for procs and blocks, single array passed to multi-arg must be spread
        if (arity != Arity.ONE_ARGUMENT && arity.required() != 0 &&
                (arity.isFixed() || arity != Arity.OPTIONAL) &&
                args.length == 1 && args[0].respondsTo("to_ary")) {
            args = args[0].convertToArray().toJavaArray();
        }

        if (arity.isFixed()) {
            List<IRubyObject> list = new ArrayList<IRubyObject>(Arrays.asList(args));
            int required = arity.required();
            if (required > args.length) {
                for (int i = args.length; i < required; i++) {
                    list.add(context.runtime.getNil());
                }
                args = list.toArray(args);
View Full Code Here

       
        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;
View Full Code Here

            return line;
        }
    }

    public void addInvokerDescriptor(String newMethodName, int methodArity, StaticScope scope, CallConfiguration callConfig, String filename, int line) {
        Arity arity = Arity.createArity(methodArity);
        InvokerDescriptor descriptor = new InvokerDescriptor(newMethodName, classname, arity, scope, callConfig, filename, line);

        invokerDescriptors.add(descriptor);
    }
View Full Code Here

        DynamicMethod me = klass.searchMethod("respond_to?");

        // NOTE: isBuiltin here would be NOEX_BASIC in MRI, a flag only added to respond_to?, method_missing, and
        //       respond_to_missing? Same effect, I believe.
        if (me != null && !me.isUndefined() && !me.isBuiltin()) {
            Arity arity = me.getArity();

            if (arity.getValue() > 2)
                throw runtime.newArgumentError("respond_to? must accept 1 or 2 arguments (requires " + arity + ")");

            IRubyObject result = me.call(context, recv, klass, "respond_to?", runtime.newString(mid), runtime.getTrue());
            if (!result.isTrue()) {
                return false;
View Full Code Here

TOP

Related Classes of org.jruby.runtime.Arity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.