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); }
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); }
private void OnLocalFunction(IFunctionStream functionStream) { try { functionStream.AdvanceToNextFunction(); } catch (CCCParserSuccessException info) { OnFunction(info.Function, info.StreamOffset, functionStream); } }
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); }
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; }
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; }
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; }
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! } }
private void OnLocalFunction(IFunctionStream functionStream) { try { functionStream.AdvanceToNextFunction(); } catch (CCCParserSuccessException info) { OnFunction(info.Function, info.StreamOffset, functionStream); } }
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); }