Пример #1
0
        public override int GetComplexity(SyntaxNode node)
        {
            var walker = new CyclomaticComplexityWalker();

            walker.Visit(node);
            return(walker.CyclomaticComplexity);
        }
        protected void CheckComplexity <TSyntax>(SyntaxNodeAnalysisContext context, Func <TSyntax, Location> getLocation, Func <TSyntax, SyntaxNode> getNodeToCheck, string declarationType)
            where TSyntax : SyntaxNode
        {
            var node = (TSyntax)context.Node;

            var walker = new CyclomaticComplexityWalker();

            var nodeToCheck = getNodeToCheck(node);

            if (nodeToCheck == null)
            {
                return;
            }

            walker.Walk(nodeToCheck);

            if (walker.CyclomaticComplexity > Maximum)
            {
                context.ReportDiagnosticWhenActive(
                    Diagnostic.Create(
                        rule,
                        getLocation(node),
                        walker.IncrementLocations.ToAdditionalLocations(),
                        walker.IncrementLocations.ToProperties(),
                        new object[] { Maximum, walker.CyclomaticComplexity, declarationType }));
            }
        }
Пример #3
0
        /// <summary>
        /// Gets info about cyclomatic complexity, counting the number of predicates within the scope of rootNode and within each nested function
        /// (methods and anonymous functions).
        /// </summary>
        /// <param name="rootNode">The SyntaxNode to measure cyclomatic complexity within</param>
        /// <returns>A sequence of RegionInfo objects, each containing the region-defining node (either rootNode or a function-defining node)
        /// and cyclomatic complexity values for the region. There will always be at least one RegionInfo returned for the rootNode,
        ///  plus one for each nested function.</returns>
        public static IEnumerable <CyclomaticComplexityWalker.RegionInfo> GetCyclomaticComplexityInfo(this SyntaxNode rootNode, SemanticModel model)
        {
            var walker = new CyclomaticComplexityWalker(rootNode, model);

            walker.Visit(rootNode);
            return(walker.Results);
        }
Пример #4
0
        public static int GetCount(SyntaxNode classNode)
        {
            CyclomaticComplexityWalker walker = new CyclomaticComplexityWalker();

            return(walker.CalculateComplexity(classNode));
        }