public static int GetNoParams(FunctionExpression func) { if (func.getParams() == null) { return(0); } return(func.getParams().Count); }
public static bool IsVoidFunc(FunctionExpression func) { if (func.getReturnDescription() == null || func.getReturnDescription().Equals(VOID, StringComparison.OrdinalIgnoreCase)) { return(true); } return(false); }
public override ScriptsExpression HandleAndGenScripts(IScriptGenerationParams scriptGenerationParams, ScriptType scriptType = ScriptType.Normal) { string re = GetComment(scriptGenerationParams) + NEW_LINE; if (scriptGenerationParams is ValidationUCScriptGenerationParams param) { string newFunctionContent = ""; if (param.SpecNode.Attribute == null || param.SpecNode.Attribute == "") { param.SpecNode.Attribute = TEXT; } foreach (string exp in param.ListExps) { if (newFunctionContent != "") { newFunctionContent += NEW_LINE; } if (scriptType == ScriptType.Normal) { newFunctionContent += ValidationSpecUserAction.GetRawScripts(param, exp).Expression; } else if (scriptType == ScriptType.Ranorex) { newFunctionContent += ValidationSpecUserAction.GetRawRanorexScripts(param as IRanorexScriptGenerationParams, exp).Expression; } } string newClassName = param.ClassName; string newFuncName = param.FunctionName; re += newClassName + "." + newFuncName + "();"; var pair = CheckFunctionExisted(param.ClassExpressions, newClassName, newFuncName, 0, true); // if not existed if (!pair.Item1) { FunctionExpression func = new FunctionExpression(newFuncName); func.setContent(newFunctionContent); UserCodeScriptsExpression re1 = new UserCodeScriptsExpression(re); re1.MapClassAndFuncsAddition = new Dictionary <string, List <FunctionExpression> > { { newClassName, new List <FunctionExpression>() { func } } }; return(re1); } return(new ScriptsExpression(re)); } else { re += ValidationSpecUserAction.GetRawScripts(scriptGenerationParams, this.Expression).Expression; return(new ScriptsExpression(re)); } }
public static void MergeFunctions(List <FunctionExpression> functions, FunctionExpression func2) { if (functions == null) { functions = new List <FunctionExpression> { func2 }; return; } if (functions.Contains(func2)) { return; } functions.Add(func2); }
public void AppendNewAdditionFunc(string className, FunctionExpression func) { if (mapClassAndFuncsAddition == null) { mapClassAndFuncsAddition = new Dictionary <string, List <FunctionExpression> >(); } if (mapClassAndFuncsAddition.ContainsKey(className)) { Utils.MergeFunctions(mapClassAndFuncsAddition[className], func); } else { mapClassAndFuncsAddition.Add(className, new List <FunctionExpression> { func }); } }
public bool Equals(object other) { if (!(other is FunctionExpression)) { return(false); } FunctionExpression other1 = (FunctionExpression)other; if (!this.name.Equals(other1.name)) { return(false); } if (GetNoParams(this) != GetNoParams(other1)) { return(false); } if (IsVoidFunc(this) != IsVoidFunc(other1)) { return(false); } return(true); }
public List <ClassExpression> parse(FunctionDescriptionSheet funcSheet, MyLog myLog) { // parseOneFile title row Excel.Range xlRange = funcSheet.getSheet().UsedRange; int rowCount = xlRange.Rows.Count; int columnCount = xlRange.Columns.Count; Excel.Range firstRow = funcSheet.getSheet().Rows[1]; setColumnIndex(firstRow, myLog, ref columnCount); if (columnCount < 0) { return(null); } List <ClassExpression> classExpressions = new List <ClassExpression>(); ClassExpression classExpression = new ClassExpression(); for (int fi = 2; fi <= rowCount; fi++) { Excel.Range row = funcSheet.getSheet().Rows[fi]; string funcName = getValueCell(row, FUNCTION_NAME_COLUMN_INDEX); // indicate end sheet if (funcName == null || funcName.Equals("")) { break; } string workspace = getValueCell(row, WORKSPACE_COLUMN_INDEX); string _class = getValueCell(row, CLASS_COLUMN_INDEX); string accessibility = getValueCell(row, ACCESSIBILITY_COLUMN_INDEX); string summary = getValueCell(row, SUMMARY_COLUMN_INDEX); string parameters = getValueCell(row, PARAMETERS_COLUMN_INDEX); string _returns = getValueCell(row, RETURNS_COLUMN_INDEX); string implementation = getValueCell(row, IMPLEMENTATION_COLUMN_INDEX); string last_workspace = workspace == null || workspace.Equals("") ? classExpression.getWorkspace() : workspace; string last_class = _class == null || _class.Equals("") ? classExpression.getName() : _class; if (last_workspace == null || last_workspace.Equals("")) { myLog.Warn("Not know workspace for row #" + (fi + 1) + " in \"" + funcSheet.getSheet().Name + "\" sheet", logger); } if (last_class == null || last_workspace.Equals("")) { myLog.Warn("Not know workspace for row #" + (fi + 1) + " in \"" + funcSheet.getSheet().Name + "\" sheet", logger); } if (workspace != null && !workspace.Equals("") || (_class != null && !_class.Equals(""))) { classExpression = new ClassExpression(last_workspace, last_class); classExpressions.Add(classExpression); } List <ParameterExpression> _params = parseParams(parameters, myLog); FunctionExpression funcEpx = new FunctionExpression( funcName, accessibility, summary, _params); funcEpx.setReturnDescription(_returns); funcEpx.setContent(implementation); if (classExpression.getListFunction() == null) { classExpression.setListFunction(new List <FunctionExpression>()); } classExpression.getListFunction().Add(funcEpx); } return(classExpressions); }
/// <summary> /// scripts content for a function /// </summary> /// <param name="functionExpression"></param> /// <param name="listUIElements"></param> /// <param name="mapAliasWithNode"></param> /// <param name="myLog"></param> /// <param name="instanceName"></param> /// <returns></returns> private string GenerateFunctionExpScripts(FunctionExpression functionExpression, ListUIElements listUIElements, Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName) { string accessibility = functionExpression.GetCorrectAccessibility(); string summary = functionExpression.getSummary(); List <ParameterExpression> @params = functionExpression.getParams(); string name = functionExpression.getName(); string returnDes = functionExpression.getReturnDescription(); string content = functionExpression.getContent(); string re = ""; if (summary != null) { re += "/// <summary>" + NEW_LINE; string[] listLines = summary.Split('\n'); foreach (string line in listLines) { re += "/// " + line + NEW_LINE; } re += "/// </summary>"; } var pair = GetParamsScripts(@params, listUIElements, mapAliasWithNode, myLog, instanceName); if (pair.Item2 != null && pair.Item2.Count > 0) { for (int fi = 0; fi < pair.Item2.Count; fi++) { string paramName = pair.Item2[fi]; string paramDesc = @params[fi].getDescription(); if (paramDesc == null) { paramDesc = ""; } if (re != "") { re += NEW_LINE; } re += "/// <param name=\"" + paramName + "\">" + paramDesc + "</param>"; } } string returnType = functionExpression.GetCorrectReturnType(); if (returnType != FunctionExpression.VOID) { if (re != "") { re += NEW_LINE; } re += "/// <returns>" + (returnDes ?? "") + "</returns>"; } if (re != "") { re += NEW_LINE; } // Ranorex need to insert annotation re += InsertAnnotation(); re += accessibility + " static " + returnType + " " + name + "("; re += pair.Item1; re += ")" + NEW_LINE; re += "{" + NEW_LINE; if (content != null) { string[] listLines = content.Split('\n'); foreach (string line in listLines) { string line1 = line.Trim().StartsWith("//") ? line.Trim() : "// " + line.Trim(); re += line1 + NEW_LINE; } } if (returnType != FunctionExpression.VOID) { re += "return null;" + NEW_LINE; } re += "}" + NEW_LINE; return(re); }
public virtual ScriptsExpression HandleAndGenScripts(IScriptGenerationParams scriptGenerationParams, ScriptType scriptType = ScriptType.Normal) { if (scriptGenerationParams is UserCodeScriptGenerationParams ucParams) { Regex regex = new Regex("(?<class_group>.*?)\\.(?<func_group>.*)"); Match match = regex.Match(expression); if (match.Success) { string className = match.Groups["class_group"].Value; string funcName = match.Groups["func_group"].Value; Regex regex2 = new Regex("(?<func_group>.*)\\((?<params_group>.*)\\)$"); Match match2 = regex2.Match(funcName); int paramsCount = 0; string[] _params = null; if (match2.Success && match2.Groups["params_group"] != null && match2.Groups["params_group"].Value.Trim() != "") { funcName = match2.Groups["func_group"].Value; _params = match2.Groups["params_group"].Value.Split(','); paramsCount = _params.Count(); } bool voidReturn = true; if (Regex.IsMatch(ucParams.SpecNode.Expression, USER_CODE_WITH_VARIABLE_DECLARE)) { voidReturn = false; } else if (!Regex.IsMatch(ucParams.SpecNode.Expression, AbstractSpecUserAction.USER_CODE)) { logger.Error("Incorrect Expression: " + ucParams.SpecNode.Expression); } var re = new UserCodeScriptsExpression(); var pair = CheckFunctionExisted(ucParams.ClassExpressions, className, funcName, paramsCount, voidReturn); if (!pair.Item1) { FunctionExpression func = new FunctionExpression(funcName); if (_params != null) { foreach (string param in _params) { ParameterExpression parameterExpression = new ParameterExpression(); parameterExpression.setName(param); if (func.getParams() == null) { func.setParams(new List <ParameterExpression>()); } func.getParams().Add(parameterExpression); } } func.setReturnDescription("no description"); ClassExpression classExpExisted = pair.Item2; // if class existed if (classExpExisted != null) { Utils.MergeFunctions(classExpExisted.getListFunction(), func); } else { re.AppendNewAdditionFunc(className, func); } } DoGenRawScripts(className, funcName, _params, voidReturn, ucParams, re, scriptType); return(re); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } }