Example #1
0
        public string SetClassContent(ClassData classData, string content, List <string> usedClasses, List <string> usedEnums)
        {
            content = content.Replace(CLASSNAME, classData.ClassName);

            if (usedClasses.Contains(classData.DerievedClass))
            {
                content = content.Replace(DCLASSNAME, $"<a href = \"{classData.DerievedClass}_Class_Doc.html\"><font color = \"{hexDat}\">{classData.DerievedClass}</font></a>");
            }
            else
            {
                content = content.Replace(DCLASSNAME, classData.DerievedClass);
            }

            content = content.Replace(NAMESPACE, classData.Namespace);
            content = SetVariables(classData, content, usedClasses, usedEnums);
            content = SetFunctions(classData, content, usedClasses, usedEnums);
            return(content);
        }
Example #2
0
        private void ExtractClassAndDerievedClass(string line, ClassData classData)
        {
            string classAndDerievedClassPattern = @"(class\s+\w+\s+:\s+\w+)|(class\s+\w+)";
            Regex  classAndDerievedClassRegex   = new Regex(classAndDerievedClassPattern);
            string completeValue = "";

            completeValue = classAndDerievedClassRegex.Match(line).Value;
            if (completeValue.Length > 0)
            {
                line = line.Replace(completeValue, "");
            }
            //Support both derieved & no derivation
            if (completeValue.Contains(":"))
            {
                classData.ClassName     = completeValue.Substring(0, completeValue.IndexOf(":") - 1).Replace("class", "").Trim();
                classData.DerievedClass = completeValue.Substring(completeValue.IndexOf(":") + 1).Trim();
            }
            else
            {
                classData.ClassName     = completeValue.Replace("class", "").Trim();
                classData.DerievedClass = "None";
            }
        }
Example #3
0
        private string SetVariables(ClassData classData, string content, List <string> usedClasses, List <string> usedEnums)
        {
            string vars = "<ul>";

            foreach (VariableData vData in classData.Variables)
            {
                if (usedClasses.Contains(vData.VariableType))
                {
                    vars += $"<li><a href = \"{vData.VariableType}_Class_Doc.html\" ><font color = \"{hexDat}\">{vData.VariableType}</font></a> <font color = \"{hexId}\">{vData.VariableName}</font></li>";
                }
                else if (usedEnums.Contains(vData.VariableType))
                {
                    vars += $"<li><a href = \"{vData.VariableType}_Enum_Doc.html\" ><font color = \"{hexDat}\">{vData.VariableType}</font></a> <font color = \"{hexId}\">{vData.VariableName}</font></li>";
                }
                else
                {
                    vars += $"<li><font color = \"{hexDat}\">{vData.VariableType}</font></a> <font color = \"{hexId}\">{vData.VariableName}</font></li>";
                }
            }
            vars   += "</ul>";
            content = content.Replace(MEMVARS, vars);
            return(content);
        }
Example #4
0
        private string SetFunctions(ClassData classData, string content, List <string> usedClasses, List <string> usedEnums)
        {
            string funcs = "<ul>";

            foreach (FunctionData fData in classData.Functions)
            {
                //Clases
                if (usedClasses.Contains(fData.ReturnType))
                {
                    funcs += $"<li><a href = \"{fData.ReturnType}_Class_Doc.html\"><font color = \"{hexDat}\">{fData.ReturnType}</font></a> <font color = \"{hexId}\">{fData.FunctionName}</font> {fData.GetHtmlParameterString(hexId, hexDat)}</li>";
                }
                else if (usedEnums.Contains(fData.ReturnType))
                {
                    funcs += $"<li><a href = \"{fData.ReturnType}_Enum_Doc.html\"><font color = \"{hexDat}\">{fData.ReturnType}</font></a> <font color = \"{hexId}\">{fData.FunctionName}</font> {fData.GetHtmlParameterString(hexId, hexDat)}</li>";
                }
                else
                {
                    funcs += $"<li><font color = \"{hexDat}\">{fData.ReturnType}</font>  <font color = \"{hexId}\">{fData.FunctionName}</font> {fData.GetHtmlParameterString(hexId, hexDat)}</li>";
                }
            }
            funcs  += "</ul>";
            content = content.Replace(FUNCTIONS, funcs);
            return(content);
        }
Example #5
0
        private void ExtractClasses(string codeFileContent)
        {
            classes = new List <ClassData>();
            string usingPattern = @"class\s+\w+";
            Regex  usingRegex   = new Regex(usingPattern);

            //Before analyzing class content , assign namespace to the class.
            //Find last instance of namespace before match found index
            foreach (Match match in usingRegex.Matches(codeFileContent))
            {
                int indexOfClass = match.Index;
                //start index fromthere and back wards till front
                string namespaceText = "";
                if (codeFileContent.Contains("namespace "))
                {
                    int indexOfNamespace = codeFileContent.LastIndexOf("namespace ", indexOfClass);
                    int iDx = indexOfNamespace + 10;
                    while (codeFileContent[iDx] != '{')
                    {
                        namespaceText += codeFileContent[iDx];
                        iDx++;
                    }
                    namespaceText = namespaceText.Trim();
                }
                else
                {
                    namespaceText = "None";
                }
                Logger.OutputToLog("Namespace : " + namespaceText + Environment.NewLine);
                ClassData cd = new ClassData()
                {
                    Namespace = namespaceText
                };
                Stack <int> bracketPosition      = new Stack <int>();
                bool        hasEnteredClassBlock = false;
                string      newStartString       = codeFileContent.Substring(indexOfClass);
                ExtractClassAndDerievedClass(newStartString, cd);
                int  classStartIndex = 0;
                int  classEndIndex   = 0;
                bool isValidClass    = true;
                for (int i = 0; i < newStartString.Length; i++)
                {
                    if (!hasEnteredClassBlock)
                    {
                        if (!newStartString.Contains("{") && !newStartString.Contains("}"))
                        {
                            isValidClass = false;
                            break;
                        }
                    }

                    if (newStartString[i] == '{')
                    {
                        bracketPosition.Push(i);
                        if (!hasEnteredClassBlock)
                        {
                            hasEnteredClassBlock = true;
                            classStartIndex      = i + 1;
                        }
                    }
                    else if (newStartString[i] == '}')
                    {
                        if (bracketPosition.Count <= 0)
                        {
                            isValidClass = false;
                            break;
                        }
                        bracketPosition.Pop();
                    }

                    if (bracketPosition.Count == 0 && hasEnteredClassBlock)
                    {
                        classEndIndex = i;
                        break;
                    }
                }
                if (isValidClass)
                {
                    try
                    {
                        newStartString = newStartString.Substring(classStartIndex, classEndIndex - classStartIndex);
                        Logger.OutputToLog("Analysis of class Data : " + Environment.NewLine + newStartString);
                        cd.Analyze(newStartString);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error : class start index = " + classStartIndex + ", end index = " + classEndIndex + " , class : " + cd.ClassName);
                        Console.WriteLine(e.StackTrace);
                    }
                    classes.Add(cd);
                }
            }
        }