static public Box NotMain(string filePath) { List <string> functions; List <string> analisisCode; List <string> methodNames; var box = new Box(); string fileCode = System.IO.File.ReadAllText(filePath); fileCode = Refactoring(fileCode); fileCode = RemoveString(fileCode, '"', '\''); var _functions = Analyze.GetFunctions(fileCode); var _functionNames = new List <string>(); foreach (var item in _functions) { _functionNames.Add(Analyze.FindMethodName(item)); } var _uselesNames = new List <string>(); methodNames = GetMethodName(GetFunctionContents(fileCode)); foreach (var name in methodNames) { if (!_functionNames.Contains(name + "()")) { _uselesNames.Add(name); } } foreach (var item in GetMethodName(GetFunctionContents(fileCode))) // Подготавливаем код проги { fileCode = fileCode.Replace(item + "(", " "); } functions = GetFunctionContents(fileCode); // Список функций foreach (var functionCode in functions) { var tempDict = new Dictionary <string, int>(); var alilya = new Dictionary <string, int>(); var variableSet = GetVariables(functionCode); // Список уникальных переменных foreach (var item in variableSet) { if (!alilya.ContainsKey(item)) { alilya.Add(item, GetCount(variableSet, item) * GetCount(methodNames, methodNames[functions.IndexOf(functionCode)]) - GetCount(methodNames, methodNames[functions.IndexOf(functionCode)])); } } box.FirstMetric.Add(methodNames[functions.IndexOf(functionCode)], alilya); } fileCode = RemoveString(fileCode, '[', ']'); functions = GetFunctionContents(fileCode); foreach (var functionCode in functions) { analisisCode = GetCodeForAnalysis(functionCode); // Список для ИИ var variableSet = GetVariables(functionCode).Distinct(); string functionName = methodNames[functions.IndexOf(functionCode)]; var tempVariableGroup = GetVariablesGroup(variableSet, analisisCode); var secondDick = new Dictionary <string, Dictionary <string, int> >(); foreach (var item in tempVariableGroup.Keys) // Получает Словарь переменных и в нем перебирает значения { var firstDick = new Dictionary <string, int>(); var variables = tempVariableGroup[item]; foreach (var vari in variables) { firstDick.Add(vari, GetCount(variables, vari) * GetCount(methodNames, functionName) - GetCount(methodNames, functionName)); } secondDick.Add(item, firstDick); } box.SecondMetric.Add(functionName, secondDick); } foreach (var functionCode in functions) { analisisCode = GetCodeForAnalysis(functionCode); var variableSet = GetVariables(functionCode).Distinct(); string functionName = methodNames[functions.IndexOf(functionCode)]; var tempVariableGroup = GetVariablesGroupIO(variableSet, analisisCode); var secondDick = new Dictionary <string, Dictionary <string, int> >(); foreach (var item in tempVariableGroup.Keys) // Получает Словарь переменных и в нем перебирает значения { var firstDick = new Dictionary <string, int>(); var variables = tempVariableGroup[item]; foreach (var vari in variables) { firstDick.Add(vari, GetCount(variables, vari) * GetCount(methodNames, functionName) - GetCount(methodNames, functionName)); } secondDick.Add(item, firstDick); } box.ThirdMetric.Add(functionName, secondDick); } foreach (var name in _uselesNames) { box.FirstMetric.Remove(name); box.SecondMetric.Remove(name); box.ThirdMetric.Remove(name); } return(box); }
private void ShowTable(string _methodName) { if (_FilePath == null) { return; } var _listDict = Analyze.analyze(_FilePath); dataGridView1.Rows.Clear(); int i = 0, j = 0, N1 = 0, N2 = 0, way = 0; foreach (var _dict in _listDict) { if (_dict.ContainsKey(_methodName)) { _dict.Remove(_methodName); dataGridView1.Rows.Add(_dict.Count * 2); i = 1; j = 1; N1 = 0; N2 = 0; way = 0; // // Shows operators // foreach (var _oper in Analyze._operators) { if (_dict.ContainsKey(_oper)) { N1 += _dict[_oper]; dataGridView1[0, way].Value = i++; if (_oper == "do") { dataGridView1[1, way].Value = _oper + "..while"; } else if (Analyze._functions.Contains(_oper)) { dataGridView1[1, way].Value = _oper + "()"; } else if (_oper == "(") { dataGridView1[1, way].Value = _oper + ")"; } else if (_oper == "{") { dataGridView1[1, way].Value = _oper + "}"; } else if (_oper == "[") { dataGridView1[1, way].Value = _oper + "]"; } else if (_oper == "catch") { dataGridView1[1, way].Value = "try.." + _oper; } else if (_oper == "finaly") { dataGridView1[1, way].Value = "try.." + _oper; } else if (_oper == "[") { dataGridView1[1, way].Value = _oper + "]"; } else if (_oper == "else") { dataGridView1[1, way].Value = "if.." + _oper; } else { dataGridView1[1, way].Value = _oper; } dataGridView1[2, way].Value = _dict[_oper]; way++; _dict.Remove(_oper); } } foreach (var _oper in Analyze.FindMethodNames(_FilePath)) { if (_dict.ContainsKey(_oper.Substring(0, _oper.Length - 2))) { N1 += _dict[_oper.Substring(0, _oper.Length - 2)]; dataGridView1[1, way].Value = _oper; dataGridView1[0, way].Value = i++; dataGridView1[2, way].Value = _dict[_oper.Substring(0, _oper.Length - 2)]; _dict.Remove(_oper.Substring(0, _oper.Length - 2)); way++; } } // // Shows operands // way = 0; foreach (var _item in _dict) { N2 += _item.Value; dataGridView1[3, way].Value = j++; dataGridView1[4, way].Value = _item.Key; dataGridView1[5, way].Value = _item.Value; way++; } break; } } LengthDick.Text = "Length : " + (N1 + N2).ToString() + "\r\n" + "Operators : " + (N1).ToString() + "\r\n" + "Operands : " + (N2).ToString() + "\r\n" + "j Operators: " + (i - 1).ToString() + "\r\n" + "i Operands : " + (j - 1).ToString() + "\r\n" + "Dictionary : " + (i + j - 2).ToString() + "\r\n" + "Volume : " + ((int)((N1 + N2) * Math.Log(i + j - 2, 2))).ToString(); }