本文整理汇总了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;
}
}
示例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();
}
}