示例#1
0
        public void TestCSharpFileGetsCCCParserAsFunctionStream()
        {
            string filename   = "myCode.cs";
            var    langParser = LookAheadLangParser.CreateCppParser(new StreamReader(new MemoryStream()));

            IFunctionStream functionStream = FileAnalyzer.CreateFunctionStream(langParser, filename, false);

            Assert.IsNotNull(functionStream);
            Assert.IsTrue(functionStream is CCCParser);
        }
示例#2
0
        public void TestJavascriptFileGetsJSParserAsFunctionStream()
        {
            string filename   = "test.js";
            var    langParser = LookAheadLangParser.CreateCppParser(new StreamReader(new MemoryStream()));

            IFunctionStream functionStream = FileAnalyzer.CreateFunctionStream(langParser, filename, false);

            Assert.IsNotNull(functionStream);
            Assert.IsTrue(functionStream is JSParser);
        }
示例#3
0
 private void OnLocalFunction(IFunctionStream functionStream)
 {
     try
     {
         functionStream.AdvanceToNextFunction();
     }
     catch (CCCParserSuccessException info)
     {
         OnFunction(info.Function, info.StreamOffset, functionStream);
     }
 }
示例#4
0
        private void OnFunction(string unit, int streamOffset, IFunctionStream funcStream)
        {
            BlockAnalyzer analyzer = new BlockAnalyzer(this.parser, funcStream, this.OnLocalFunction, this.switchBehavior);
            int           ccm      = 1 + analyzer.ConsumeBlockCalculateAdditionalComplexity();

            var metric = new ccMetric(this.filename, unit, ccm);

            metric.StartLineNumber = GetLineNumber(streamOffset);
            metric.EndLineNumber   = GetLineNumber(this.parser.StreamOffset);

            this.callback.OnMetric(metric, this.context);
        }
示例#5
0
        public BlockAnalyzer(LookAheadLangParser parser, IFunctionStream functionStream = null, OnLocalFunctionDelegate onLocalFunctionDelegate = null)
        {
            this.parser = parser;
            this.conditionalsWithExpressions = new List <string>(
                new string[] { "if", "while", "foreach", "for", "else if", });

            this.branchPointKeywords = new List <string>(
                new string[] { "case", "catch" });

            this.functionStream          = functionStream;
            this.onLocalFunctionDelegate = onLocalFunctionDelegate;
        }
示例#6
0
        public BlockAnalyzer(LookAheadLangParser parser, IFunctionStream functionStream = null, OnLocalFunctionDelegate onLocalFunctionDelegate = null,
            ParserSwitchBehavior switchBehavior = ParserSwitchBehavior.TraditionalInclude)
        {
            this.parser = parser;
              this.conditionalsWithExpressions = new List<string>(
            new string[] { "if", "while", "foreach", "for", "else if", });

              this.branchPointKeywords = new List<string>(new string[] { "catch" });

              if (switchBehavior == ParserSwitchBehavior.TraditionalInclude)
            this.branchPointKeywords.Add("case");

              this.functionStream = functionStream;
              this.onLocalFunctionDelegate = onLocalFunctionDelegate;
        }
示例#7
0
        public BlockAnalyzer(LookAheadLangParser parser, IFunctionStream functionStream = null, OnLocalFunctionDelegate onLocalFunctionDelegate = null,
                             ParserSwitchBehavior switchBehavior = ParserSwitchBehavior.TraditionalInclude)
        {
            this.parser = parser;
            this.conditionalsWithExpressions = new List <string>(
                new string[] { "if", "while", "foreach", "for", "else if", });

            this.branchPointKeywords = new List <string>(new string[] { "catch" });

            if (switchBehavior == ParserSwitchBehavior.TraditionalInclude)
            {
                this.branchPointKeywords.Add("case");
            }

            this.functionStream          = functionStream;
            this.onLocalFunctionDelegate = onLocalFunctionDelegate;
        }
示例#8
0
        public void Analyze()
        {
            try
            {
                IFunctionStream functionFinder = CreateFunctionStream(this.parser, this.filename, this.suppressMethodSignatures);

                while (true)
                {
                    try
                    {
                        functionFinder.AdvanceToNextFunction(); // will throw CCCParserSuccessException when it finds a function
                    }
                    catch (CCCParserSuccessException info)
                    {
                        OnFunction(info.Function, info.StreamOffset, functionFinder);
                    }
                }
            }
            catch (EndOfStreamException)
            {
                // we are done!
            }
        }
示例#9
0
 private void OnLocalFunction(IFunctionStream functionStream)
 {
     try
       {
     functionStream.AdvanceToNextFunction();
       }
       catch (CCCParserSuccessException info)
       {
     OnFunction(info.Function, info.StreamOffset, functionStream);
       }
 }
示例#10
0
        private void OnFunction(string unit, int streamOffset, IFunctionStream funcStream)
        {
            BlockAnalyzer analyzer = new BlockAnalyzer(this.parser, funcStream, this.OnLocalFunction, this.switchBehavior);
              int ccm = 1 + analyzer.ConsumeBlockCalculateAdditionalComplexity();

              var metric = new ccMetric(this.filename, unit, ccm);
              metric.StartLineNumber = GetLineNumber(streamOffset);
              metric.EndLineNumber = GetLineNumber(this.parser.StreamOffset);

              this.callback.OnMetric(metric, this.context);
        }