當前位置: 首頁>>代碼示例>>C#>>正文


C# Diagnostics.AnalysisScope類代碼示例

本文整理匯總了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);
                    }
                }
            }
        }
開發者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


注:本文中的Microsoft.CodeAnalysis.Diagnostics.AnalysisScope類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。