本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.AnalysisScope类的典型用法代码示例。如果您正苦于以下问题:C# AnalysisScope类的具体用法?C# AnalysisScope怎么用?C# AnalysisScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnalysisScope类属于Microsoft.CodeAnalysis.Diagnostics命名空间,在下文中一共展示了AnalysisScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StoreAnalysisResult
public void StoreAnalysisResult(AnalysisScope analysisScope, AnalyzerDriver driver)
{
foreach (var analyzer in analysisScope.Analyzers)
{
// Dequeue reported analyzer diagnostics from the driver and store them in our maps.
var syntaxDiagnostics = driver.DequeueLocalDiagnostics(analyzer, syntax: true);
var semanticDiagnostics = driver.DequeueLocalDiagnostics(analyzer, syntax: false);
var compilationDiagnostics = driver.DequeueNonLocalDiagnostics(analyzer);
lock (_gate)
{
if (syntaxDiagnostics.Length > 0 || semanticDiagnostics.Length > 0 || compilationDiagnostics.Length > 0)
{
UpdateLocalDiagnostics_NoLock(analyzer, syntaxDiagnostics, ref _localSyntaxDiagnosticsOpt);
UpdateLocalDiagnostics_NoLock(analyzer, semanticDiagnostics, ref _localSemanticDiagnosticsOpt);
UpdateNonLocalDiagnostics_NoLock(analyzer, compilationDiagnostics);
}
if (_analyzerExecutionTimeOpt != null)
{
_analyzerExecutionTimeOpt[analyzer] += driver.ResetAnalyzerExecutionTime(analyzer);
}
}
}
}
示例2: StoreAnalysisResult
internal void StoreAnalysisResult(AnalysisScope analysisScope, AnalyzerDriver driver, Compilation compilation, Func<DiagnosticAnalyzer, AnalyzerActionCounts> getAnalyzerActionCounts, bool fullAnalysisResultForAnalyzersInScope)
{
Debug.Assert(!fullAnalysisResultForAnalyzersInScope || analysisScope.FilterTreeOpt == null, "Full analysis result cannot come from partial (tree) analysis.");
foreach (var analyzer in analysisScope.Analyzers)
{
// Dequeue reported analyzer diagnostics from the driver and store them in our maps.
var syntaxDiagnostics = driver.DequeueLocalDiagnostics(analyzer, syntax: true, compilation: compilation);
var semanticDiagnostics = driver.DequeueLocalDiagnostics(analyzer, syntax: false, compilation: compilation);
var compilationDiagnostics = driver.DequeueNonLocalDiagnostics(analyzer, compilation);
lock (_gate)
{
if (_completedAnalyzers.Contains(analyzer))
{
// Already stored full analysis result for this analyzer.
continue;
}
if (syntaxDiagnostics.Length > 0 || semanticDiagnostics.Length > 0 || compilationDiagnostics.Length > 0 || fullAnalysisResultForAnalyzersInScope)
{
UpdateLocalDiagnostics_NoLock(analyzer, syntaxDiagnostics, fullAnalysisResultForAnalyzersInScope, ref _localSyntaxDiagnosticsOpt);
UpdateLocalDiagnostics_NoLock(analyzer, semanticDiagnostics, fullAnalysisResultForAnalyzersInScope, ref _localSemanticDiagnosticsOpt);
UpdateNonLocalDiagnostics_NoLock(analyzer, compilationDiagnostics, fullAnalysisResultForAnalyzersInScope);
}
if (_analyzerExecutionTimeOpt != null)
{
var timeSpan = driver.ResetAnalyzerExecutionTime(analyzer);
_analyzerExecutionTimeOpt[analyzer] = fullAnalysisResultForAnalyzersInScope ?
timeSpan :
_analyzerExecutionTimeOpt[analyzer] + timeSpan;
}
if (!_analyzerActionCounts.ContainsKey(analyzer))
{
_analyzerActionCounts.Add(analyzer, getAnalyzerActionCounts(analyzer));
}
if (fullAnalysisResultForAnalyzersInScope)
{
_completedAnalyzers.Add(analyzer);
}
}
}
}
示例3: GenerateCompilationEventsAndPopulateEventsCacheAsync
private async Task GenerateCompilationEventsAndPopulateEventsCacheAsync(AnalysisScope analysisScope, AnalyzerDriver driver, CancellationToken cancellationToken)
{
#if SIMULATED_EVENT_QUEUE
await _analysisState.GenerateSimulatedCompilationEventsAsync(analysisScope, _compilation, _compilationData.GetOrCreateCachedSemanticModel, driver, cancellationToken).ConfigureAwait(false);
#else
GenerateCompilationEvents(analysisScope, cancellationToken);
await PopulateEventsCacheAsync(cancellationToken).ConfigureAwait(false);
#endif
}
示例4: ProcessCompilationCompleted
private void ProcessCompilationCompleted(CompilationCompletedEvent endEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
ExecuteCompilationActions(_compilationEndActionsMap, endEvent, analysisScope, analysisStateOpt, cancellationToken);
}
示例5: ExecuteDeclaringReferenceActions
protected abstract void ExecuteDeclaringReferenceActions(SymbolDeclaredCompilationEvent symbolEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken);
示例6: ProcessSymbolDeclared
private void ProcessSymbolDeclared(SymbolDeclaredCompilationEvent symbolEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
try
{
// Execute all analyzer actions.
var symbol = symbolEvent.Symbol;
var references = symbolEvent.DeclaringSyntaxReferences;
if (!AnalysisScope.ShouldSkipSymbolAnalysis(symbolEvent))
{
ExecuteSymbolActions(symbolEvent, analysisScope, analysisStateOpt, cancellationToken);
}
if (!AnalysisScope.ShouldSkipDeclarationAnalysis(symbol))
{
ExecuteDeclaringReferenceActions(symbolEvent, analysisScope, analysisStateOpt, cancellationToken);
}
}
finally
{
symbolEvent.FlushCache();
}
}
示例7: ProcessEvent
private void ProcessEvent(CompilationEvent e, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
ProcessEventCore(e, analysisScope, analysisStateOpt, cancellationToken);
analysisStateOpt?.OnCompilationEventProcessed(e, analysisScope);
}
示例8: ProcessCompilationEventsAsync
private async Task ProcessCompilationEventsAsync(AnalysisScope analysisScope, AnalysisState analysisStateOpt, bool prePopulatedEventQueue, CancellationToken cancellationToken)
{
try
{
CompilationCompletedEvent completedEvent = null;
if (analysisScope.ConcurrentAnalysis)
{
// Kick off worker tasks to process all compilation events (except the compilation end event) in parallel.
// Compilation end event must be processed after all other events.
var workerCount = prePopulatedEventQueue ? Math.Min(CompilationEventQueue.Count, _workerCount) : _workerCount;
var workerTasks = new Task<CompilationCompletedEvent>[workerCount];
for (int i = 0; i < workerCount; i++)
{
workerTasks[i] = ProcessCompilationEventsCoreAsync(analysisScope, analysisStateOpt, prePopulatedEventQueue, cancellationToken);
}
cancellationToken.ThrowIfCancellationRequested();
// Kick off tasks to execute syntax tree actions.
var syntaxTreeActionsTask = Task.Run(() => ExecuteSyntaxTreeActions(analysisScope, analysisStateOpt, cancellationToken));
// Wait for all worker threads to complete processing events.
await Task.WhenAll(workerTasks.Concat(syntaxTreeActionsTask)).ConfigureAwait(false);
for (int i = 0; i < workerCount; i++)
{
if (workerTasks[i].Status == TaskStatus.RanToCompletion && workerTasks[i].Result != null)
{
completedEvent = workerTasks[i].Result;
break;
}
}
}
else
{
completedEvent = await ProcessCompilationEventsCoreAsync(analysisScope, analysisStateOpt, prePopulatedEventQueue, cancellationToken).ConfigureAwait(false);
ExecuteSyntaxTreeActions(analysisScope, analysisStateOpt, cancellationToken);
}
// Finally process the compilation completed event, if any.
if (completedEvent != null)
{
ProcessEvent(completedEvent, analysisScope, analysisStateOpt, cancellationToken);
}
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
示例9: ExecuteSyntaxTreeActions
private void ExecuteSyntaxTreeActions(AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
if (analysisScope.IsTreeAnalysis && !analysisScope.IsSyntaxOnlyTreeAnalysis)
{
// For partial analysis, only execute syntax tree actions if performing syntax analysis.
return;
}
foreach (var tree in analysisScope.SyntaxTrees)
{
foreach (var analyzer in analysisScope.Analyzers)
{
cancellationToken.ThrowIfCancellationRequested();
ImmutableArray<SyntaxTreeAnalyzerAction> syntaxTreeActions;
if (_syntaxTreeActionsMap.TryGetValue(analyzer, out syntaxTreeActions))
{
// Execute actions for a given analyzer sequentially.
analyzerExecutor.ExecuteSyntaxTreeActions(syntaxTreeActions, analyzer, tree, analysisScope, analysisStateOpt);
}
else
{
analysisStateOpt?.MarkSyntaxAnalysisComplete(tree, analyzer);
}
}
}
}
示例10: AddDiagnostics_NoLock
private static void AddDiagnostics_NoLock(
Dictionary<DiagnosticAnalyzer, List<Diagnostic>> diagnostics,
AnalysisScope analysisScope,
ImmutableArray<Diagnostic>.Builder builder)
{
Debug.Assert(diagnostics != null);
foreach (var analyzer in analysisScope.Analyzers)
{
List<Diagnostic> diagnosticsByAnalyzer;
if (diagnostics.TryGetValue(analyzer, out diagnosticsByAnalyzer))
{
builder.AddRange(diagnosticsByAnalyzer);
}
}
}
示例11: AddLocalDiagnosticsForPartialAnalysis_NoLock
private static void AddLocalDiagnosticsForPartialAnalysis_NoLock(
Dictionary<SyntaxTree, Dictionary<DiagnosticAnalyzer, List<Diagnostic>>> localDiagnostics,
AnalysisScope analysisScope,
ImmutableArray<Diagnostic>.Builder builder)
{
Dictionary<DiagnosticAnalyzer, List<Diagnostic>> diagnosticsForTree;
if (localDiagnostics != null && localDiagnostics.TryGetValue(analysisScope.FilterTreeOpt, out diagnosticsForTree))
{
AddDiagnostics_NoLock(diagnosticsForTree, analysisScope, builder);
}
}
示例12: AddAllLocalDiagnostics_NoLock
private static void AddAllLocalDiagnostics_NoLock(
Dictionary<SyntaxTree, Dictionary<DiagnosticAnalyzer, List<Diagnostic>>> localDiagnostics,
AnalysisScope analysisScope,
ImmutableArray<Diagnostic>.Builder builder)
{
if (localDiagnostics != null)
{
foreach (var localDiagsByTree in localDiagnostics.Values)
{
AddDiagnostics_NoLock(localDiagsByTree, analysisScope, builder);
}
}
}
示例13: GetDiagnostics_NoLock
private ImmutableArray<Diagnostic> GetDiagnostics_NoLock(AnalysisScope analysisScope, bool getLocalDiagnostics, bool getNonLocalDiagnostics)
{
Debug.Assert(getLocalDiagnostics || getNonLocalDiagnostics);
var builder = ImmutableArray.CreateBuilder<Diagnostic>();
if (getLocalDiagnostics)
{
if (!analysisScope.IsTreeAnalysis)
{
AddAllLocalDiagnostics_NoLock(_localSyntaxDiagnosticsOpt, analysisScope, builder);
AddAllLocalDiagnostics_NoLock(_localSemanticDiagnosticsOpt, analysisScope, builder);
}
else if (analysisScope.IsSyntaxOnlyTreeAnalysis)
{
AddLocalDiagnosticsForPartialAnalysis_NoLock(_localSyntaxDiagnosticsOpt, analysisScope, builder);
}
else
{
AddLocalDiagnosticsForPartialAnalysis_NoLock(_localSemanticDiagnosticsOpt, analysisScope, builder);
}
}
if (getNonLocalDiagnostics && _nonLocalDiagnosticsOpt != null)
{
AddDiagnostics_NoLock(_nonLocalDiagnosticsOpt, analysisScope, builder);
}
return builder.ToImmutableArray();
}
示例14: GetDiagnostics
public ImmutableArray<Diagnostic> GetDiagnostics(AnalysisScope analysisScope, bool getLocalDiagnostics, bool getNonLocalDiagnostics)
{
lock (_gate)
{
return GetDiagnostics_NoLock(analysisScope, getLocalDiagnostics, getNonLocalDiagnostics);
}
}
示例15: GenerateCompilationEvents
private void GenerateCompilationEvents(AnalysisScope analysisScope, CancellationToken cancellationToken)
{
// Invoke GetDiagnostics to populate CompilationEvent queue for the given analysis scope.
// Discard the returned diagnostics.
if (analysisScope.FilterTreeOpt == null)
{
var unused = _compilation.GetDiagnostics(cancellationToken);
}
else if (!analysisScope.IsSyntaxOnlyTreeAnalysis)
{
var mappedModel = _compilationData.GetOrCreateCachedSemanticModel(analysisScope.FilterTreeOpt, _compilation, cancellationToken);
var unused = mappedModel.GetDiagnostics(cancellationToken: cancellationToken);
}
}