Exemplo n.º 1
0
        private static Dictionary <string, int> GetBugAmountInClasses(List <FaultyVersion> faultyVersions)
        {
            Dictionary <string, int> bugAmountInClasses = new Dictionary <string, int>();

            foreach (var faultyVersion in faultyVersions)
            {
                foreach (FaultyFile faultyFile in faultyVersion.FaultyFiles)
                {
                    // This means the first line of the file has been inserted. And its the only change. Which means its a new file. Therefore, skip file.
                    if (faultyFile.AffectedLines[0] == -1 && faultyFile.AffectedLines.Count == 1)
                    {
                        continue;
                    }
                    string absoluteFileLocation = $"{RepositoriesFolder}/{_repository}/{faultyFile.Filename}";
                    var    response             = _shellService.CheckoutFileForCommit(faultyFile.Filename, faultyVersion.Hash);
                    Thread.Sleep(100);
                    response = _shellService.CheckoutFileForCommit(faultyFile.Filename, faultyVersion.Hash);
                    string code;
                    using (StreamReader r = new StreamReader(absoluteFileLocation))
                    {
                        code = r.ReadToEnd();
                    }


                    SyntaxNode       treeRoot        = CSharpSyntaxTree.ParseText(code).GetRoot();
                    HashSet <string> affectedClasses = GithubService.GetAffectedClasses(treeRoot, faultyFile.AffectedLines, absoluteFileLocation);

                    foreach (string affectedClass in affectedClasses)
                    {
                        if (bugAmountInClasses.ContainsKey(affectedClass))
                        {
                            bugAmountInClasses[affectedClass]++;
                        }
                        else
                        {
                            bugAmountInClasses.Add(affectedClass, 1);
                        }
                    }
                }
            }

            return(bugAmountInClasses);
        }