From e182acda64d13d1d181e8524cf99dd3a11467b61 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Tue, 10 Mar 2020 11:52:46 -0700 Subject: [PATCH] Move all the shared layer analyzers to use the new options and code style types - this cleans up the `#if CODE_STYLE` mess from our shared layer analyzers. --- ...SwitchStatementToExpressionDiagnosticAnalyzer.cs | 7 +------ .../CSharpTypeStyleDiagnosticAnalyzerBase.cs | 13 ++++++------- .../AbstractFileHeaderDiagnosticAnalyzer.cs | 8 ++------ .../AbstractFileHeaderCodeFixProvider.cs | 6 +----- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/Analyzers/CSharp/Analyzers/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs b/src/Analyzers/CSharp/Analyzers/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs index f133313180e03..190c19264a9d6 100644 --- a/src/Analyzers/CSharp/Analyzers/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs +++ b/src/Analyzers/CSharp/Analyzers/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs @@ -6,16 +6,11 @@ using System.Globalization; using System.Linq; using Microsoft.CodeAnalysis.CodeStyle; +using Microsoft.CodeAnalysis.CSharp.CodeStyle; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.PooledObjects; -#if CODE_STYLE -using Microsoft.CodeAnalysis.CSharp.Internal.CodeStyle; -#else -using Microsoft.CodeAnalysis.CSharp.CodeStyle; -#endif - namespace Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression { using Constants = ConvertSwitchStatementToExpressionConstants; diff --git a/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs b/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs index 7ab8e7c35765b..9a2e38c021a14 100644 --- a/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs +++ b/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs @@ -4,18 +4,17 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis.CodeStyle; +using Microsoft.CodeAnalysis.CSharp.CodeStyle; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Utilities; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; #if CODE_STYLE using OptionSet = Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptions; -using Microsoft.CodeAnalysis.CSharp.Internal.CodeStyle; -using Microsoft.CodeAnalysis.Internal.Options; #else -using Microsoft.CodeAnalysis.CSharp.CodeStyle; -using Microsoft.CodeAnalysis.Options; +using OptionSet = Microsoft.CodeAnalysis.Options.OptionSet; #endif namespace Microsoft.CodeAnalysis.CSharp.Diagnostics.TypeStyle @@ -42,9 +41,9 @@ public override bool OpenFileOnly(OptionSet options) var whereApparentOption = options.GetOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent).Notification; var wherePossibleOption = options.GetOption(CSharpCodeStyleOptions.VarElsewhere).Notification; - return !(forIntrinsicTypesOption == NotificationOption.Warning || forIntrinsicTypesOption == NotificationOption.Error || - whereApparentOption == NotificationOption.Warning || whereApparentOption == NotificationOption.Error || - wherePossibleOption == NotificationOption.Warning || wherePossibleOption == NotificationOption.Error); + return !(forIntrinsicTypesOption == NotificationOption2.Warning || forIntrinsicTypesOption == NotificationOption2.Error || + whereApparentOption == NotificationOption2.Warning || whereApparentOption == NotificationOption2.Error || + wherePossibleOption == NotificationOption2.Warning || wherePossibleOption == NotificationOption2.Error); } protected override void InitializeWorker(AnalysisContext context) diff --git a/src/Analyzers/Core/Analyzers/FileHeaders/AbstractFileHeaderDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/FileHeaders/AbstractFileHeaderDiagnosticAnalyzer.cs index fba3bfd8bafca..34c4cafe1f8c8 100644 --- a/src/Analyzers/Core/Analyzers/FileHeaders/AbstractFileHeaderDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/FileHeaders/AbstractFileHeaderDiagnosticAnalyzer.cs @@ -9,10 +9,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Roslyn.Utilities; -#if CODE_STYLE -using Microsoft.CodeAnalysis.Internal.Options; -#endif - namespace Microsoft.CodeAnalysis.FileHeaders { internal abstract class AbstractFileHeaderDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer @@ -20,7 +16,7 @@ internal abstract class AbstractFileHeaderDiagnosticAnalyzer : AbstractBuiltInCo protected AbstractFileHeaderDiagnosticAnalyzer(string language) : base( IDEDiagnosticIds.FileHeaderMismatch, - CodeStyleOptions.FileHeaderTemplate, + CodeStyleOptions2.FileHeaderTemplate, language, new LocalizableResourceString(nameof(AnalyzersResources.The_file_header_is_missing_or_not_located_at_the_top_of_the_file), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), new LocalizableResourceString(nameof(AnalyzersResources.A_source_file_is_missing_a_required_header), AnalyzersResources.ResourceManager, typeof(AnalyzersResources))) @@ -55,7 +51,7 @@ private void HandleSyntaxTree(SyntaxTreeAnalysisContext context) return; } - if (!context.Options.TryGetEditorConfigOption(CodeStyleOptions.FileHeaderTemplate, tree, out string fileHeaderTemplate) + if (!context.Options.TryGetEditorConfigOption(CodeStyleOptions2.FileHeaderTemplate, tree, out string fileHeaderTemplate) || string.IsNullOrEmpty(fileHeaderTemplate)) { return; diff --git a/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs index 75721c785b3a2..50c8fa5a4f97f 100644 --- a/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs @@ -20,10 +20,6 @@ using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; -#if CODE_STYLE -using CodeStyleOptions = Microsoft.CodeAnalysis.Internal.Options.CodeStyleOptions; -#endif - namespace Microsoft.CodeAnalysis.FileHeaders { internal abstract class AbstractFileHeaderCodeFixProvider : CodeFixProvider @@ -62,7 +58,7 @@ private async Task GetTransformedSyntaxRootAsync(Document document, var tree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false); - if (!document.Project.AnalyzerOptions.TryGetEditorConfigOption(CodeStyleOptions.FileHeaderTemplate, tree, out string fileHeaderTemplate) + if (!document.Project.AnalyzerOptions.TryGetEditorConfigOption(CodeStyleOptions2.FileHeaderTemplate, tree, out string fileHeaderTemplate) || string.IsNullOrEmpty(fileHeaderTemplate)) { // This exception would show up as a gold bar, but as indicated we do not believe this is reachable.