public static void Initialize() { LogFileName = IOFile.CompleteFileNameOutput( DateTime.Today.Date.ToShortDateString().Replace("/", "") + ".log"); LogWriter = File.AppendText(LogFileName); Log("-------------------------------------------------------"); Log("-------------------------------------------------------"); Log("New Task."); }
/// <summary> /// Analyze the code by all trees and semantic models /// </summary> /// <param name="treeList"></param> /// <param name="compilation"></param> public static void AnalyzeAllTrees(Dictionary <SyntaxTree, SemanticModel> treeAndModelDic, Compilation compilation) { // statistics int numFiles = treeAndModelDic.Count; var treeNode = treeAndModelDic.Keys .Select(tree => tree.GetRoot().DescendantNodes().Count()); // analyze every tree simultaneously treeAndModelDic.Keys.AsParallel() .ForAll(tree => GetAllMethodDeclarations(tree, treeAndModelDic, compilation)); //foreach (var methoddeclar in allMethodDeclarations) //{ // MergeDic(ref AllMyMethods, methoddeclar); //} Logger.Log("Cached all method declarations."); var codeStatsList = treeAndModelDic.Keys.AsParallel() .Select(tree => AnalyzeATree(tree, treeAndModelDic, compilation)).ToList(); CodeStatistics allStats = new CodeStatistics(codeStatsList); // Log statistics Logger.Log("Num of syntax nodes: " + treeNode.Sum()); Logger.Log("Num of source files: " + numFiles); allStats.CodeStats["NumFiles"] = numFiles; allStats.CodeStats["NumDeclaredMethods"] = AllMyMethods.Count; allStats.CodeStats["NumInvokedMethods"] = InvokedMethods.Count; allStats.CodeStats["NumInvokedMethodsBinded"] = InvokedMethods.Values.Count(method => method.isBinded()); allStats.CodeStats["NumInvokedMethodsDeclared"] = InvokedMethods.Values.Count(method => method.isDeclared()); allStats.CodeStats["NumInvokedMethodsExtDocPresent"] = InvokedMethods.Values.Count(method => method.isExternalDocPresent()); allStats.PrintSatistics(); // Save all the source code into a txt file bool saveAllSource = false; if (saveAllSource == true) { var sb = new StringBuilder(treeAndModelDic.Keys.First().Length *numFiles); //initial length foreach (var stat in codeStatsList) { sb.Append(stat.Item1.GetText()); } string txtFilePath = IOFile.CompleteFileNameOutput("AllSource.txt"); using (StreamWriter sw = new StreamWriter(txtFilePath)) { sw.Write(sb.ToString()); } } }
public void PrintToFileCSV() { Logger.Log("Writing CatchBlock features into file..."); StreamWriter csvSW = new StreamWriter(IOFile.CompleteFileNameOutput("PossibleExceptionsBlock.csv")); StreamWriter metaCSVSW = new StreamWriter(IOFile.CompleteFileNameOutput("PossibleExceptionsBlock_Meta.csv")); int catchId = 0; string metaKey = ""; foreach (var meta in PossibleExceptionsBlock.MetaKeys) { metaKey += (meta + ","); } string OpFeaturesKey = ""; foreach (var OpFeature in PossibleExceptionsBlock.OpFeaturesKeys) { OpFeaturesKey += (OpFeature + ","); } csvSW.WriteLine("id," + OpFeaturesKey + "ThrownType,CaughtType,DeclaringMethod,InvokedMethod,InvokedMethodLine,CatchFilePath,CatchStartLine"); metaCSVSW.WriteLine("id," + metaKey); foreach (string exception in this.Keys) { PossibleExceptionsList possibleExceptionsList = this[exception]; foreach (var possibleExceptionsBlock in possibleExceptionsList) { catchId++; csvSW.WriteLine(catchId + "," + possibleExceptionsBlock.PrintFeaturesCSV()); metaCSVSW.WriteLine(catchId + "," + possibleExceptionsBlock.PrintMetaInfoCSV()); } csvSW.Flush(); metaCSVSW.Flush(); } csvSW.Close(); metaCSVSW.Close(); Logger.Log("Writing done."); }
public void PrintToFileCSV() { Logger.Log("Writing CatchBlock features into file..."); StreamWriter csvSW = new StreamWriter(IOFile.CompleteFileNameOutput("CatchBlock.csv")); StreamWriter metaCSVSW = new StreamWriter(IOFile.CompleteFileNameOutput("CatchBlock_Meta.csv")); int catchId = 0; string metaKey = ""; foreach (var meta in CatchBlock.MetaKeys) { metaKey += (meta + ","); } string OpFeaturesKey = ""; foreach (var OpFeature in CatchBlock.OpFeaturesKeys) { OpFeaturesKey += (OpFeature + ","); } csvSW.WriteLine("id," + OpFeaturesKey + "ExceptionType,ParentMethod,ParentType,FilePath,StartLine"); metaCSVSW.WriteLine("id," + metaKey); foreach (string exception in this.Keys) { CatchList catchList = this[exception]; foreach (var catchblock in catchList) { catchId++; csvSW.WriteLine(catchId + "," + catchblock.PrintFeaturesCSV()); metaCSVSW.WriteLine(catchId + "," + catchblock.PrintMetaInfoCSV()); } csvSW.Flush(); metaCSVSW.Flush(); } csvSW.Close(); metaCSVSW.Close(); Logger.Log("Writing done."); }