Package railo.transformer.library.function

Examples of railo.transformer.library.function.FunctionLibFunctionArg


    Map<Key, FunctionLibFunction> members = getMembers(pc, type);
    FunctionLibFunction member=members.get(methodName);
   
    if(member!=null){
      List<FunctionLibFunctionArg> _args = member.getArg();
      FunctionLibFunctionArg arg;
      if(args.length<_args.size()){
        ArrayList<Ref> refs=new ArrayList<Ref>();
        refs.add(new Casting(strType,type,coll));
        for(int y=0;y<args.length;y++){
          arg = _args.get(y+1);
          refs.add(new Casting(arg.getTypeAsString(),arg.getType(),args[y]));
        }
        return new BIFCall(coll, member, refs.toArray(new Ref[refs.size()])).getValue(pc);
      }
     
    }
View Full Code Here


    Map<Key, FunctionLibFunction> members = getMembers(pc, type);
    FunctionLibFunction member=members.get(methodName);
   
    if(member!=null){
      List<FunctionLibFunctionArg> _args = member.getArg();
      FunctionLibFunctionArg arg;
      if(args.size()<_args.size()){
        Object val;
        ArrayList<Ref> refs=new ArrayList<Ref>();
        arg=_args.get(0);
        refs.add(new Casting(arg.getTypeAsString(),arg.getType(),new LFunctionValue(new LString(arg.getName()),coll)));
        for(int y=1;y<_args.size();y++){
          arg = _args.get(y);
         
          // match by name
          val = args.get(arg.getName(),null);
         
          //match by alias
          if(val==null) {
            String alias=arg.getAlias();
            if(!StringUtil.isEmpty(alias,true)) {
              String[] aliases = railo.runtime.type.util.ListUtil.trimItems(railo.runtime.type.util.ListUtil.listToStringArray(alias,','));
              for(int x=0;x<aliases.length;x++){
                val = args.get(aliases[x],null);
                if(val!=null) break;
              }
            }
          }
         
          if(val==null) {
            if(arg.getRequired()) {
              throw new ExpressionException("missing required argument ["+arg.getName()+"] for member function call ["+member.getMemberName()+"]");
            }
          }
          else{
            refs.add(new Casting(arg.getTypeAsString(),arg.getType(),new LFunctionValue(new LString(arg.getName()),val)));
            //refs.add(new LFunctionValue(new LString(arg.getName()),new Casting(pc,arg.getTypeAsString(),arg.getType(),val)));
          }
         
        }
        return new BIFCall(coll,member, refs.toArray(new Ref[refs.size()])).getValue(pc);
View Full Code Here

        Iterator<FunctionLibFunctionArg> it = list.iterator();
       
        argTypes=new Type[list.size()+1];
        argTypes[0]=Types.PAGE_CONTEXT;
       
        FunctionLibFunctionArg flfa;
        int index=0;
        VT vt;
        while(it.hasNext()) {
          flfa =it.next();
          vt = getMatchingValueAndType(flfa,nargs,names,line);
          if(vt.index!=-1)
            names[vt.index]=null;
          argTypes[++index]=Types.toType(vt.type);
          if(vt.value==null)ASMConstants.NULL(bc.getAdapter());
          else vt.value.writeOut(bc, Types.isPrimitiveType(argTypes[index])?MODE_VALUE:MODE_REF);
        }
       
        for(int y=0;y<names.length;y++){
          if(names[y]!=null) {
            BytecodeException bce = new BytecodeException("argument ["+names[y]+"] is not allowed for function ["+bif.getFlf().getName()+"]", args[y].getStart());
            UDFUtil.addFunctionDoc(bce, bif.getFlf());
            throw bce;
          }
        }
       
      }
      else{
        argTypes=new Type[args.length+1];
        argTypes[0]=Types.PAGE_CONTEXT;
       
       
        for(int y=0;y<args.length;y++) {
          argTypes[y+1]=Types.toType(args[y].getStringType());
          args[y].writeOutValue(bc, Types.isPrimitiveType(argTypes[y+1])?MODE_VALUE:MODE_REF);
        }
        // if no method exists for the exact match of arguments, call the method with all arguments (when exists)
        if(methodExists(bifClass,"call",argTypes,rtnType)==Boolean.FALSE) {
          ArrayList<FunctionLibFunctionArg> _args = bif.getFlf().getArg();
         
          Type[] tmp = new Type[_args.size()+1];
         
          // fill the existing
          for(int i=0;i<argTypes.length;i++){
            tmp[i]=argTypes[i];
          }
         
          // get the rest with default values
          FunctionLibFunctionArg flfa;
          for(int i=argTypes.length;i<tmp.length;i++){
            flfa = _args.get(i-1);
            tmp[i]=Types.toType(flfa.getTypeAsString());
            getDefaultValue(flfa).value.writeOut(
                bc,
                Types.isPrimitiveType(tmp[i])?MODE_VALUE:MODE_REF);
          }
          argTypes=tmp;
View Full Code Here

        FunctionLibFunction flf = new FunctionLibFunction(fl);
      flf.setArgType(FunctionLibFunction.ARG_DYNAMIC);
      flf.setCls("railo.runtime.functions.system.CFFunction");
      flf.setName(name);
      flf.setReturn("object");
      FunctionLibFunctionArg arg = new FunctionLibFunctionArg(flf);
        arg.setName("__filename");
        arg.setRequired(true);
        arg.setType("string");
        arg.setHidden(true);
        arg.setDefaultValue(filename);
        flf.setArg(arg);
       
        arg = new FunctionLibFunctionArg(flf);
        arg.setName("__name");
        arg.setRequired(true);
        arg.setHidden(true);
        arg.setType("string");
        arg.setDefaultValue(name);
        flf.setArg(arg);
       
        arg = new FunctionLibFunctionArg(flf);
        arg.setName("__isweb");
        arg.setRequired(true);
        arg.setHidden(true);
        arg.setType("boolean");
        arg.setDefaultValue(this instanceof ConfigWeb?"true":"false");
        flf.setArg(arg);
     
     
     
      fl.setFunction(flf);
View Full Code Here

      fm=bif;
     
      if(flf.getArgType()== FunctionLibFunction.ARG_DYNAMIC && flf.hasDefaultValues()){
            ArrayList<FunctionLibFunctionArg> args = flf.getArg();
        Iterator<FunctionLibFunctionArg> it = args.iterator();
            FunctionLibFunctionArg arg;
            while(it.hasNext()){
              arg=it.next();
              if(arg.getDefaultValue()!=null)
                bif.addArgument(
                    new NamedArgument(
                        LitString.toExprString(arg.getName()),
                        LitString.toExprString(arg.getDefaultValue()),
                        arg.getTypeAsString(),false
                        ));
            }
      }
    }
    else {
      fm = new UDF(name);
    }
   
   
   

    // Function Attributes
    ArrayList<FunctionLibFunctionArg> arrFuncLibAtt = null;
    int libLen = 0;
    if (checkLibrary) {
      arrFuncLibAtt = flf.getArg();
      libLen = arrFuncLibAtt.size();
    }
    int count = 0;
    do {
      data.cfml.next();
            comments(data);

      // finish
      if (count==0 && data.cfml.isCurrent(')'))
        break;

      // too many Attributes
      boolean isDynamic=false;
      int max=-1;
      if(checkLibrary) {
        isDynamic=flf.getArgType()==FunctionLibFunction.ARG_DYNAMIC;
        max=flf.getArgMax();
      // Dynamic
        if(isDynamic) {
          if(max!=-1 && max <= count)
            throw new TemplateException(
              data.cfml,
              "too many Attributes in function [" + ASMUtil.display(name) + "]");
        }
      // Fix
        else {
          if(libLen <= count){
           
            TemplateException te = new TemplateException(
              data.cfml,
              "too many Attributes in function call [" + ASMUtil.display(name) + "]");
            UDFUtil.addFunctionDoc(te, flf);
            throw te;
          }
        }
       
      }
     
      //Argument arg;
      if (checkLibrary && !isDynamic) {
        // current attribues from library
        FunctionLibFunctionArg funcLibAtt =arrFuncLibAtt.get(count);
        fm.addArgument(functionArgument(data,funcLibAtt.getTypeAsString(),false))
      }
      else {
        fm.addArgument(functionArgument(data,false));
      }
View Full Code Here

          arguments = RefUtil.getValue(pc,refArgs);
          if(flf.hasDefaultValues()){
            List<Object> tmp=new ArrayList<Object>();
            ArrayList<FunctionLibFunctionArg> args = flf.getArg();
            Iterator<FunctionLibFunctionArg> it = args.iterator();
            FunctionLibFunctionArg arg;
            while(it.hasNext()){
              arg=it.next();
              if(arg.getDefaultValue()!=null)
                tmp.add(new FunctionValueImpl(arg.getName(),arg.getDefaultValue()));
            }
            for(int i=0;i<arguments.length;i++){
              tmp.add(arguments[i]);
            }
            arguments=tmp.toArray();
          }
          arguments=new Object[]{arguments};
        }
        else {
          if(isNamed(pc,refArgs)){
            FunctionValue[] fvalues=getFunctionValues(pc,refArgs);
            String[] names = getNames(fvalues);
           
            ArrayList<FunctionLibFunctionArg> list = flf.getArg();
        Iterator<FunctionLibFunctionArg> it = list.iterator();
        arguments=new Object[list.size()];
       
       
        FunctionLibFunctionArg flfa;
        int index=0;
        VT vt;
        while(it.hasNext()) {
          flfa =it.next();
          vt = getMatchingValueAndType(flfa,fvalues,names);
View Full Code Here

            }

           
            if (checkLibrary && !isDynamic) {
                // current attribues from library
                FunctionLibFunctionArg funcLibAtt = (FunctionLibFunctionArg) arrFuncLibAtt.get(count);
                short type=CFTypes.toShort(funcLibAtt.getTypeAsString(),false,CFTypes.TYPE_UNKNOW);
                if(type==CFTypes.TYPE_VARIABLE_STRING) {
                    arr.add(functionArgDeclarationVarString());
                }
                else {
                  ref = functionArgDeclaration();
                  arr.add(new Casting(funcLibAtt.getTypeAsString(),type,ref));
                }
            }
            else {
                arr.add(functionArgDeclaration());
            }
View Full Code Here

   
    // Pattern
    StringBuilder pattern=new StringBuilder(flf.getName());
    StringBuilder end=new StringBuilder();
    pattern.append("(");
    FunctionLibFunctionArg arg;
    int c=0;
    while(it.hasNext()){
      arg = it.next();
      if(!arg.isRequired()) {
        pattern.append(" [");
        end.append("]");
      }
      if(c++>0)pattern.append(", ");
      pattern.append(arg.getName());
      pattern.append(":");
      pattern.append(arg.getTypeAsString());
     
    }
    pattern.append(end);
    pattern.append("):");
    pattern.append(flf.getReturnTypeAsString());
   
    pe.setAdditional(KeyConstants._Pattern, pattern);
   
    // Documentation
    StringBuilder doc=new StringBuilder(flf.getDescription());
    StringBuilder req=new StringBuilder();
    StringBuilder opt=new StringBuilder();
    StringBuilder tmp;
    doc.append("\n");
   
    it = args.iterator();
    while(it.hasNext()){
      arg = it.next();
      tmp=arg.isRequired()?req:opt;
     
      tmp.append("- ");
      tmp.append(arg.getName());
      tmp.append(" (");
      tmp.append(arg.getTypeAsString());
      tmp.append("): ");
      tmp.append(arg.getDescription());
      tmp.append("\n");
    }

    if(req.length()>0)doc.append("\nRequired:\n").append(req);
    if(opt.length()>0)doc.append("\nOptional:\n").append(opt);
View Full Code Here

    Array _args=new ArrayImpl();
    sct.set(KeyConstants._arguments,_args);
    if(function.getArgType()!=FunctionLibFunction.ARG_DYNAMIC){
      ArrayList<FunctionLibFunctionArg> args = function.getArg();
      for(int i=0;i<args.size();i++) {
        FunctionLibFunctionArg arg=args.get(i);
        Struct _arg=new StructImpl();
        _arg.set(KeyConstants._required,arg.getRequired()?Boolean.TRUE:Boolean.FALSE);
        _arg.set(KeyConstants._type,StringUtil.emptyIfNull(arg.getTypeAsString()));
        _arg.set(KeyConstants._name,StringUtil.emptyIfNull(arg.getName()));
        _arg.set(KeyConstants._status,TagLibFactory.toStatus(arg.getStatus()));
        _arg.set(KeyConstants._description,StringUtil.toStringEmptyIfNull(arg.getDescription()));
       
       
        _args.append(_arg);
      }
    }
View Full Code Here

   
   
    int optionals=0;
    ArrayList args = function.getArg();
    for(int i=0;i<args.size();i++) {
      FunctionLibFunctionArg arg=(FunctionLibFunctionArg) args.get(i);
      if(i!=0)rtn.append(", ");
      if(!arg.getRequired()) {
        rtn.append("[");
        optionals++;
      }
      rtn.append(arg.getName());
      rtn.append(":");
      rtn.append(arg.getTypeAsString());
    }
    for(int i=0;i<optionals;i++)
      rtn.append("]");
    rtn.append("):"+function.getReturnTypeAsString());
   
View Full Code Here

TOP

Related Classes of railo.transformer.library.function.FunctionLibFunctionArg

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.