Exemple #1
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            if (!IOHelper.IsThisADirectory(args[0]))
            {
                return;
            }

            string directory = args[0];

            RulesReader.FromFile("codeDefinition.json");
            ExcludeWordsConfig excludeWordsConfig = ExcludeWordsConfig.FromJsonFile("excludeWords.json");

            LinesOfCode.LineProcessComplete += LinesOfCode_LineProcessComplete;
            FilesOfCode.FileFound           += (f) => LinesOfCode.CountLinesOfCodeInFile(f);
            FilesOfCode.Find(directory);

            foreach (KeyValuePair <string, int> k in _occurrances
                     .Where(kvp => kvp.Value > THRESHOLD)
                     .Where(kvp => !excludeWordsConfig.ExcludeWords.Contains(kvp.Key))
                     .OrderByDescending(kvp => { return(kvp.Value); }))
            {
                Console.WriteLine(k.Value + ":\t" + k.Key);
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
        public void Multi_Comment_Line_Spanning_Lines_Do_Not_Count()
        {
            LinesOfCode.Count(@"/* test 
commented line
counted line */ using System;")
            .ShouldBe(1);
        }
Exemple #3
0
        public void Apply(Instance src)
        {
            if (!Matches(src))
            {
                return;
            }

            LinesOfCode                  = LinesOfCode.Max(src.LinesOfCode);
            DepthOfInheritance           = DepthOfInheritance.Max(src.DepthOfInheritance);
            CyclomaticComplexity         = CyclomaticComplexity.Max(src.CyclomaticComplexity);
            ClassCoupling                = ClassCoupling.Max(src.ClassCoupling);
            NumberOfMethods              = NumberOfMethods.Max(src.NumberOfMethods);
            AnonymousInnerClassLength    = AnonymousInnerClassLength.Max(src.AnonymousInnerClassLength);
            ClassFanOutComplexity        = ClassFanOutComplexity.Max(src.ClassFanOutComplexity);
            ClassDataAbstractionCoupling = ClassDataAbstractionCoupling.Max(src.ClassDataAbstractionCoupling);

            if (src.Members.HasValues())
            {
                Members = new List <Member>(src.Members);
            }
            if (src.Duplicates.HasValues())
            {
                Duplicates = new List <Duplicate>(src.Duplicates);
            }
        }
Exemple #4
0
        public void Multiple_Lines_Count()
        {
            LinesOfCode.Count(@"using System;
using System.Text;
using System.IO;")
            .ShouldBe(3);
        }
Exemple #5
0
        public void ExcludeLinesWithComments()
        {
            RulesReader.FromFile("codeDefinition.json");

            Assert.IsFalse(LinesOfCode.DoCount("//"));
            Assert.IsFalse(LinesOfCode.DoCount("   //"));
            Assert.IsFalse(LinesOfCode.DoCount("///"));
        }
        public void Blank_Line_Does_Not_Count()
        {
            LinesOfCode.Count(@"// test
using System;

using System.Text;")
            .ShouldBe(2);
        }
        public void Multi_Comment_Line_With_Interceptions_Count()
        {
            LinesOfCode.Count(@"/* test 
commented line */
using System; //works
using /* another */ System; /*
counted line */ using System;")
            .ShouldBe(3);
        }
Exemple #8
0
        public void ExcludeLinesThatOnlyContainBrackets()
        {
            RulesReader.FromFile("codeDefinition.json");

            Assert.IsFalse(LinesOfCode.DoCount("	}"));
            Assert.IsFalse(LinesOfCode.DoCount("{"));
            Assert.IsFalse(LinesOfCode.DoCount("{}"));

            Assert.IsTrue(LinesOfCode.DoCount("{ i=0;"));
        }
Exemple #9
0
        public void MethodWithAttribute_AttributeDoesNotCount()
        {
            AddLineToFile("[STAThread]");
            AddLineToFile("static void Main()");
            AddLineToFile("{");
            AddLineToFile("}");

            int nrOfCodeLines = LinesOfCode.CountLinesOfCodeInFile(_testFile);

            Assert.AreEqual(1, nrOfCodeLines);
        }
Exemple #10
0
        public void MethodWithDocComments_CommentsDoesNotCount()
        {
            AddLineToFile("    /// <summary>");
            AddLineToFile("/// The main entry point for the application.");
            AddLineToFile("/// </summary>");
            AddLineToFile("static void Main()");

            int nrOfCodeLines = LinesOfCode.CountLinesOfCodeInFile(_testFile);

            Assert.AreEqual(1, nrOfCodeLines);
        }
Exemple #11
0
    public static void main()
    {
        Console.WriteLine("Let's measure this project's code!");
        Console.WriteLine();

        Measurement LoC = new LinesOfCode(ProjectPath);
        Measurement NoC = new NumberOfClasses(ProjectPath);

        Console.WriteLine();
        Console.WriteLine("RESULTS");
        Console.WriteLine("LOC: " + LoC.Result);
        Console.WriteLine("NOC: " + NoC.Result);
    }
        public void WarningState_ClassCountOverMaxNumberOfLinesAllowed_Is_EqualToThreshold_Test()
        {
            var mockRepository       = new MockRepository(MockBehavior.Strict);
            var codeAnalysisToolMock = mockRepository.Create <CodeAnalysisTool>();

            codeAnalysisToolMock.Setup(x => x.GetClassCountOverMaxNumberOfLinesAllowed(500)).Returns(10);

            var linesOfCode  = new LinesOfCode(codeAnalysisToolMock.Object, 500);
            var stateContext = linesOfCode.Check(10);

            Assert.IsType <Warning>(stateContext.GetState());
            Assert.Equal($"{stateContext.GetType().Name} is in a warning state.", stateContext.GetStateMessage());

            codeAnalysisToolMock.Verify(x => x.GetClassCountOverMaxNumberOfLinesAllowed(500), Times.Once);
        }
        private void WriteProjectStats(StringBuilder sb)
        {
            sb.AppendLine("<p class=\"projectInfo\">");

            var namedTypes = this.DeclaredSymbols.Keys.OfType <INamedTypeSymbol>();

            sb.Append("Project&nbsp;path:&nbsp;").Append(ProjectSourcePath).AppendLine("<br>");
            sb.Append("Files:&nbsp;").Append(DocumentCount.WithThousandSeparators()).AppendLine("<br>");
            sb.Append("Lines&nbsp;of&nbsp;code:&nbsp;").Append(LinesOfCode.WithThousandSeparators()).AppendLine("<br>");
            sb.Append("Bytes:&nbsp;").Append(BytesOfCode.WithThousandSeparators()).AppendLine("<br>");
            sb.Append("Declared&nbsp;symbols:&nbsp;").Append(this.DeclaredSymbols.Count.WithThousandSeparators()).AppendLine("<br>");
            sb.Append("Declared&nbsp;types:&nbsp;").Append(namedTypes.Count().WithThousandSeparators()).AppendLine("<br>");
            sb.Append("Public&nbsp;types:&nbsp;").Append(namedTypes.Where(t => t.DeclaredAccessibility == Accessibility.Public).Count().WithThousandSeparators()).AppendLine("<br>");
            sb.Append("Indexed&nbsp;on:&nbsp;").AppendLine(DateTime.Now.ToString("MMMM dd", CultureInfo.InvariantCulture));

            sb.AppendLine("</p>");
        }
        public override string ToString()
        {
            string str = "";

            if (!IsClass && !IsInterface)
            {
                str += "This file does not contain code";
                return(str);
            }
            if (IsClass)
            {
                str += "(Class)";
            }
            if (IsInterface)
            {
                str += "(Class)";
            }
            str += Namespace + "," + Name + "," + LinesOfCode.ToString();
            return(str);
        }
        public static void Main(string[] args)
        {
            //for home
            //  string path = @"E:\EducatioN\MSSE\thesis\project\poi-src-3.10-FINAL-20140208";
            //  string excelFilePath = @"C:\Users\x-man\Desktop\poi.xlsx";


            //for lab
            string path = @"D:\Code\TestCasePrioritization";

            string excelFilePath = @"C:\Users\xman\Documents\mynewfile2.xlsx";
            PackageExtractorManager packageManager = new PackageExtractorManager();

            packageManager.GetPackageInfo(path);
            var item = packageManager.GetPackageList();

            List <CodeMetricsClass> codeMetrics = new List <CodeMetricsClass>();

            PublicMethodManager pmm = new PublicMethodManager();

            pmm.GetPublicInfo(path, codeMetrics);
            pmm.GetParentCls(codeMetrics);
            pmm.GetLcomInfo(codeMetrics);
            pmm.GetCoupling(codeMetrics);
            pmm.GetNocCount(codeMetrics);
            pmm.GetDitCount(codeMetrics);
            pmm.GetRfcCount(codeMetrics);

            LinesOfCode loc = new LinesOfCode();

            loc.GetLinesOfCode(codeMetrics);

            FileManager fileManager = new FileManager();

            fileManager.GenerateExcelFile(codeMetrics, excelFilePath);
            Console.WriteLine("End of Operation...");
        }
Exemple #16
0
        public void CountLinesOfCode(string[] args,
                                     Action <LOCStat> onSuccess,
                                     Action onComplete,
                                     Action <string> onFileAccessError,
                                     Action <string> onFolderAccessError)
        {
            CommandLine command    = new CommandLine();
            FileAccess  fileAccess = new FileAccess();
            LinesOfCode loc        = new LinesOfCode();


            string path = command.GetPath(args);

            fileAccess.FindSourceCodeFile(path,
                                          onVorhanden: (filename) =>
            {
                var lines = fileAccess.ReadFile(filename);
                loc.CreateLinesOfCodeStat(lines);
            },
                                          onKeineWeiteren: () =>
            {
            }
                                          );
        }
 public void Multi_Comment_Line_With_Preceeding_Literal_Does_Count()
 {
     LinesOfCode.Count("using System; /* test */")
     .ShouldBe(1);
 }
 public void Multi_Comment_Line_Does_Not_Count()
 {
     LinesOfCode.Count("/* test */")
     .ShouldBe(0);
 }
 public void Comment_Line_Does_Not_Count()
 {
     LinesOfCode.Count("// test")
     .ShouldBe(0);
 }
Exemple #20
0
 public void DoNotCountEmptyLines()
 {
     Assert.IsFalse(LinesOfCode.DoCount("\n"));
     Assert.IsFalse(LinesOfCode.DoCount(string.Empty));
 }
Exemple #21
0
 public void CountOneLine()
 {
     RulesReader.FromFile("codeDefinition.json");
     Assert.IsTrue(LinesOfCode.DoCount("i=0;\n"));
 }
Exemple #22
0
 public void Empty_String_Does_Not_Count()
 {
     LinesOfCode.Count(string.Empty)
     .ShouldBe(0);
 }
Exemple #23
0
 public void Single_Line_Does_Count()
 {
     LinesOfCode.Count("using System;")
     .ShouldBe(1);
 }