Пример #1
0
        protected override void Run(IMethodDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            var maxStatements   = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumMethodStatements);
            var maxDeclarations = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumDeclarationsInMethod);

            var statementCount = element.CountChildren <IStatement>();

            if (statementCount <= maxStatements)
            {
                // Only look in the method body for declarations, otherwise we see
                // parameters + type parameters. We can ignore arrow expressions, as
                // they must be a single expression and won't have declarations
                var declarationCount = element.Body?.CountChildren <IDeclaration>() ?? 0;
                if (declarationCount <= maxDeclarations)
                {
                    return;
                }
            }

            var highlighting = new MethodTooLongHighlighting(element.GetNameDocumentRange());

            consumer.AddHighlighting(highlighting);
        }