001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.intergral.fusiondebug.server.type.coll; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import lucee.commons.lang.StringUtil; 025import lucee.intergral.fusiondebug.server.type.FDValueNotMutability; 026import lucee.intergral.fusiondebug.server.type.simple.FDSimpleVariable; 027import lucee.runtime.op.Caster; 028import lucee.runtime.type.FunctionArgument; 029import lucee.runtime.type.UDF; 030import lucee.runtime.type.util.UDFUtil; 031 032import com.intergral.fusiondebug.server.IFDStackFrame; 033 034public class FDUDF extends FDValueNotMutability { 035 036 private ArrayList children=new ArrayList(); 037 private String name; 038 private UDF udf; 039 040 /** 041 * Constructor of the class 042 * @param name 043 * @param coll 044 */ 045 public FDUDF(IFDStackFrame frame, String name, UDF udf) { 046 this.name=name; 047 this.udf=udf; 048 049 // meta 050 List<FDSimpleVariable> list=new ArrayList<FDSimpleVariable>(); 051 children.add(new FDSimpleVariable(frame,"Meta Data","",list)); 052 list.add(new FDSimpleVariable(frame,"Function Name",udf.getFunctionName(),null)); 053 if(!StringUtil.isEmpty(udf.getDisplayName())) 054 list.add(new FDSimpleVariable(frame,"Display Name",udf.getDisplayName(),null)); 055 if(!StringUtil.isEmpty(udf.getDescription())) 056 list.add(new FDSimpleVariable(frame,"Description",udf.getDescription(),null)); 057 if(!StringUtil.isEmpty(udf.getHint())) 058 list.add(new FDSimpleVariable(frame,"Hint",udf.getHint(),null)); 059 list.add(new FDSimpleVariable(frame,"Return Type",udf.getReturnTypeAsString(),null)); 060 list.add(new FDSimpleVariable(frame,"Return Format",UDFUtil.toReturnFormat(udf.getReturnFormat(),"plain"),null)); 061 list.add(new FDSimpleVariable(frame,"Source",Caster.toString(udf.getPageSource().getDisplayPath()),null)); 062 list.add(new FDSimpleVariable(frame,"Secure Json",Caster.toString(udf.getSecureJson(),""),null)); 063 list.add(new FDSimpleVariable(frame,"Verify Client",Caster.toString(udf.getVerifyClient(),""),null)); 064 065 // arguments 066 list=new ArrayList(); 067 List el; 068 children.add(new FDSimpleVariable(frame,"Arguments","",list)); 069 FunctionArgument[] args = udf.getFunctionArguments(); 070 for(int i=0;i<args.length;i++){ 071 el=new ArrayList(); 072 list.add(new FDSimpleVariable(frame,"["+(i+1)+"]","",el)); 073 el.add(new FDSimpleVariable(frame,"Name",args[i].getName().getString(),null)); 074 el.add(new FDSimpleVariable(frame,"Type",args[i].getTypeAsString(),null)); 075 el.add(new FDSimpleVariable(frame,"Required",Caster.toString(args[i].isRequired()),null)); 076 077 if(!StringUtil.isEmpty(args[i].getDisplayName())) 078 el.add(new FDSimpleVariable(frame,"Display Name",args[i].getDisplayName(),null)); 079 if(!StringUtil.isEmpty(args[i].getHint())) 080 el.add(new FDSimpleVariable(frame,"Hint",args[i].getHint(),null)); 081 } 082 083 // return 084 children.add(new FDSimpleVariable(frame,"return",udf.getReturnTypeAsString(),null)); 085 } 086 087 @Override 088 public List getChildren() { 089 return children; 090 } 091 092 public String getName() { 093 return name; 094 } 095 096 @Override 097 public boolean hasChildren() { 098 return true; 099 } 100 101 @Override 102 public String toString() { 103 return toString(udf); 104 } 105 public static String toString(UDF udf) { 106 FunctionArgument[] args = udf.getFunctionArguments(); 107 StringBuffer sb=new StringBuffer("function "); 108 sb.append(udf.getFunctionName()); 109 sb.append("("); 110 for(int i=0;i<args.length;i++){ 111 if(i>0)sb.append(", "); 112 sb.append(args[i].getTypeAsString()); 113 sb.append(" "); 114 sb.append(args[i].getName()); 115 } 116 sb.append("):"); 117 sb.append(udf.getReturnTypeAsString()); 118 119 return sb.toString(); 120 } 121}