Пример #1
0
 public static void MergeClasses(List <ClassExpression> classes, ClassExpression class2)
 {
     if (classes == null)
     {
         classes = new List <ClassExpression> {
             class2
         };
         return;
     }
     if (class2 == null || class2.getName() == null)
     {
         return;
     }
     foreach (ClassExpression cl in classes)
     {
         // add new functions to existed class
         if (cl.getName() == class2.getName())
         {
             var newListFunc = class2.getListFunction();
             if (newListFunc != null && newListFunc.Count > 0)
             {
                 foreach (var newFunc in newListFunc)
                 {
                     MergeFunctions(cl.getListFunction(), newFunc);
                 }
             }
             return;
         }
     }
     // add new class
     NormalizeClass(class2);
     classes.Add(class2);
 }
Пример #2
0
 public static void MergeClassesExpression(List <ClassExpression> @base, ClassExpression addition)
 {
     foreach (ClassExpression existed in @base.ToList())
     {
         if (existed.getName() == addition.getName())
         {
             List <FunctionExpression> newListFuncs = addition.getListFunction();
             if (newListFuncs != null)
             {
                 foreach (FunctionExpression newFunc in newListFuncs.ToList())
                 {
                     if (newFunc != null)
                     {
                         MergeFunctions(existed.getListFunction(), newFunc);
                     }
                 }
             }
             return;
         }
     }
     if (addition != null)
     {
         @base.Add(addition);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="classExpression"></param>
        /// <param name="projectPath"></param>
        /// <param name="name_space"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mapAliasWithNode"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns>relative file path</returns>
        private string GenerateClassExpScripts(ClassExpression classExpression, string projectPath, string name_space,
                                               ListUIElements listUIElements, Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            if (classExpression.getName() == null || classExpression.getListFunction() == null ||
                classExpression.getListFunction().Count <= 0)
            {
                return(null);
            }
            string functionsScripts = "";

            foreach (FunctionExpression func in classExpression.getListFunction())
            {
                if (functionsScripts != "")
                {
                    functionsScripts += NEW_LINE;
                }
                functionsScripts += GenerateFunctionExpScripts(func, listUIElements, mapAliasWithNode, myLog, instanceName);
            }
            // create new file
            string classContent = GetTemplateUCClassContent()
                                  //.Replace(GLOBAL_REPLACE, "") disabled by @duongtd 05/29
                                  .Replace(CLASS_REPLACE, classExpression.getName())
                                  .Replace(CONTENT_REPLACE, functionsScripts);
            string filePath            = Path.Combine(classExpression.GetCorrectWorkspace(), classExpression.getName() + ".cs");
            string fileContentTemplate = GetTemplateRunCsFileContent()
                                         .Replace(NAMESPACE_REPLACE, name_space);

            CreateNewFile(fileContentTemplate, classContent, Path.Combine(projectPath, filePath));
            return(filePath);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="existedClasses"></param>
        /// <param name="className"></param>
        /// <param name="funcName"></param>
        /// <param name="paramsCount"></param>
        /// <param name="voidReturn"></param>
        /// <returns>{indicate function existed, classExpression with className}</returns>
        public Tuple <bool, ClassExpression> CheckFunctionExisted(List <ClassExpression> existedClasses,
                                                                  string className, string funcName, int paramsCount, bool voidReturn)
        {
            if (existedClasses == null || existedClasses.Count == 0)
            {
                return(new Tuple <bool, ClassExpression>(false, null));
            }
            ClassExpression classExpExisted = null;

            foreach (ClassExpression classExp in existedClasses)
            {
                if (classExp.getName().Equals(className))
                {
                    classExpExisted = classExp;
                    List <FunctionExpression> listFuncs = classExp.getListFunction();
                    if (listFuncs != null)
                    {
                        foreach (FunctionExpression funcExp in listFuncs)
                        {
                            if (funcExp.getName().Equals(funcName) &&
                                voidReturn == funcExp.GetCorrectReturnType().Equals(FunctionExpression.VOID) &&
                                paramsCount == (funcExp.getParams() == null ? 0 : funcExp.getParams().Count))
                            {
                                return(new Tuple <bool, ClassExpression>(true, classExp));
                            }
                        }
                    }
                }
            }
            return(new Tuple <bool, ClassExpression>(false, classExpExisted));;
        }
        public ClassExpression clone()
        {
            ClassExpression re = new ClassExpression(workspace, name);

            if (listFunction != null)
            {
                re.listFunction = new List <FunctionExpression>(listFunction);
            }
            return(re);
        }
        public bool Equals(object other)
        {
            if (!(other is ClassExpression))
            {
                return(false);
            }
            ClassExpression other1 = (ClassExpression)other;

            return(compareStr(this.getName(), other1.getName()));
            //                compareStr(this.getWorkspace(), other1.getWorkspace());
        }
Пример #7
0
        public static void NormalizeClass(ClassExpression cl)
        {
            List <FunctionExpression> listFunc = cl.getListFunction();

            if (listFunc == null)
            {
                return;
            }
            List <FunctionExpression> newListFunc = new List <FunctionExpression>();

            foreach (FunctionExpression func in listFunc)
            {
                MergeFunctions(newListFunc, func);
            }
            cl.setListFunction(newListFunc);
        }
Пример #8
0
        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);
        }
 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();
     }
 }