Ejemplo n.º 1
0
        public void TestMethod1(string identifier, string[] wordsResult)
        {
            var wordsExtracted = new List <string>(WordExtracter.ExtractWordsFromIdentifier(identifier));

            Assert.IsTrue(wordsExtracted.Count == wordsResult.Length);
            for (var i = 0; i < wordsResult.Length; i++)
            {
                Assert.IsTrue(wordsExtracted[i] == wordsResult[i]);
            }
        }
Ejemplo n.º 2
0
        public void Run()
        {
            IAnalysisResult analysisResult;

            if (!ProjectAnalysisUtils.TryChooseAnalysisResult(out analysisResult))
            {
                return;
            }
            Debug.Assert(analysisResult != null);

            var codeBase = analysisResult.CodeBase;

            //
            // Get weight for each identifier
            //
            var identifierWeights = codeBase.Assemblies.Select(IdentifierWeightComputer.GetWeigth).ToList();

            identifierWeights.AddRange(codeBase.Namespaces.Select(IdentifierWeightComputer.GetWeigth).ToList());
            identifierWeights.AddRange(codeBase.Types.Select(IdentifierWeightComputer.GetWeigth).ToList());
            identifierWeights.AddRange(codeBase.Methods.Select(IdentifierWeightComputer.GetWeigth).ToList());
            identifierWeights.AddRange(codeBase.Fields.Select(IdentifierWeightComputer.GetWeigth).ToList());


            //
            // Extract words and their weight from identifier
            //
            var dico = new Dictionary <string, float>();

            foreach (var identifierWeight in identifierWeights)
            {
                if (identifierWeight == null)
                {
                    continue;
                }
                var weightNullable = identifierWeight.Weight;
                if (weightNullable == null || weightNullable == 0)
                {
                    continue;
                }
                var weight = weightNullable.Value;
                var words  = WordExtracter.ExtractWordsFromIdentifier(identifierWeight.Identifier);
                foreach (var word in words)
                {
                    if (!dico.ContainsKey(word))
                    {
                        dico.Add(word, weight);
                        continue;
                    }
                    dico[word] += weight;
                }
            }

            //
            // Sort weigh descendant
            //
            var wordWeights = dico.Select(pair => new IdentifierWeight(pair.Key, pair.Value)).ToList();

            wordWeights.Sort((w1, w2) => w1.Weight <w2.Weight ? 1 : w1.Weight> w2.Weight ? -1 : 0);



            //
            // show result
            //
            var listOfLines = (from wordWeight in wordWeights
                               let identifier = wordWeight.Identifier
                                                select identifier + (identifier.Length < 30 ? new string(' ', 30 - identifier.Length) : "   ") + "Weight: " + wordWeight.Weight).ToList();

            ShowConsoleListOfLines(listOfLines);
        }