本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.AnalysisState类的典型用法代码示例。如果您正苦于以下问题:C# AnalysisState类的具体用法?C# AnalysisState怎么用?C# AnalysisState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnalysisState类属于Microsoft.CodeAnalysis.Diagnostics命名空间,在下文中一共展示了AnalysisState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:54,代码来源:AnalyzerDriver.cs
示例2: ProcessCompilationEventsCoreAsync
private async Task<CompilationCompletedEvent> ProcessCompilationEventsCoreAsync(AnalysisScope analysisScope, AnalysisState analysisStateOpt, bool prePopulatedEventQueue, CancellationToken cancellationToken)
{
try
{
CompilationCompletedEvent completedEvent = null;
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
if (CompilationEventQueue.Count == 0 &&
(prePopulatedEventQueue || CompilationEventQueue.IsCompleted))
{
break;
}
CompilationEvent e;
try
{
if (!prePopulatedEventQueue)
{
e = await CompilationEventQueue.DequeueAsync(cancellationToken).ConfigureAwait(false);
}
else if (!CompilationEventQueue.TryDequeue(out e))
{
return completedEvent;
}
}
catch (TaskCanceledException) when (!prePopulatedEventQueue)
{
// When the queue is completed with a pending DequeueAsync return then a
// TaskCanceledException will be thrown. This just signals the queue is
// complete and we should finish processing it.
Debug.Assert(CompilationEventQueue.IsCompleted, "DequeueAsync should never throw unless the AsyncQueue<T> is completed.");
break;
}
// Don't process the compilation completed event as other worker threads might still be processing other compilation events.
// The caller will wait for all workers to complete and finally process this event.
var compilationCompletedEvent = e as CompilationCompletedEvent;
if (compilationCompletedEvent != null)
{
completedEvent = compilationCompletedEvent;
continue;
}
ProcessEvent(e, analysisScope, analysisStateOpt, cancellationToken);
}
return completedEvent;
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:56,代码来源:AnalyzerDriver.cs
示例3: TryProcessCompilationStarted
/// <summary>
/// Tries to execute compilation started actions.
/// </summary>
/// <returns>
/// True, if successfully executed the actions for the given analysis scope OR no actions were required to be executed for the given analysis scope.
/// False, otherwise.
/// </returns>
private bool TryProcessCompilationStarted(CompilationStartedEvent startedEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
return TryExecuteCompilationActions(_compilationActionsMap, startedEvent, analysisScope, analysisStateOpt, cancellationToken);
}
开发者ID:jkotas,项目名称:roslyn,代码行数:11,代码来源:AnalyzerDriver.cs
示例4: 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);
}
}
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:27,代码来源:AnalyzerDriver.cs
示例5: ExecuteDeclaringReferenceActions
protected abstract void ExecuteDeclaringReferenceActions(SymbolDeclaredCompilationEvent symbolEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken);
开发者ID:JRobertGit,项目名称:roslyn,代码行数:1,代码来源:AnalyzerDriver.cs
示例6: ProcessCompilationCompleted
private void ProcessCompilationCompleted(CompilationCompletedEvent endEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
ExecuteCompilationActions(_compilationEndActionsMap, endEvent, analysisScope, analysisStateOpt, cancellationToken);
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:4,代码来源:AnalyzerDriver.cs
示例7: ExecuteCompilationActionsAsync
private async Task ExecuteCompilationActionsAsync(
ImmutableDictionary<DiagnosticAnalyzer, ImmutableArray<CompilationAnalyzerAction>> compilationActionsMap,
CompilationEvent compilationEvent,
AnalysisScope analysisScope,
AnalysisState analysisStateOpt,
CancellationToken cancellationToken)
{
Debug.Assert(compilationEvent is CompilationStartedEvent || compilationEvent is CompilationCompletedEvent);
try
{
foreach (var analyzer in analysisScope.Analyzers)
{
ImmutableArray<CompilationAnalyzerAction> compilationActions;
if (compilationActionsMap.TryGetValue(analyzer, out compilationActions))
{
await analyzerExecutor.ExecuteCompilationActionsAsync(compilationActions, analyzer, compilationEvent, analysisScope, analysisStateOpt).ConfigureAwait(false);
}
else if (analysisStateOpt != null)
{
await analysisStateOpt.MarkEventCompleteAsync(compilationEvent, analyzer, cancellationToken).ConfigureAwait(false);
}
}
}
finally
{
compilationEvent.FlushCache();
}
}
开发者ID:jeffanders,项目名称:roslyn,代码行数:29,代码来源:AnalyzerDriver.cs
示例8: 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();
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:22,代码来源:AnalyzerDriver.cs
示例9: ProcessSymbolDeclaredAsync
private async Task ProcessSymbolDeclaredAsync(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))
{
await ExecuteSymbolActionsAsync(symbolEvent, analysisScope, analysisStateOpt, cancellationToken).ConfigureAwait(false);
}
if (!AnalysisScope.ShouldSkipDeclarationAnalysis(symbol))
{
await ExecuteDeclaringReferenceActionsAsync(symbolEvent, analysisScope, analysisStateOpt, cancellationToken).ConfigureAwait(false);
}
}
finally
{
symbolEvent.FlushCache();
}
}
开发者ID:jeffanders,项目名称:roslyn,代码行数:22,代码来源:AnalyzerDriver.cs
示例10: ProcessCompilationCompletedAsync
private Task ProcessCompilationCompletedAsync(CompilationCompletedEvent endEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
return ExecuteCompilationActionsAsync(_compilationEndActionsMap, endEvent, analysisScope, analysisStateOpt, cancellationToken);
}
开发者ID:jeffanders,项目名称:roslyn,代码行数:4,代码来源:AnalyzerDriver.cs
示例11: ProcessEventAsync
private async Task ProcessEventAsync(CompilationEvent e, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
await ProcessEventCoreAsync(e, analysisScope, analysisStateOpt, cancellationToken).ConfigureAwait(false);
if (analysisStateOpt != null)
{
await analysisStateOpt.OnCompilationEventProcessedAsync(e, analysisScope, cancellationToken).ConfigureAwait(false);
}
}
开发者ID:jeffanders,项目名称:roslyn,代码行数:9,代码来源:AnalyzerDriver.cs
示例12: ExecuteSyntaxTreeActionsAsync
private async Task ExecuteSyntaxTreeActionsAsync(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.
await analyzerExecutor.ExecuteSyntaxTreeActionsAsync(syntaxTreeActions, analyzer, tree, analysisScope, analysisStateOpt).ConfigureAwait(false);
}
else if (analysisStateOpt != null)
{
await analysisStateOpt.MarkSyntaxAnalysisCompleteAsync(tree, analyzer, cancellationToken).ConfigureAwait(false);
}
}
}
}
开发者ID:jeffanders,项目名称:roslyn,代码行数:27,代码来源:AnalyzerDriver.cs
示例13: TryProcessSymbolDeclared
/// <summary>
/// Tries to execute symbol and declaration actions for the given symbol.
/// </summary>
/// <returns>
/// True, if successfully executed the actions for the given analysis scope OR no actions were required to be executed for the given analysis scope.
/// False, otherwise.
/// </returns>
private bool TryProcessSymbolDeclared(SymbolDeclaredCompilationEvent symbolEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
try
{
// Attempt to execute all analyzer actions.
var success = true;
var symbol = symbolEvent.Symbol;
var isGeneratedCodeSymbol = IsGeneratedCodeSymbol(symbol);
if (!AnalysisScope.ShouldSkipSymbolAnalysis(symbolEvent) &&
!TryExecuteSymbolActions(symbolEvent, analysisScope, analysisStateOpt, isGeneratedCodeSymbol, cancellationToken))
{
success = false;
}
if (!AnalysisScope.ShouldSkipDeclarationAnalysis(symbol) &&
!TryExecuteDeclaringReferenceActions(symbolEvent, analysisScope, analysisStateOpt, isGeneratedCodeSymbol, cancellationToken))
{
success = false;
}
return success;
}
finally
{
symbolEvent.FlushCache();
}
}
开发者ID:jkotas,项目名称:roslyn,代码行数:34,代码来源:AnalyzerDriver.cs
示例14: ProcessEvent
private void ProcessEvent(CompilationEvent e, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
ProcessEventCore(e, analysisScope, analysisStateOpt, cancellationToken);
analysisStateOpt?.OnCompilationEventProcessed(e, analysisScope);
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:5,代码来源:AnalyzerDriver.cs
示例15: CompilationWithAnalyzers
private CompilationWithAnalyzers(Compilation compilation, ImmutableArray<DiagnosticAnalyzer> analyzers, CompilationWithAnalyzersOptions analysisOptions, CancellationToken cancellationToken)
{
VerifyArguments(compilation, analyzers, analysisOptions);
_compilation = compilation.WithEventQueue(new AsyncQueue<CompilationEvent>());
_analyzers = analyzers;
_analysisOptions = analysisOptions;
_cancellationToken = cancellationToken;
_analysisState = new AnalysisState(analyzers);
_analysisResult = new AnalysisResult(analysisOptions.LogAnalyzerExecutionTime, analyzers);
_driverPool = new ObjectPool<AnalyzerDriver>(() => compilation.AnalyzerForLanguage(analyzers, AnalyzerManager.Instance));
_executingConcurrentTreeTasksOpt = analysisOptions.ConcurrentAnalysis ? new Dictionary<SyntaxTree, Tuple<Task, CancellationTokenSource>>() : null;
_concurrentTreeTaskTokensOpt = analysisOptions.ConcurrentAnalysis ? new Dictionary<Task, int>() : null;
_executingCompilationOrNonConcurrentTreeTask = null;
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:16,代码来源:CompilationWithAnalyzers.cs
示例16: ProcessEventCore
private void ProcessEventCore(CompilationEvent e, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var symbolEvent = e as SymbolDeclaredCompilationEvent;
if (symbolEvent != null)
{
ProcessSymbolDeclared(symbolEvent, analysisScope, analysisStateOpt, cancellationToken);
return;
}
var completedEvent = e as CompilationUnitCompletedEvent;
if (completedEvent != null)
{
ProcessCompilationUnitCompleted(completedEvent, analysisScope, analysisStateOpt, cancellationToken);
return;
}
var endEvent = e as CompilationCompletedEvent;
if (endEvent != null)
{
ProcessCompilationCompleted(endEvent, analysisScope, analysisStateOpt, cancellationToken);
return;
}
var startedEvent = e as CompilationStartedEvent;
if (startedEvent != null)
{
ProcessCompilationStarted(startedEvent, analysisScope, analysisStateOpt, cancellationToken);
return;
}
throw new InvalidOperationException("Unexpected compilation event of type " + e.GetType().Name);
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:34,代码来源:AnalyzerDriver.cs
示例17: ExecuteSymbolActions
private void ExecuteSymbolActions(SymbolDeclaredCompilationEvent symbolEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
var symbol = symbolEvent.Symbol;
if (!analysisScope.ShouldAnalyze(symbol))
{
return;
}
foreach (var analyzer in analysisScope.Analyzers)
{
// Invoke symbol analyzers only for source symbols.
ImmutableArray<ImmutableArray<SymbolAnalyzerAction>> actionsByKind;
if (_symbolActionsByKind.TryGetValue(analyzer, out actionsByKind) && (int)symbol.Kind < actionsByKind.Length)
{
analyzerExecutor.ExecuteSymbolActions(actionsByKind[(int)symbol.Kind], analyzer, symbol, GetTopmostNodeForAnalysis, analysisScope, analysisStateOpt);
}
else
{
analysisStateOpt?.MarkSymbolComplete(symbol, analyzer);
}
}
}
开发者ID:nemec,项目名称:roslyn,代码行数:22,代码来源:AnalyzerDriver.cs
示例18: ExecuteSymbolActions
private void ExecuteSymbolActions(SymbolDeclaredCompilationEvent symbolEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
var symbol = symbolEvent.Symbol;
if (!analysisScope.ShouldAnalyze(symbol))
{
return;
}
Action<Diagnostic> addDiagnosticForSymbol = GetDiagnosticSinkWithSuppression(DiagnosticQueue.Enqueue, symbolEvent.Compilation, symbol);
Action<Diagnostic, DiagnosticAnalyzer, bool> addLocalDiagnosticForSymbol = analysisScope.CategorizeDiagnostics ? GetDiagnosticSinkWithSuppression(DiagnosticQueue.EnqueueLocal, symbolEvent.Compilation, symbol) : null;
Action<Diagnostic, DiagnosticAnalyzer> addNonLocalDiagnosticForSymbol = analysisScope.CategorizeDiagnostics ? GetDiagnosticSinkWithSuppression(DiagnosticQueue.EnqueueNonLocal, symbolEvent.Compilation, symbol) : null;
foreach (var analyzer in analysisScope.Analyzers)
{
// Invoke symbol analyzers only for source symbols.
ImmutableArray<ImmutableArray<SymbolAnalyzerAction>> actionsByKind;
if (_symbolActionsByKind.TryGetValue(analyzer, out actionsByKind) && (int)symbol.Kind < actionsByKind.Length)
{
analyzerExecutor.ExecuteSymbolActions(actionsByKind[(int)symbol.Kind], analyzer, symbol, addDiagnosticForSymbol,
addLocalDiagnosticForSymbol, addNonLocalDiagnosticForSymbol, GetTopmostNodeForAnalysis, analysisScope, analysisStateOpt);
}
else
{
analysisStateOpt?.MarkSymbolComplete(symbol, analyzer);
}
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:27,代码来源:AnalyzerDriver.cs
示例19: AttachQueueAndProcessAllEventsAsync
/// <summary>
/// Attaches a pre-populated event queue to the driver and processes all events in the queue.
/// </summary>
/// <param name="eventQueue">Compilation events to analyze.</param>
/// <param name="analysisScope">Scope of analysis.</param>
/// <param name="analysisStateOpt">An optional object to track partial analysis state.</param>
/// <param name="cancellationToken">Cancellation token to abort analysis.</param>
/// <remarks>Driver must be initialized before invoking this method, i.e. <see cref="Initialize(AnalyzerExecutor, DiagnosticQueue, CancellationToken)"/> method must have been invoked and <see cref="WhenInitializedTask"/> must be non-null.</remarks>
internal async Task AttachQueueAndProcessAllEventsAsync(AsyncQueue<CompilationEvent> eventQueue, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
try
{
if (_initializeSucceeded)
{
this.CompilationEventQueue = eventQueue;
_queueRegistration = default(CancellationTokenRegistration);
await ExecutePrimaryAnalysisTaskAsync(analysisScope, analysisStateOpt, usingPrePopulatedEventQueue: true, cancellationToken: cancellationToken).ConfigureAwait(false);
_primaryTask = Task.FromResult(true);
}
}
finally
{
if (_primaryTask == null)
{
// Set primaryTask to be a cancelled task.
var tcs = new TaskCompletionSource<int>();
tcs.SetCanceled();
_primaryTask = tcs.Task;
}
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:33,代码来源:AnalyzerDriver.cs
示例20: ProcessCompilationUnitCompleted
private void ProcessCompilationUnitCompleted(CompilationUnitCompletedEvent completedEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
// When the compiler is finished with a compilation unit, we can run user diagnostics which
// might want to ask the compiler for all the diagnostics in the source file, for example
// to get information about unnecessary usings.
var semanticModel = analysisStateOpt != null ?
GetOrCreateCachedSemanticModel(completedEvent.CompilationUnit, completedEvent.Compilation, cancellationToken) :
completedEvent.SemanticModel;
if (!analysisScope.ShouldAnalyze(semanticModel.SyntaxTree))
{
return;
}
try
{
foreach (var analyzer in analysisScope.Analyzers)
{
ImmutableArray<SemanticModelAnalyzerAction> semanticModelActions;
if (_semanticModelActionsMap.TryGetValue(analyzer, out semanticModelActions))
{
// Execute actions for a given analyzer sequentially.
analyzerExecutor.ExecuteSemanticModelActions(semanticModelActions, analyzer, semanticModel, completedEvent, analysisScope, analysisStateOpt);
}
else
{
analysisStateOpt?.MarkEventComplete(completedEvent, analyzer);
}
}
}
finally
{
completedEvent.FlushCache();
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:36,代码来源:AnalyzerDriver.cs
注:本文中的Microsoft.CodeAnalysis.Diagnostics.AnalysisState类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论