Examples of Arity


Examples of org.jruby.runtime.Arity

            return getMetaClass().isMethodBound(name, false);
        } else if (!method.isUndefined()) {
            // medium path, invoke user's respond_to? if defined

            // We have to check and enforce arity
            Arity arity = method.getArity();
            ThreadContext context = runtime.getCurrentContext();
            if (arity.isFixed() && arity.required() == 1) {
                return method.call(context, this, metaClass, "respond_to?", runtime.newSymbol(name)).isTrue();
            } else if (arity.isFixed() && arity.required() != 2) {
                throw runtime.newArgumentError("respond_to? must accept 1 or 2 arguments (requires " + arity.getValue() + ")");
            } else {

            }

            return method.call(context, this, metaClass, "respond_to?", runtime.newSymbol(name), runtime.newBoolean(true)).isTrue();
View Full Code Here

Examples of org.jruby.runtime.Arity

       
        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

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.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

Examples of org.jruby.truffle.runtime.methods.Arity

            optional = 0;
        } else {
            optional = methodDetails.getMethodAnnotation().optional();
        }

        final Arity arity = new Arity(required,  optional, methodDetails.getMethodAnnotation().argumentsAsArray());

        final List<RubyNode> argumentsNodes = new ArrayList<>();

        if (needsSelf) {
            RubyNode readSelfNode = new SelfNode(context, sourceSection);

            if (methodDetails.getMethodAnnotation().lowerFixnumSelf()) {
                readSelfNode = new FixnumLowerNode(readSelfNode);
            }

            argumentsNodes.add(readSelfNode);
        }

        if (methodDetails.getMethodAnnotation().argumentsAsArray()) {
            argumentsNodes.add(new ReadAllArgumentsNode(context, sourceSection));
        } else {
            for (int n = 0; n < arity.getRequired() + arity.getOptional(); n++) {
                RubyNode readArgumentNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehaviour.UNDEFINED);

                if (ArrayUtils.contains(methodDetails.getMethodAnnotation().lowerFixnumParameters(), n)) {
                    readArgumentNode = new FixnumLowerNode(readArgumentNode);
                }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.Arity

          return makeResult(type, getValue().asRelation().closure(), ctx);
        } catch (IllegalOperationException e){
          throw new UnsupportedOperation("Illegal argument of transitive closure (+)", ctx.getCurrentAST());
        }
      }
      throw new Arity(2, getValue().asRelation().arity(), ctx.getCurrentAST());
    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.Arity

          return makeResult(type, getValue().asRelation().closureStar(), ctx);
        } catch (IllegalOperationException e){
          throw new UnsupportedOperation("Illegal argument of reflexive transitive closure (*)", ctx.getCurrentAST());
        }
      }
      throw new Arity(2, getValue().asRelation().arity(), ctx.getCurrentAST());
    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.Arity

      Type rightrelType = right.getType();
      int leftArity = leftrelType.getArity();
      int rightArity = rightrelType.getArity();
       
      if (leftArity != 0 && leftArity != 2) {
        throw new Arity(2, leftArity, ctx.getCurrentAST());
      }
       
      if (rightArity != 0 && rightArity != 2) {
        throw new Arity(2, rightArity, ctx.getCurrentAST());
      }
      Type resultType = leftrelType.compose(rightrelType);
      return makeResult(resultType, left.getValue().asRelation().compose(right.getValue().asRelation()), ctx);
    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.Arity

    @Override
    public  <U extends IValue> Result<U> transitiveClosure() {
      if (getValue().asRelation().arity() == 0 || getValue().asRelation().arity() == 2) {
        return makeResult(type, getValue().asRelation().closure(), ctx);
      }
      throw new Arity(2, getValue().asRelation().arity(), ctx.getCurrentAST());
    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.Arity

    @Override
    public  <U extends IValue> Result<U> transitiveReflexiveClosure() {
      if (getValue().asRelation().arity() == 0 || getValue().asRelation().arity() == 2) {
        return makeResult(type, getValue().asRelation().closureStar(), ctx);
      }
      throw new Arity(2, getValue().asRelation().arity(), ctx.getCurrentAST());
    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.Arity

      Type rightrelType = right.getType();
      int leftArity = leftrelType.getArity();
      int rightArity = rightrelType.getArity();
       
      if (leftArity != 0 && leftArity != 2) {
        throw new Arity(2, leftArity, ctx.getCurrentAST());
      }
       
      if (rightArity != 0 && rightArity != 2) {
        throw new Arity(2, rightArity, ctx.getCurrentAST());
      }
      Type resultType = leftrelType.compose(rightrelType);
      return makeResult(resultType, left.getValue().asRelation().compose(right.getValue().asRelation()), ctx);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.