Example #1
0
        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSyntaxNodeActionInNonGenerated(
                GeneratedCodeRecognizer,
                c =>
            {
                var topLevelUnary = (TSyntaxNode)c.Node;

                if (!TopLevelUnaryInChain(topLevelUnary))
                {
                    return;
                }

                var repeatedCount = 0U;
                var currentUnary  = topLevelUnary;
                var lastUnary     = currentUnary;
                while (currentUnary != null &&
                       SameOperators(currentUnary, topLevelUnary))
                {
                    lastUnary = currentUnary;
                    repeatedCount++;
                    currentUnary = GetOperand(currentUnary) as TSyntaxNode;
                }

                if (repeatedCount < 2)
                {
                    return;
                }

                c.ReportDiagnosticWhenActive(Diagnostic.Create(Rule, topLevelUnary.CreateLocation(GetOperatorToken(lastUnary)),
                                                               GetOperatorToken(topLevelUnary).ToString()));
            }, SyntaxKinds.ToArray());
        }
        private static Func <SyntaxTrivia, bool> GetStepIntoFunction(
            bool skipped, bool directives, bool docComments)
        {
            SyntaxKinds index = (skipped ? SyntaxKinds.SkippedTokens : 0) |
                                (directives ? SyntaxKinds.Directives : 0) |
                                (docComments ? SyntaxKinds.DocComments : 0);

            return(s_stepIntoFunctions[(int)index]);
        }