コード例 #1
0
 private static bool HasSemanticDocumentActions(AnalyzerActions analyzerActions)
 {
     return analyzerActions.SymbolActionsCount > 0 ||
         analyzerActions.SyntaxNodeActionsCount > 0 ||
         analyzerActions.SemanticModelActionsCount > 0 ||
         analyzerActions.CodeBlockActionsCount > 0 ||
         analyzerActions.CodeBlockStartActionsCount > 0;
 }
コード例 #2
0
        internal static AnalyzerActionCounts Create(AnalyzerActions analyzerActions)
        {
            if (analyzerActions == null)
            {
                return Empty;
            }

            return new AnalyzerActionCounts(analyzerActions);
        }
コード例 #3
0
 public void SetAnalyzerTypeCount(AnalyzerActions analyzerActions)
 {
     Counts[0] = analyzerActions.CodeBlockEndActionsCount;
     Counts[1] = analyzerActions.CodeBlockStartActionsCount;
     Counts[2] = analyzerActions.CompilationEndActionsCount;
     Counts[3] = analyzerActions.CompilationStartActionsCount;
     Counts[4] = analyzerActions.SemanticModelActionsCount;
     Counts[5] = analyzerActions.SymbolActionsCount;
     Counts[6] = analyzerActions.SyntaxNodeActionsCount;
     Counts[7] = analyzerActions.SyntaxTreeActionsCount;
 }
コード例 #4
0
 private AnalyzerActionCounts(AnalyzerActions analyzerActions)
 {
     CompilationStartActionsCount = analyzerActions.CompilationStartActionsCount;
     CompilationEndActionsCount = analyzerActions.CompilationEndActionsCount;
     CompilationActionsCount = analyzerActions.CompilationActionsCount;
     SyntaxTreeActionsCount = analyzerActions.SyntaxTreeActionsCount;
     SemanticModelActionsCount = analyzerActions.SemanticModelActionsCount;
     SymbolActionsCount = analyzerActions.SymbolActionsCount;
     SyntaxNodeActionsCount = analyzerActions.SyntaxNodeActionsCount;
     CodeBlockStartActionsCount = analyzerActions.CodeBlockStartActionsCount;
     CodeBlockEndActionsCount = analyzerActions.CodeBlockEndActionsCount;
     CodeBlockActionsCount = analyzerActions.CodeBlockActionsCount;
 }
コード例 #5
0
 internal ActionCounts(AnalyzerActions analyzerActions)
 {
     analyzerActions = analyzerActions ?? AnalyzerActions.Empty;
     CompilationStartActionsCount = analyzerActions.CompilationStartActionsCount;
     CompilationEndActionsCount = analyzerActions.CompilationEndActionsCount;
     CompilationActionsCount = analyzerActions.CompilationActionsCount;
     SyntaxTreeActionsCount = analyzerActions.SyntaxTreeActionsCount;
     SemanticModelActionsCount = analyzerActions.SemanticModelActionsCount;
     SymbolActionsCount = analyzerActions.SymbolActionsCount;
     SyntaxNodeActionsCount = analyzerActions.SyntaxNodeActionsCount;
     CodeBlockStartActionsCount = analyzerActions.CodeBlockStartActionsCount;
     CodeBlockEndActionsCount = analyzerActions.CodeBlockEndActionsCount;
     CodeBlockActionsCount = analyzerActions.CodeBlockActionsCount;
 }
コード例 #6
0
        public void UpdateAnalyzerTypeCount(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions)
        {
            var telemetry = DiagnosticAnalyzerLogger.AllowsTelemetry(_owner, analyzer);

            ImmutableInterlocked.AddOrUpdate(
                ref _analyzerInfoMap,
                analyzer.GetType(),
                addValue: new AnalyzerInfo(analyzer, analyzerActions, telemetry),
                updateValueFactory: (k, ai) =>
                {
                    ai.SetAnalyzerTypeCount(analyzerActions);
                    return ai;
                });
        }
コード例 #7
0
            public AnalyzerInfo(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions, bool telemetry)
            {
                CLRType = analyzer.GetType();
                Telemetry = telemetry;

                Counts[0] = analyzerActions.CodeBlockEndActionsCount;
                Counts[1] = analyzerActions.CodeBlockStartActionsCount;
                Counts[2] = analyzerActions.CompilationEndActionsCount;
                Counts[3] = analyzerActions.CompilationStartActionsCount;
                Counts[4] = analyzerActions.SemanticModelActionsCount;
                Counts[5] = analyzerActions.SymbolActionsCount;
                Counts[6] = analyzerActions.SyntaxNodeActionsCount;
                Counts[7] = analyzerActions.SyntaxTreeActionsCount;
            }
コード例 #8
0
        /// <summary>
        /// Initializes the compilation for the analyzer driver.
        /// It also computes and initializes <see cref="analyzerActions"/> and <see cref="_symbolActionsByKind"/>.
        /// Finally, it initializes and starts the <see cref="_primaryTask"/> for the driver.
        /// </summary>
        /// <remarks>
        /// NOTE: This method must only be invoked from <see cref="AnalyzerDriver.Create(Compilation, ImmutableArray{DiagnosticAnalyzer}, AnalyzerOptions, AnalyzerManager, Action{Diagnostic}, out Compilation, CancellationToken)"/>.
        /// </remarks>
        private void Initialize(Compilation comp, AnalyzerExecutor analyzerExecutor, CancellationToken cancellationToken)
        {
            try
            {
                Debug.Assert(_compilation == null);
                Debug.Assert(comp.EventQueue == this.CompilationEventQueue);

                _compilation = comp;
                this.analyzerExecutor = analyzerExecutor;

                // Compute the set of effective actions based on suppression, and running the initial analyzers
                var analyzerActionsTask = GetAnalyzerActionsAsync(_analyzers, analyzerManager, analyzerExecutor);
                var initializeTask = analyzerActionsTask.ContinueWith(t =>
                {
                    this.analyzerActions = t.Result;
                    _symbolActionsByKind = MakeSymbolActionsByKind();
                    _semanticModelActionsMap = MakeSemanticModelActionsByAnalyzer();
                    _compilationActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationActions);
                    _compilationEndActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationEndActions);
                }, cancellationToken, TaskContinuationOptions.None, TaskScheduler.Default);

                // create the primary driver task.
                cancellationToken.ThrowIfCancellationRequested();
                _primaryTask = Task.Run(async () =>
                    {
                        await initializeTask.ConfigureAwait(false);

                        await ProcessCompilationEventsAsync(cancellationToken).ConfigureAwait(false);
                    }, 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();
                }
            }
        }
コード例 #9
0
 internal AnalyzerActionCounts(AnalyzerActions analyzerActions) :
     this(
         analyzerActions?.CompilationStartActionsCount ?? 0,
         analyzerActions?.CompilationEndActionsCount ?? 0,
         analyzerActions?.CompilationActionsCount ?? 0,
         analyzerActions?.SyntaxTreeActionsCount ?? 0,
         analyzerActions?.SemanticModelActionsCount ?? 0,
         analyzerActions?.SymbolActionsCount ?? 0,
         analyzerActions?.SyntaxNodeActionsCount ?? 0,
         analyzerActions?.CodeBlockStartActionsCount ?? 0,
         analyzerActions?.CodeBlockEndActionsCount ?? 0,
         analyzerActions?.CodeBlockActionsCount ?? 0,
         analyzerActions?.OperationActionsCount ?? 0,
         analyzerActions?.OperationBlockStartActionsCount ?? 0,
         analyzerActions?.OperationBlockEndActionsCount ?? 0,
         analyzerActions?.OperationBlockActionsCount ?? 0)
 {
 }
コード例 #10
0
        private AnalyzerActionCounts(AnalyzerActions analyzerActions)
        {
            CompilationStartActionsCount = analyzerActions.CompilationStartActionsCount;
            CompilationEndActionsCount = analyzerActions.CompilationEndActionsCount;
            CompilationActionsCount = analyzerActions.CompilationActionsCount;
            SyntaxTreeActionsCount = analyzerActions.SyntaxTreeActionsCount;
            SemanticModelActionsCount = analyzerActions.SemanticModelActionsCount;
            SymbolActionsCount = analyzerActions.SymbolActionsCount;
            SyntaxNodeActionsCount = analyzerActions.SyntaxNodeActionsCount;
            CodeBlockStartActionsCount = analyzerActions.CodeBlockStartActionsCount;
            CodeBlockEndActionsCount = analyzerActions.CodeBlockEndActionsCount;
            CodeBlockActionsCount = analyzerActions.CodeBlockActionsCount;
            OperationActionsCount = analyzerActions.OperationActionsCount;
            OperationBlockStartActionsCount = analyzerActions.OperationBlockStartActionsCount;
            OperationBlockEndActionsCount = analyzerActions.OperationBlockEndActionsCount;
            OperationBlockActionsCount = analyzerActions.OperationBlockActionsCount;

            HasAnyExecutableCodeActions = CodeBlockActionsCount > 0 ||
                CodeBlockStartActionsCount > 0 ||
                SyntaxNodeActionsCount > 0 ||
                OperationActionsCount > 0 ||
                OperationBlockActionsCount > 0 ||
                OperationBlockStartActionsCount > 0;
        }
コード例 #11
0
ファイル: AnalyzerDriver.cs プロジェクト: RoryVL/roslyn
        /// <summary>
        /// Initializes the <see cref="analyzerActions"/> and related actions maps for the analyzer driver.
        /// It kicks off the <see cref="WhenInitializedTask"/> task for initialization.
        /// Note: This method must be invoked exactly once on the driver.
        /// </summary>
        private void Initialize(AnalyzerExecutor analyzerExecutor, DiagnosticQueue diagnosticQueue, CompilationData compilationData, CancellationToken cancellationToken)
        {
            try
            {
                Debug.Assert(_initializeTask == null);

                this.analyzerExecutor = analyzerExecutor;
                this.compilationData = compilationData;
                this.DiagnosticQueue = diagnosticQueue;

                // Compute the set of effective actions based on suppression, and running the initial analyzers
                _initializeTask = Task.Run(async () =>
                {
                    var unsuppressedAnalyzers = GetUnsuppressedAnalyzers(analyzers, analyzerManager, analyzerExecutor);
                    this.analyzerActions = await GetAnalyzerActionsAsync(unsuppressedAnalyzers, analyzerManager, analyzerExecutor).ConfigureAwait(false);
                    _analyzerGateMap = await GetAnalyzerGateMapAsync(unsuppressedAnalyzers, analyzerManager, analyzerExecutor).ConfigureAwait(false);

                    _generatedCodeAnalysisFlagsMap = await GetGeneratedCodeAnalysisFlagsAsync(unsuppressedAnalyzers, analyzerManager, analyzerExecutor).ConfigureAwait(false);
                    _doNotAnalyzeGeneratedCode = ShouldSkipAnalysisOnGeneratedCode(unsuppressedAnalyzers);
                    _treatAllCodeAsNonGeneratedCode = ShouldTreatAllCodeAsNonGeneratedCode(unsuppressedAnalyzers, _generatedCodeAnalysisFlagsMap);
                    _lazyGeneratedCodeFilesMap = _treatAllCodeAsNonGeneratedCode ? null : new Dictionary<SyntaxTree, bool>();
                    _lazyGeneratedCodeSymbolsMap = _treatAllCodeAsNonGeneratedCode ? null : new Dictionary<SyntaxTree, ImmutableHashSet<ISymbol>>();
                    _generatedCodeAttribute = analyzerExecutor.Compilation?.GetTypeByMetadataName("System.CodeDom.Compiler.GeneratedCodeAttribute");

                    _symbolActionsByKind = MakeSymbolActionsByKind();
                    _semanticModelActionsMap = MakeSemanticModelActionsByAnalyzer();
                    _syntaxTreeActionsMap = MakeSyntaxTreeActionsByAnalyzer();
                    _compilationActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationActions);
                    _compilationEndActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationEndActions);
                }, cancellationToken);

                // create the primary driver task. 
                cancellationToken.ThrowIfCancellationRequested();

                _initializeSucceeded = true;
            }
            finally
            {
                if (_initializeTask == null)
                {
                    // Set initializeTask to be a cancelled task.
                    var tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _initializeTask = tcs.Task;

                    // Set primaryTask to be a cancelled task.
                    tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _primaryTask = tcs.Task;

                    // Try to set the DiagnosticQueue to be complete.
                    this.DiagnosticQueue.TryComplete();
                }
            }
        }
コード例 #12
0
ファイル: AnalyzerDriver.cs プロジェクト: RoryVL/roslyn
        private static async Task<AnalyzerActions> GetAnalyzerActionsAsync(
            ImmutableArray<DiagnosticAnalyzer> analyzers,
            AnalyzerManager analyzerManager,
            AnalyzerExecutor analyzerExecutor)
        {
            var allAnalyzerActions = new AnalyzerActions();
            foreach (var analyzer in analyzers)
            {
                Debug.Assert(!IsDiagnosticAnalyzerSuppressed(analyzer, analyzerExecutor.Compilation.Options, analyzerManager, analyzerExecutor));

                var analyzerActions = await analyzerManager.GetAnalyzerActionsAsync(analyzer, analyzerExecutor).ConfigureAwait(false);
                if (analyzerActions != null)
                {
                    allAnalyzerActions = allAnalyzerActions.Append(analyzerActions);
                }
            }

            return allAnalyzerActions;
        }
コード例 #13
0
        private AnalyzerActions GetPerCompilationAnalyzerActions(
            DiagnosticAnalyzer analyzer,
            AnalyzerActions sessionActions,
            Compilation compilation,
            Action<Diagnostic> addDiagnostic)
        {
            Contract.ThrowIfFalse(sessionActions.CompilationStartActionsCount > 0);

            var compilationActionsMap = s_compilationActionsTable.GetOrCreateValue(compilation);
            AnalyzerActions result;
            if (compilationActionsMap.TryGetValue(analyzer, out result))
            {
                return result;
            }

            result = AnalyzerDriverHelper.ExecuteCompilationStartActions(sessionActions, analyzer, compilation,
                _analyzerOptions, addDiagnostic, CatchAnalyzerException, _cancellationToken);

            if (!compilationActionsMap.TryAdd(analyzer, result))
            {
                return compilationActionsMap[analyzer];
            }

            return result;
        }
コード例 #14
0
ファイル: AnalyzerDriver.cs プロジェクト: elemk0vv/roslyn-1
        private static void VerifyArguments(
            Compilation compilation,
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            DiagnosticAnalyzer analyzer,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (compilation == null)
            {
                throw new ArgumentNullException(nameof(compilation));
            }

            if (analyzer == null)
            {
                throw new ArgumentNullException(nameof(analyzer));
            }

            VerifyArguments(actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }
コード例 #15
0
ファイル: AnalyzerDriver.cs プロジェクト: elemk0vv/roslyn-1
        private static void VerifyArguments(
            SyntaxTree syntaxTree,
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            VerifyArguments(actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }
コード例 #16
0
ファイル: AnalyzerDriver.cs プロジェクト: JRobertGit/roslyn
        private static Task<AnalyzerActions> GetAnalyzerActionsAsync(
            ImmutableArray<DiagnosticAnalyzer> analyzers,
            AnalyzerManager analyzerManager,
            AnalyzerExecutor analyzerExecutor)
        {
            return Task.Run(async () =>
            {
                AnalyzerActions allAnalyzerActions = new AnalyzerActions();
                foreach (var analyzer in analyzers)
                {
                    if (!IsDiagnosticAnalyzerSuppressed(analyzer, analyzerExecutor.Compilation.Options, analyzerManager, analyzerExecutor))
                    {
                        var analyzerActions = await analyzerManager.GetAnalyzerActionsAsync(analyzer, analyzerExecutor).ConfigureAwait(false);
                        if (analyzerActions != null)
                        {
                            allAnalyzerActions = allAnalyzerActions.Append(analyzerActions);
                        }
                    }
                }

                return allAnalyzerActions;
            }, analyzerExecutor.CancellationToken);
        }
コード例 #17
0
ファイル: AnalyzerDriver.cs プロジェクト: elemk0vv/roslyn-1
        internal static void VerifyArguments(
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            VerifyArguments(analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }
コード例 #18
0
        public static void UpdateAnalyzerTypeCount(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions, DiagnosticLogAggregator logAggregator)
        {
            if (analyzerActions == null || analyzer == null || logAggregator == null)
            {
                return;
            }

            logAggregator.UpdateAnalyzerTypeCount(analyzer, analyzerActions);
        }
コード例 #19
0
ファイル: AnalyzerDriver.cs プロジェクト: JRobertGit/roslyn
        /// <summary>
        /// Initializes the <see cref="analyzerActions"/> and related actions maps for the analyzer driver.
        /// It kicks off the <see cref="WhenInitializedTask"/> task for initialization.
        /// Note: This method must be invoked exactly once on the driver.
        /// </summary>
        private void Initialize(AnalyzerExecutor analyzerExecutor, DiagnosticQueue diagnosticQueue, CancellationToken cancellationToken)
        {
            try
            {
                Debug.Assert(_initializeTask == null);

                this.analyzerExecutor = analyzerExecutor;
                this.DiagnosticQueue = diagnosticQueue;

                // Compute the set of effective actions based on suppression, and running the initial analyzers
                var analyzerActionsTask = GetAnalyzerActionsAsync(analyzers, analyzerManager, analyzerExecutor);
                _initializeTask = analyzerActionsTask.ContinueWith(t =>
                {
                    this.analyzerActions = t.Result;
                    _symbolActionsByKind = MakeSymbolActionsByKind();
                    _semanticModelActionsMap = MakeSemanticModelActionsByAnalyzer();
                    _syntaxTreeActionsMap = MakeSyntaxTreeActionsByAnalyzer();
                    _compilationActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationActions);
                    _compilationEndActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationEndActions);
                }, cancellationToken, TaskContinuationOptions.None, TaskScheduler.Default);

                // create the primary driver task.
                cancellationToken.ThrowIfCancellationRequested();

                _initializeSucceeded = true;
            }
            finally
            {
                if (_initializeTask == null)
                {
                    // Set initializeTask to be a cancelled task.
                    var tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _initializeTask = tcs.Task;

                    // Set primaryTask to be a cancelled task.
                    tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _primaryTask = tcs.Task;

                    // Try to set the DiagnosticQueue to be complete.
                    this.DiagnosticQueue.TryComplete();
                }
            }
        }
コード例 #20
0
ファイル: AnalyzerDriver.cs プロジェクト: elemk0vv/roslyn-1
        private static void VerifyArguments(
            IEnumerable<ISymbol> symbols,
            Compilation compilation,
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException(nameof(symbols));
            }

            if (symbols.Any(s => s == null))
            {
                throw new ArgumentException(CodeAnalysisResources.ArgumentElementCannotBeNull, nameof(symbols));
            }

            VerifyArguments(compilation, actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }