Skip to content

Commit

Permalink
Move all the shared layer analyzers to use the new options and code s…
Browse files Browse the repository at this point in the history
…tyle types - this cleans up the `#if CODE_STYLE` mess from our shared layer analyzers.
  • Loading branch information
mavasani committed Mar 10, 2020
1 parent e96fd8f commit e182acd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
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
{
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)))
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +58,7 @@ private async Task<SyntaxNode> 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.
Expand Down

0 comments on commit e182acd

Please sign in to comment.