From a947b6cd9c547b3a1ee192f6536aab880cd9d327 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Tue, 11 Aug 2020 10:41:35 -0700 Subject: [PATCH] Fixes --- .../DiagnosticAnalyzer/AnalyzerDriver.cs | 4 +-- .../DiagnosticAnalyzer/AnalyzerExecutor.cs | 28 ++++++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs index debadb16a9c..1ea2010aee4 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs @@ -1211,7 +1211,7 @@ static ImmutableHashSet computeGeneratedCodeSymbolsInTree(SyntaxTree tr } } - private bool IsAnalyzerSuppressedForTree(DiagnosticAnalyzer analyzer, SyntaxTree tree, SyntaxTreeOptionsProvider options) + private bool IsAnalyzerSuppressedForTree(DiagnosticAnalyzer analyzer, SyntaxTree tree, SyntaxTreeOptionsProvider? options) { if (!SuppressedAnalyzersForTreeMap.TryGetValue(tree, out var suppressedAnalyzers)) { @@ -1221,7 +1221,7 @@ private bool IsAnalyzerSuppressedForTree(DiagnosticAnalyzer analyzer, SyntaxTree return suppressedAnalyzers.Contains(analyzer); } - private ImmutableHashSet ComputeSuppressedAnalyzersForTree(SyntaxTree tree, SyntaxTreeOptionsProvider options) + private ImmutableHashSet ComputeSuppressedAnalyzersForTree(SyntaxTree tree, SyntaxTreeOptionsProvider? options) { if (options is null) { diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs index 3f2c21b30ee..90f89b9c875 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs @@ -68,7 +68,11 @@ internal partial class AnalyzerExecutor private Func GetControlFlowGraph => _lazyGetControlFlowGraph ??= GetControlFlowGraphImpl; - private SyntaxTreeOptionsProvider SyntaxTreeOptions => _compilation.Options.SyntaxTreeOptionsProvider; + private bool IsAnalyzerSuppressedForTree(DiagnosticAnalyzer analyzer, SyntaxTree tree) + { + Debug.Assert(_isAnalyzerSuppressedForTree != null); + return _isAnalyzerSuppressedForTree(analyzer, tree, Compilation.Options.SyntaxTreeOptionsProvider); + } /// /// Creates to execute analyzer actions with given arguments @@ -690,10 +694,8 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana AnalyzerStateData? analyzerState, bool isGeneratedCode) { - Debug.Assert(_isAnalyzerSuppressedForTree != null); - if (isGeneratedCode && _shouldSkipAnalysisOnGeneratedCode(analyzer) || - _isAnalyzerSuppressedForTree(analyzer, semanticModel.SyntaxTree, SyntaxTreeOptions)) + IsAnalyzerSuppressedForTree(analyzer, semanticModel.SyntaxTree)) { return; } @@ -774,11 +776,10 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana bool isGeneratedCode) { Debug.Assert(file.SourceTree != null); - Debug.Assert(_isAnalyzerSuppressedForTree != null); var tree = file.SourceTree; if (isGeneratedCode && _shouldSkipAnalysisOnGeneratedCode(analyzer) || - _isAnalyzerSuppressedForTree(analyzer, tree, SyntaxTreeOptions)) + IsAnalyzerSuppressedForTree(analyzer, tree)) { return; } @@ -1060,10 +1061,9 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana Debug.Assert(CanHaveExecutableCodeBlock(declaredSymbol)); Debug.Assert(startActions.Any() || endActions.Any() || actions.Any()); Debug.Assert(!executableBlocks.IsEmpty); - Debug.Assert(_isAnalyzerSuppressedForTree != null); if (isGeneratedCode && _shouldSkipAnalysisOnGeneratedCode(analyzer) || - _isAnalyzerSuppressedForTree(analyzer, declaredNode.SyntaxTree, SyntaxTreeOptions)) + IsAnalyzerSuppressedForTree(analyzer, declaredNode.SyntaxTree)) { return; } @@ -1316,10 +1316,8 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana bool isGeneratedCode) where TLanguageKindEnum : struct { - Debug.Assert(_isAnalyzerSuppressedForTree != null); - if (isGeneratedCode && _shouldSkipAnalysisOnGeneratedCode(analyzer) || - _isAnalyzerSuppressedForTree(analyzer, model.SyntaxTree, SyntaxTreeOptions)) + IsAnalyzerSuppressedForTree(analyzer, model.SyntaxTree)) { return; } @@ -1456,10 +1454,8 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana OperationAnalyzerStateData? analyzerState, bool isGeneratedCode) { - Debug.Assert(_isAnalyzerSuppressedForTree != null); - if (isGeneratedCode && _shouldSkipAnalysisOnGeneratedCode(analyzer) || - _isAnalyzerSuppressedForTree(analyzer, model.SyntaxTree, SyntaxTreeOptions)) + IsAnalyzerSuppressedForTree(analyzer, model.SyntaxTree)) { return; } @@ -2014,12 +2010,10 @@ private ControlFlowGraph GetControlFlowGraphImpl(IOperation operation) private bool IsAnalyzerSuppressedForSymbol(DiagnosticAnalyzer analyzer, ISymbol symbol) { - Debug.Assert(_isAnalyzerSuppressedForTree != null); - foreach (var location in symbol.Locations) { if (location.SourceTree != null && - !_isAnalyzerSuppressedForTree(analyzer, location.SourceTree, SyntaxTreeOptions)) + IsAnalyzerSuppressedForTree(analyzer, location.SourceTree)) { return false; } -- GitLab