Example #1
0
        /// <summary>
        /// Executes the given code block actions on all the executable code blocks for each declaration info in <paramref name="declarationsInNode"/>.
        /// </summary>
        /// <param name="actions"><see cref="AnalyzerActions"/> whose code block start actions and end actions are to be executed.</param>
        /// <param name="declarationsInNode">Declarations to be analyzed.</param>
        /// <param name="semanticModel">SemanticModel to be shared amongst all actions.</param>
        /// <param name="getKind">Delegate to compute language specific syntax kind for a syntax node.</param>
        public void ExecuteCodeBlockActions <TLanguageKindEnum>(
            AnalyzerActions actions,
            IEnumerable <DeclarationInfo> declarationsInNode,
            SemanticModel semanticModel,
            Func <SyntaxNode, TLanguageKindEnum> getKind)
            where TLanguageKindEnum : struct
        {
            var codeBlockStartActions = actions.GetCodeBlockStartActions <TLanguageKindEnum>();
            var codeBlockActions      = actions.CodeBlockActions;
            var codeBlockEndActions   = actions.CodeBlockEndActions;

            if (!codeBlockStartActions.Any() && !codeBlockActions.Any() && !codeBlockEndActions.Any())
            {
                return;
            }

            foreach (var declInfo in declarationsInNode)
            {
                var declaredNode         = declInfo.DeclaredNode;
                var declaredSymbol       = declInfo.DeclaredSymbol;
                var executableCodeBlocks = declInfo.ExecutableCodeBlocks;

                if (declaredSymbol != null && declInfo.ExecutableCodeBlocks.Any())
                {
                    ExecuteCodeBlockActions(codeBlockStartActions, codeBlockActions, codeBlockEndActions,
                                            declaredNode, declaredSymbol, executableCodeBlocks, semanticModel, getKind);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Executes the given code block actions on all the executable code blocks for each declaration info in <paramref name="declarationsInNode"/>.
        /// </summary>
        /// <param name="actions"><see cref="AnalyzerActions"/> whose code block start actions and end actions are to be executed.</param>
        /// <param name="declarationsInNode">Declarations to be analyzed.</param>
        /// <param name="semanticModel">SemanticModel to be shared amongst all actions.</param>
        /// <param name="analyzerOptions">Analyzer options.</param>
        /// <param name="addDiagnostic">Delegate to add diagnostics.</param>
        /// <param name="continueOnAnalyzerException">Predicate to decide if exceptions from any action should be handled or not.</param>
        /// <param name="getKind">Delegate to compute language specific syntax kind for a syntax node.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public static void ExecuteCodeBlockActions <TLanguageKindEnum>(
            AnalyzerActions actions,
            IEnumerable <DeclarationInfo> declarationsInNode,
            SemanticModel semanticModel,
            AnalyzerOptions analyzerOptions,
            Action <Diagnostic> addDiagnostic,
            Func <Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException,
            Func <SyntaxNode, TLanguageKindEnum> getKind,
            CancellationToken cancellationToken)
            where TLanguageKindEnum : struct
        {
            VerifyArguments(declarationsInNode, getKind, semanticModel, actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);

            var codeBlockStartActions = actions.GetCodeBlockStartActions <TLanguageKindEnum>();
            var codeBlockEndActions   = actions.CodeBlockEndActions;

            if (!codeBlockStartActions.Any() && !codeBlockEndActions.Any())
            {
                return;
            }

            foreach (var declInfo in declarationsInNode)
            {
                var declaredNode         = declInfo.DeclaredNode;
                var declaredSymbol       = declInfo.DeclaredSymbol;
                var executableCodeBlocks = declInfo.ExecutableCodeBlocks;

                if (declaredSymbol != null && declInfo.ExecutableCodeBlocks.Any())
                {
                    ExecuteCodeBlockActions(codeBlockStartActions, codeBlockEndActions, declaredNode, declaredSymbol,
                                            executableCodeBlocks, analyzerOptions, semanticModel, addDiagnostic, continueOnAnalyzerException, getKind, cancellationToken);
                }
            }
        }