当前位置: 首页>>代码示例>>C#>>正文


C# DiagnosticAnalyzer.SupportsSemanticDiagnosticAnalysis方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer.SupportsSemanticDiagnosticAnalysis方法的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticAnalyzer.SupportsSemanticDiagnosticAnalysis方法的具体用法?C# DiagnosticAnalyzer.SupportsSemanticDiagnosticAnalysis怎么用?C# DiagnosticAnalyzer.SupportsSemanticDiagnosticAnalysis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer的用法示例。


在下文中一共展示了DiagnosticAnalyzer.SupportsSemanticDiagnosticAnalysis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldRunProviderForStateType

            private static bool ShouldRunProviderForStateType(StateType stateTypeId, DiagnosticAnalyzer provider, DiagnosticAnalyzerDriver driver,
                out bool supportsSemanticInSpan, ImmutableHashSet<string> diagnosticIds = null, Func<DiagnosticAnalyzer, ImmutableArray<DiagnosticDescriptor>> getDescriptor = null)
            {
                Debug.Assert(!IsAnalyzerSuppressed(provider, driver.Project.CompilationOptions, driver));

                supportsSemanticInSpan = false;
                if (diagnosticIds != null && getDescriptor(provider).All(d => !diagnosticIds.Contains(d.Id)))
                {
                    return false;
                }

                switch (stateTypeId)
                {
                    case StateType.Syntax:
                        return provider.SupportsSyntaxDiagnosticAnalysis(driver);

                    case StateType.Document:
                        return provider.SupportsSemanticDiagnosticAnalysis(driver, out supportsSemanticInSpan);

                    case StateType.Project:
                        return provider.SupportsProjectDiagnosticAnalysis(driver);

                    default:
                        throw ExceptionUtilities.Unreachable;
                }
            }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:26,代码来源:DiagnosticAnalyzerService.IncrementalAnalyzer.cs

示例2: GetSemanticDiagnosticsAsync

        public async Task<IEnumerable<Diagnostic>> GetSemanticDiagnosticsAsync(DiagnosticAnalyzer analyzer)
        {
            var model = await _document.GetSemanticModelAsync(_cancellationToken).ConfigureAwait(false);
            Contract.ThrowIfNull(_document);
            Contract.ThrowIfFalse(analyzer.SupportsSemanticDiagnosticAnalysis(this));

            using (var pooledObject = SharedPools.Default<List<Diagnostic>>().GetPooledObject())
            {
                var diagnostics = pooledObject.Object;

                // Stateless semantic analyzers:
                //  1) ISemanticModelAnalyzer/IDocumentBasedDiagnosticAnalyzer
                //  2) ISymbolAnalyzer
                //  3) ISyntaxNodeAnalyzer

                _cancellationToken.ThrowIfCancellationRequested();

                var documentAnalyzer = analyzer as DocumentDiagnosticAnalyzer;
                if (documentAnalyzer != null)
                {
                    try
                    {
                        await documentAnalyzer.AnalyzeSemanticsAsync(_document, diagnostics.Add, _cancellationToken).ConfigureAwait(false);
                    }
                    catch (Exception e) when(CatchAnalyzerException(e, analyzer))
                    {
                        var exceptionDiagnostics = AnalyzerExceptionToDiagnostics(analyzer, e, _cancellationToken);
                        return model == null ? exceptionDiagnostics : GetFilteredDocumentDiagnostics(exceptionDiagnostics, model.Compilation);
                    }
                    }
                else
                {
                        var analyzerActions = await GetAnalyzerActionsAsync(analyzer, diagnostics.Add).ConfigureAwait(false);

                        if (analyzerActions != null)
                        {
                            // SemanticModel actions.
                            if (analyzerActions.SemanticModelActionsCount > 0)
                            {
                                AnalyzerDriverHelper.ExecuteSemanticModelActions(analyzerActions, model, _analyzerOptions,
                                    diagnostics.Add, CatchAnalyzerException, _cancellationToken);
                            }

                            var compilation = model.Compilation;

                            // Symbol actions.
                            if (analyzerActions.SymbolActionsCount > 0)
                            {
                                var symbols = this.GetSymbolsToAnalyze(model);
                                AnalyzerDriverHelper.ExecuteSymbolActions(analyzerActions, symbols, compilation,
                                        _analyzerOptions, diagnostics.Add, CatchAnalyzerException, _cancellationToken);
                            }

                            if (this.SyntaxNodeAnalyzerService != null)
                            {
                                // SyntaxNode actions.
                                if (analyzerActions.SyntaxNodeActionsCount > 0)
                                {
                                    this.SyntaxNodeAnalyzerService.ExecuteSyntaxNodeActions(analyzerActions, GetSyntaxNodesToAnalyze(), model,
                                        _analyzerOptions, diagnostics.Add, CatchAnalyzerException, _cancellationToken);
                                }

                                // CodeBlockStart, CodeBlockEnd, and generated SyntaxNode actions.
                                if (analyzerActions.CodeBlockStartActionsCount > 0 || analyzerActions.CodeBlockEndActionsCount > 0)
                                {
                                    this.SyntaxNodeAnalyzerService.ExecuteCodeBlockActions(analyzerActions, this.GetDeclarationInfos(model), model,
                                        _analyzerOptions, diagnostics.Add, CatchAnalyzerException, _cancellationToken);
                                }
                            }
                        }
                    }

                    var result = model == null
                        ? diagnostics
                        : GetFilteredDocumentDiagnostics(diagnostics, model.Compilation);

                    return result.ToImmutableArray();
                }
            }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:79,代码来源:DiagnosticAnalyzerDriver.cs


注:本文中的Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer.SupportsSemanticDiagnosticAnalysis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。