Beispiel #1
0
        public static T GetOption <T>(this SemanticModelAnalysisContext context, PerLanguageOption <T> option, string?language)
        {
            var analyzerOptions   = context.Options;
            var syntaxTree        = context.SemanticModel.SyntaxTree;
            var cancellationToken = context.CancellationToken;

            return(GetOption(analyzerOptions, option, language, syntaxTree, cancellationToken));
        }
Beispiel #2
0
            public static void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
            {
                var declDiagnostics = context.SemanticModel.GetDeclarationDiagnostics(context.FilterSpan, context.CancellationToken);
                var bodyDiagnostics = context.SemanticModel.GetMethodBodyDiagnostics(context.FilterSpan, context.CancellationToken);

                ReportDiagnostics(declDiagnostics, context.ReportDiagnostic, IsSourceLocation, s_declaration);
                ReportDiagnostics(bodyDiagnostics, context.ReportDiagnostic, IsSourceLocation);
            }
Beispiel #3
0
            public static void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
            {
                ImmutableArray <Diagnostic> declDiagnostics = context.SemanticModel.GetDeclarationDiagnostics(cancellationToken: context.CancellationToken);

                ReportDiagnostics(declDiagnostics, context.ReportDiagnostic, IsSourceLocation, s_declaration);

                ImmutableArray <Diagnostic> bodyDiagnostics = context.SemanticModel.GetMethodBodyDiagnostics(cancellationToken: context.CancellationToken);

                ReportDiagnostics(bodyDiagnostics, context.ReportDiagnostic, IsSourceLocation);
            }
Beispiel #4
0
        /// <summary>
        /// Executes the semantic model actions on the given semantic model.
        /// </summary>
        /// <param name="actions"><see cref="AnalyzerActions"/> whose semantic model actions are to be executed.</param>
        /// <param name="semanticModel">Semantic model to analyze.</param>
        /// <param name="analyzerOptions">Analyzer options.</param>
        /// <param name="addDiagnostic">Delegate to add diagnostics.</param>
        /// <param name="continueOnAnalyzerException">Predicate to decide if exceptions from the action should be handled or not.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public static void ExecuteSemanticModelActions(
            AnalyzerActions actions,
            SemanticModel semanticModel,
            AnalyzerOptions analyzerOptions,
            Action <Diagnostic> addDiagnostic,
            Func <Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException,
            CancellationToken cancellationToken)
        {
            VerifyArguments(semanticModel, actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);

            foreach (var semanticModelAction in actions.SemanticModelActions)
            {
                cancellationToken.ThrowIfCancellationRequested();

                // Catch Exception from action.
                ExecuteAndCatchIfThrows(semanticModelAction.Analyzer, addDiagnostic, continueOnAnalyzerException, () =>
                {
                    var context = new SemanticModelAnalysisContext(semanticModel, analyzerOptions, addDiagnostic, cancellationToken);
                    semanticModelAction.Action(context);
                }, cancellationToken);
            }
        }