本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.AnalysisScope类的典型用法代码示例。如果您正苦于以下问题:C# AnalysisScope类的具体用法?C# AnalysisScope怎么用?C# AnalysisScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnalysisScope类属于Microsoft.CodeAnalysis.Diagnostics命名空间,在下文中一共展示了AnalysisScope类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
}
}
开发者ID:noahstein,项目名称:roslyn,代码行数:25,代码来源:AnalysisResult.cs
示例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);
}
}
}
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:46,代码来源:AnalysisResultBuilder.cs
示例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
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:9,代码来源:CompilationWithAnalyzers.cs
示例4: ProcessCompilationCompleted
private void ProcessCompilationCompleted(CompilationCompletedEvent endEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
{
ExecuteCompilationActions(_compilationEndActionsMap, endEvent, analysisScope, analysisStateOpt, cancellationToken);
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:4,代码来源:AnalyzerDriver.cs
示例5: ExecuteDeclaringReferenceActions
protected abstract void ExecuteDeclaringReferenceActions(SymbolDeclaredCompilationEvent symbolEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken);
开发者ID:JRobertGit,项目名称:roslyn,代码行数:1,代码来源:AnalyzerDriver.cs
示例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();
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:22,代码来源:AnalyzerDriver.cs
示例7: 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
示例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;
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:54,代码来源:AnalyzerDriver.cs
示例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);
}
}
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:27,代码来源:AnalyzerDriver.cs
示例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);
}
}
}
开发者ID:noahstein,项目名称:roslyn,代码行数:16,代码来源:AnalysisResult.cs
示例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);
}
}
开发者ID:noahstein,项目名称:roslyn,代码行数:11,代码来源:AnalysisResult.cs
示例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);
}
}
}
开发者ID:noahstein,项目名称:roslyn,代码行数:13,代码来源:AnalysisResult.cs
示例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();
}
开发者ID:noahstein,项目名称:roslyn,代码行数:29,代码来源:AnalysisResult.cs
示例14: GetDiagnostics
public ImmutableArray<Diagnostic> GetDiagnostics(AnalysisScope analysisScope, bool getLocalDiagnostics, bool getNonLocalDiagnostics)
{
lock (_gate)
{
return GetDiagnostics_NoLock(analysisScope, getLocalDiagnostics, getNonLocalDiagnostics);
}
}
开发者ID:noahstein,项目名称:roslyn,代码行数:7,代码来源:AnalysisResult.cs
示例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);
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:14,代码来源:CompilationWithAnalyzers.cs
示例16: AttachQueueAndStartProcessingEvents
/// <summary>
/// Attaches event queue to the driver and start processing all events pertaining to the given analysis scope.
/// </summary>
/// <param name="eventQueue">Compilation events to analyze.</param>
/// <param name="analysisScope">Scope of analysis.</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 void AttachQueueAndStartProcessingEvents(AsyncQueue<CompilationEvent> eventQueue, AnalysisScope analysisScope, CancellationToken cancellationToken)
{
try
{
if (_initializeSucceeded)
{
this.CompilationEventQueue = eventQueue;
_queueRegistration = cancellationToken.Register(() =>
{
this.CompilationEventQueue.TryComplete();
this.DiagnosticQueue.TryComplete();
});
_primaryTask = ExecutePrimaryAnalysisTaskAsync(analysisScope, analysisStateOpt: null, usingPrePopulatedEventQueue: false, cancellationToken: cancellationToken)
.ContinueWith(c => DiagnosticQueue.TryComplete(), cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
}
finally
{
if (_primaryTask == null)
{
// Set primaryTask to be a cancelled task.
var tcs = new TaskCompletionSource<int>();
tcs.SetCanceled();
_primaryTask = tcs.Task;
// Try to set the DiagnosticQueue to be complete.
this.DiagnosticQueue.TryComplete();
}
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:38,代码来源:AnalyzerDriver.cs
示例17: ExecutePrimaryAnalysisTaskAsync
private async Task ExecutePrimaryAnalysisTaskAsync(AnalysisScope analysisScope, AnalysisState analysisStateOpt, bool usingPrePopulatedEventQueue, CancellationToken cancellationToken)
{
Debug.Assert(analysisScope != null);
Debug.Assert(WhenInitializedTask != null);
await WhenInitializedTask.ConfigureAwait(false);
if (WhenInitializedTask.IsFaulted)
{
OnDriverException(WhenInitializedTask, this.analyzerExecutor, analysisScope.Analyzers);
}
else if (!WhenInitializedTask.IsCanceled)
{
this.analyzerExecutor = this.analyzerExecutor.WithCancellationToken(cancellationToken);
await ProcessCompilationEventsAsync(analysisScope, analysisStateOpt, usingPrePopulatedEventQueue, cancellationToken).ConfigureAwait(false);
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:18,代码来源:AnalyzerDriver.cs
示例18: GetAnalyzerDiagnosticsCoreAsync
private async Task<ImmutableArray<Diagnostic>> GetAnalyzerDiagnosticsCoreAsync(ImmutableArray<DiagnosticAnalyzer> analyzers, bool includeCompilerDiagnostics, bool includeSourceEvents, bool includeNonSourceEvents, bool forceCompleteCompilation, CancellationToken cancellationToken)
{
Debug.Assert(!includeCompilerDiagnostics || forceCompleteCompilation);
await WaitForActiveAnalysisTasksAsync(cancellationToken).ConfigureAwait(false);
var diagnostics = ImmutableArray<Diagnostic>.Empty;
var analysisScope = new AnalysisScope(_compilation, analyzers, _analysisOptions.ConcurrentAnalysis, categorizeDiagnostics: true);
Action generateCompilationEvents = () =>
{
if (forceCompleteCompilation)
{
// Invoke GetDiagnostics to populate the compilation's CompilationEvent queue.
// Discard the returned diagnostics.
var compDiagnostics = _compilation.GetDiagnostics(cancellationToken);
if (includeCompilerDiagnostics)
{
diagnostics = compDiagnostics;
}
}
};
Func<AsyncQueue<CompilationEvent>> getEventQueue = () =>
GetPendingEvents(analyzers, includeSourceEvents, includeNonSourceEvents);
// Compute the analyzer diagnostics for the given analysis scope.
await ComputeAnalyzerDiagnosticsAsync(analysisScope, generateCompilationEvents, getEventQueue, newTaskToken: 0, cancellationToken: cancellationToken).ConfigureAwait(false);
// Return computed analyzer diagnostics for the given analysis scope.
var analyzerDiagnostics = _analysisResult.GetDiagnostics(analysisScope, getLocalDiagnostics: includeSourceEvents, getNonLocalDiagnostics: includeNonSourceEvents);
return diagnostics.AddRange(analyzerDiagnostics);
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:33,代码来源:CompilationWithAnalyzers.cs
示例19: CreateAndAttachToCompilation
// internal for testing purposes
internal static AnalyzerDriver CreateAndAttachToCompilation(
Compilation compilation,
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerOptions options,
AnalyzerManager analyzerManager,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
bool reportAnalyzer,
out Compilation newCompilation,
CancellationToken cancellationToken)
{
AnalyzerDriver analyzerDriver = compilation.AnalyzerForLanguage(analyzers, analyzerManager);
newCompilation = compilation.WithEventQueue(new AsyncQueue<CompilationEvent>());
var categorizeDiagnostics = false;
var analysisOptions = new CompilationWithAnalyzersOptions(options, onAnalyzerException, concurrentAnalysis: true, logAnalyzerExecutionTime: reportAnalyzer);
analyzerDriver.Initialize(newCompilation, analysisOptions, categorizeDiagnostics, cancellationToken);
var analysisScope = new AnalysisScope(newCompilation, analyzers, concurrentAnalysis: newCompilation.Options.ConcurrentBuild, categorizeDiagnostics: categorizeDiagnostics);
analyzerDriver.AttachQueueAndStartProcessingEvents(newCompilation.EventQueue, analysisScope, cancellationToken: cancellationToken);
return analyzerDriver;
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:22,代码来源:AnalyzerDriver.cs
示例20: GetAnalyzerSyntaxDiagnosticsCoreAsync
private async Task<ImmutableArray<Diagnostic>> GetAnalyzerSyntaxDiagnosticsCoreAsync(SyntaxTree tree, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
{
try
{
var taskToken = Interlocked.Increment(ref _currentToken);
var analysisScope = new AnalysisScope(analyzers, tree, filterSpan: null, syntaxAnalysis: true, concurrentAnalysis: _analysisOptions.ConcurrentAnalysis, categorizeDiagnostics: true);
Action generateCompilationEvents = null;
Func<AsyncQueue<CompilationEvent>> getEventQueue = () => s_EmptyEventQueue;
// Compute the analyzer diagnostics for the given analysis scope.
await ComputeAnalyzerDiagnosticsAsync(analysisScope, generateCompilationEvents, getEventQueue, taskToken, cancellationToken).ConfigureAwait(false);
// Return computed analyzer diagnostics for the given analysis scope.
return _analysisResult.GetDiagnostics(analysisScope, getLocalDiagnostics: true, getNonLocalDiagnostics: false);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
开发者ID:JRobertGit,项目名称:roslyn,代码行数:21,代码来源:CompilationWithAnalyzers.cs
注:本文中的Microsoft.CodeAnalysis.Diagnostics.AnalysisScope类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论