本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.CompilationEvent类的典型用法代码示例。如果您正苦于以下问题:C# CompilationEvent类的具体用法?C# CompilationEvent怎么用?C# CompilationEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationEvent类属于Microsoft.CodeAnalysis.Diagnostics命名空间,在下文中一共展示了CompilationEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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();
}
}
示例3: 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);
}
示例4: AddPendingSourceEvent_NoLock
private void AddPendingSourceEvent_NoLock(SyntaxTree tree, CompilationEvent compilationEvent)
{
HashSet<CompilationEvent> currentEvents;
if (!_pendingSourceEvents.TryGetValue(tree, out currentEvents))
{
currentEvents = _compilationEventsPool.Allocate();
_pendingSourceEvents[tree] = currentEvents;
AnalyzerDriver.RemoveCachedSemanticModel(tree, compilationEvent.Compilation);
}
currentEvents.Add(compilationEvent);
}
示例5: OnCompilationEventProcessed
/// <summary>
/// Invoke this method at completion of event processing for the given analysis scope.
/// It updates the analysis state of this event for each analyzer and if the event has been fully processed for all analyzers, then removes it from our event cache.
/// </summary>
public void OnCompilationEventProcessed(CompilationEvent compilationEvent, AnalysisScope analysisScope)
{
// Analyze if the symbol and all its declaring syntax references are analyzed.
var symbolDeclaredEvent = compilationEvent as SymbolDeclaredCompilationEvent;
if (symbolDeclaredEvent != null)
{
OnSymbolDeclaredEventProcessed(symbolDeclaredEvent, analysisScope.Analyzers);
}
// Check if event is fully analyzed for all analyzers.
foreach (var analyzerState in _analyzerStateMap.Values)
{
if (!analyzerState.IsEventAnalyzed(compilationEvent))
{
return;
}
}
// Remove the event from event map.
lock (_gate)
{
UpdateEventsMap_NoLock(compilationEvent, add: false);
}
}
示例6: MarkEventComplete
/// <summary>
/// Marks the given event as fully analyzed for the given analyzer.
/// </summary>
public void MarkEventComplete(CompilationEvent compilationEvent, DiagnosticAnalyzer analyzer)
{
_analyzerStateMap[analyzer].MarkEventComplete(compilationEvent);
}
示例7: AddPendingSourceEvent_NoLock
private void AddPendingSourceEvent_NoLock(SyntaxTree tree, CompilationEvent compilationEvent)
{
HashSet<CompilationEvent> currentEvents;
if (!_pendingSourceEvents.TryGetValue(tree, out currentEvents))
{
currentEvents = new HashSet<CompilationEvent>();
_pendingSourceEvents[tree] = currentEvents;
_compilationData.RemoveCachedSemanticModel(tree);
}
currentEvents.Add(compilationEvent);
}
示例8: RemovePendingSourceEvent_NoLock
private void RemovePendingSourceEvent_NoLock(SyntaxTree tree, CompilationEvent compilationEvent)
{
HashSet<CompilationEvent> currentEvents;
if (_pendingSourceEvents.TryGetValue(tree, out currentEvents))
{
if (currentEvents.Remove(compilationEvent) && currentEvents.Count == 0)
{
_compilationEventsPool.Free(currentEvents);
_pendingSourceEvents.Remove(tree);
}
}
}
示例9: ProcessEventAsync
private async Task ProcessEventAsync(CompilationEvent e, CancellationToken cancellationToken)
{
try
{
var processEventTask = ProcessEventCoreAsync(e, cancellationToken);
if (processEventTask != null)
{
await processEventTask.ConfigureAwait(false);
}
}
catch (OperationCanceledException)
{
// when just a single operation is cancelled, we continue processing events.
// TODO: what is the desired behavior in this case?
}
}
示例10: ProcessEventCoreAsync
private Task ProcessEventCoreAsync(CompilationEvent e, CancellationToken cancellationToken)
{
var symbolEvent = e as SymbolDeclaredCompilationEvent;
if (symbolEvent != null)
{
return ProcessSymbolDeclaredAsync(symbolEvent, cancellationToken);
}
var completedEvent = e as CompilationUnitCompletedEvent;
if (completedEvent != null)
{
return ProcessCompilationUnitCompletedAsync(completedEvent, cancellationToken);
}
var endEvent = e as CompilationCompletedEvent;
if (endEvent != null)
{
return ProcessCompilationCompletedAsync(endEvent, cancellationToken);
}
if (e is CompilationStartedEvent)
{
// Ignore CompilationStartedEvent.
return null;
}
throw new InvalidOperationException("Unexpected compilation event of type " + e.GetType().Name);
}
示例11: MarkEventCompleteAsync
/// <summary>
/// Marks the given event as fully analyzed for the given analyzer.
/// </summary>
public Task MarkEventCompleteAsync(CompilationEvent compilationEvent, DiagnosticAnalyzer analyzer, CancellationToken cancellationToken)
{
return GetAnalyzerState(analyzer).MarkEventCompleteAsync(compilationEvent, cancellationToken);
}
示例12: TryStartProcessingEventAsync
/// <summary>
/// Attempts to start processing a compilation event for the given analyzer.
/// </summary>
/// <returns>
/// Returns null if the event has already been processed for the analyzer OR is currently being processed by another task.
/// Otherwise, returns a non-null state representing partial analysis state for the given event for the given analyzer.
/// </returns>
public Task<AnalyzerStateData> TryStartProcessingEventAsync(CompilationEvent compilationEvent, DiagnosticAnalyzer analyzer, CancellationToken cancellationToken)
{
return GetAnalyzerState(analyzer).TryStartProcessingEventAsync(compilationEvent, cancellationToken);
}
示例13: OnCompilationEventProcessedAsync
/// <summary>
/// Invoke this method at completion of event processing for the given analysis scope.
/// It updates the analysis state of this event for each analyzer and if the event has been fully processed for all analyzers, then removes it from our event cache.
/// </summary>
public async Task OnCompilationEventProcessedAsync(CompilationEvent compilationEvent, AnalysisScope analysisScope, CancellationToken cancellationToken)
{
// Analyze if the symbol and all its declaring syntax references are analyzed.
var symbolDeclaredEvent = compilationEvent as SymbolDeclaredCompilationEvent;
if (symbolDeclaredEvent != null)
{
await OnSymbolDeclaredEventProcessedAsync(symbolDeclaredEvent, analysisScope.Analyzers, cancellationToken).ConfigureAwait(false);
}
// Check if event is fully analyzed for all analyzers.
foreach (var analyzerState in _analyzerStates)
{
var eventAnalyzed = await analyzerState.IsEventAnalyzedAsync(compilationEvent, cancellationToken).ConfigureAwait(false);
if (!eventAnalyzed)
{
return;
}
}
// Remove the event from event map.
using (await _gate.DisposableWaitAsync(cancellationToken).ConfigureAwait(false))
{
UpdateEventsMap_NoLock(compilationEvent, add: false);
}
if (symbolDeclaredEvent != null)
{
AnalyzerDriver.RemoveCachedDeclaringReferences(symbolDeclaredEvent.Symbol, symbolDeclaredEvent.Compilation);
}
}
示例14: UpdateEventsMap_NoLock
private void UpdateEventsMap_NoLock(CompilationEvent compilationEvent, bool add)
{
var symbolEvent = compilationEvent as SymbolDeclaredCompilationEvent;
if (symbolEvent != null)
{
// Add/remove symbol events.
// Any diagnostics request for a tree should trigger symbol and syntax node analysis for symbols with at least one declaring reference in the tree.
foreach (var location in symbolEvent.Symbol.Locations)
{
if (location.SourceTree != null)
{
if (add)
{
AddPendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
}
else
{
RemovePendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
}
}
}
}
else
{
// Add/remove compilation unit completed events.
var compilationUnitCompletedEvent = compilationEvent as CompilationUnitCompletedEvent;
if (compilationUnitCompletedEvent != null)
{
var tree = compilationUnitCompletedEvent.SemanticModel.SyntaxTree;
if (add)
{
AddPendingSourceEvent_NoLock(tree, compilationEvent);
}
else
{
RemovePendingSourceEvent_NoLock(tree, compilationEvent);
}
}
else if (compilationEvent is CompilationStartedEvent || compilationEvent is CompilationCompletedEvent)
{
// Add/remove compilation events.
if (add)
{
_pendingNonSourceEvents.Add(compilationEvent);
}
else
{
_pendingNonSourceEvents.Remove(compilationEvent);
}
}
else
{
throw new InvalidOperationException("Unexpected compilation event of type " + compilationEvent.GetType().Name);
}
}
}
示例15: RemovePendingSourceEvent_NoLock
private void RemovePendingSourceEvent_NoLock(SyntaxTree tree, CompilationEvent compilationEvent)
{
HashSet<CompilationEvent> currentEvents;
if (_pendingSourceEvents.TryGetValue(tree, out currentEvents))
{
if (currentEvents.Remove(compilationEvent) && currentEvents.Count == 0)
{
_pendingSourceEvents.Remove(tree);
_compilationData.RemoveCachedSemanticModel(tree);
}
}
}