diff --git a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs index 539d47eb743e1..57ae84194335c 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs @@ -2,25 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.AddAccessibilityModifiers; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Host.Mef; namespace Microsoft.CodeAnalysis.CSharp.AddAccessibilityModifiers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddAccessibilityModifiers), Shared] -internal class CSharpAddAccessibilityModifiersCodeFixProvider : AbstractAddAccessibilityModifiersCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddAccessibilityModifiersCodeFixProvider() : AbstractAddAccessibilityModifiersCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddAccessibilityModifiersCodeFixProvider() - { - } - protected override SyntaxNode MapToDeclarator(SyntaxNode node) { switch (node) diff --git a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs index 265d06d8b08c1..62b52a9e97e5f 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs @@ -10,11 +10,6 @@ namespace Microsoft.CodeAnalysis.CSharp.AddAccessibilityModifiers; [ExportLanguageService(typeof(IAddAccessibilityModifiersService), LanguageNames.CSharp), Shared] -internal class CSharpAddAccessibilityModifiersService : CSharpAddAccessibilityModifiers, IAddAccessibilityModifiersService -{ - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpAddAccessibilityModifiersService() - { - } -} +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpAddAccessibilityModifiersService() : CSharpAddAccessibilityModifiers, IAddAccessibilityModifiersService; diff --git a/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs index d5bf25d66e50a..35252af110f14 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs @@ -14,7 +14,9 @@ namespace Microsoft.CodeAnalysis.CSharp.AddAnonymousTypeMemberName; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddAnonymousTypeMemberName), Shared] -internal class CSharpAddAnonymousTypeMemberNameCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddAnonymousTypeMemberNameCodeFixProvider() : AbstractAddAnonymousTypeMemberNameCodeFixProvider< ExpressionSyntax, AnonymousObjectCreationExpressionSyntax, @@ -22,12 +24,6 @@ internal class CSharpAddAnonymousTypeMemberNameCodeFixProvider { private const string CS0746 = nameof(CS0746); // Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddAnonymousTypeMemberNameCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS0746]; diff --git a/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs index ce87505e16a52..64b8379d9d73f 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.Diagnostics; @@ -16,14 +15,10 @@ namespace Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddBraces), Shared] -internal sealed class CSharpAddBracesCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddBracesCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddBracesCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.AddBracesDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs index b8bc2a6442d2a..c835f9f901206 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs @@ -21,19 +21,15 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.AddInheritdoc; using static CSharpSyntaxTokens; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddInheritdoc), Shared] -internal sealed class AddInheritdocCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class AddInheritdocCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { /// /// CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' /// private const string CS1591 = nameof(CS1591); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public AddInheritdocCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS1591]; public override async Task RegisterCodeFixesAsync(CodeFixContext context) diff --git a/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs index da69e0b653a9e..1c98d5c0e4a6f 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs @@ -13,8 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.AddObsoleteAttribute; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddObsoleteAttribute), Shared] -internal class CSharpAddObsoleteAttributeCodeFixProvider - : AbstractAddObsoleteAttributeCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpAddObsoleteAttributeCodeFixProvider() + : AbstractAddObsoleteAttributeCodeFixProvider(CSharpSyntaxFacts.Instance, CSharpCodeFixesResources.Add_Obsolete) { public override ImmutableArray FixableDiagnosticIds { get; } = [ @@ -22,14 +24,6 @@ internal class CSharpAddObsoleteAttributeCodeFixProvider "CS0618", "CS0672", "CS1062", - "CS1064" -, // The best overloaded Add method 'MyCollection.Add(int)' for the collection initializer element is obsolete" + "CS1064", ]; - - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpAddObsoleteAttributeCodeFixProvider() - : base(CSharpSyntaxFacts.Instance, CSharpCodeFixesResources.Add_Obsolete) - { - } } diff --git a/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs index 339b59bf7270f..0325a7d6da94b 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -18,7 +16,9 @@ namespace Microsoft.CodeAnalysis.CSharp.AddParameter; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddParameter), Shared] [ExtensionOrder(Before = PredefinedCodeFixProviderNames.GenerateConstructor)] -internal class CSharpAddParameterCodeFixProvider : AbstractAddParameterCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddParameterCodeFixProvider() : AbstractAddParameterCodeFixProvider< ArgumentSyntax, AttributeArgumentSyntax, ArgumentListSyntax, @@ -34,12 +34,6 @@ internal class CSharpAddParameterCodeFixProvider : AbstractAddParameterCodeFixPr private static readonly ImmutableArray AddParameterFixableDiagnosticIds = [CS1501, CS1503, CS1660, CS1729, CS1739]; - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddParameterCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => AddParameterFixableDiagnosticIds; @@ -52,14 +46,14 @@ protected override ImmutableArray CannotConvertDiagnosticIds protected override ITypeSymbol GetArgumentType(SyntaxNode argumentNode, SemanticModel semanticModel, CancellationToken cancellationToken) => ((ArgumentSyntax)argumentNode).DetermineParameterType(semanticModel, cancellationToken); - protected override RegisterFixData TryGetLanguageSpecificFixInfo( + protected override RegisterFixData? TryGetLanguageSpecificFixInfo( SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { if (node is ConstructorInitializerSyntax constructorInitializer) { - var constructorDeclaration = constructorInitializer.Parent; + var constructorDeclaration = constructorInitializer.GetRequiredParent(); if (semanticModel.GetDeclaredSymbol(constructorDeclaration, cancellationToken) is IMethodSymbol constructorSymbol) { var type = constructorSymbol.ContainingType; diff --git a/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs index 80d6a95e75451..03f739a6ed179 100644 --- a/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs @@ -13,19 +13,15 @@ namespace Microsoft.CodeAnalysis.CSharp.AliasAmbiguousType; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AliasAmbiguousType), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.FullyQualify)] -internal class CSharpAliasAmbiguousTypeCodeFixProvider : AbstractAliasAmbiguousTypeCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAliasAmbiguousTypeCodeFixProvider() : AbstractAliasAmbiguousTypeCodeFixProvider { /// /// 'reference' is an ambiguous reference between 'identifier' and 'identifier' /// private const string CS0104 = nameof(CS0104); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAliasAmbiguousTypeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS0104]; diff --git a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs index 074030de7ec6c..0c6bc32df6a13 100644 --- a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs @@ -19,14 +19,10 @@ namespace Microsoft.CodeAnalysis.CSharp.AssignOutParameters; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AssignOutParametersAboveReturn), Shared] -internal class AssignOutParametersAboveReturnCodeFixProvider : AbstractAssignOutParametersCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class AssignOutParametersAboveReturnCodeFixProvider() : AbstractAssignOutParametersCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public AssignOutParametersAboveReturnCodeFixProvider() - { - } - protected override void TryRegisterFix(CodeFixContext context, Document document, SyntaxNode container, SyntaxNode location) { RegisterCodeFix(context, CSharpCodeFixesResources.Assign_out_parameters, nameof(CSharpCodeFixesResources.Assign_out_parameters)); diff --git a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs index 68e6c53f9fa52..17ec3bec4b51d 100644 --- a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs @@ -17,14 +17,10 @@ namespace Microsoft.CodeAnalysis.CSharp.AssignOutParameters; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AssignOutParametersAtStart), Shared] -internal class AssignOutParametersAtStartCodeFixProvider : AbstractAssignOutParametersCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class AssignOutParametersAtStartCodeFixProvider() : AbstractAssignOutParametersCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public AssignOutParametersAtStartCodeFixProvider() - { - } - protected override void TryRegisterFix(CodeFixContext context, Document document, SyntaxNode container, SyntaxNode location) { // Don't offer if we're already the starting statement of the container. This case will diff --git a/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs index dae9100c4191b..be9a3102fe507 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs @@ -21,16 +21,12 @@ namespace Microsoft.CodeAnalysis.CSharp.ConditionalExpressionInStringInterpolati using static CSharpSyntaxTokens; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddParenthesesAroundConditionalExpressionInInterpolatedString), Shared] -internal class CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider() : CodeFixProvider { private const string CS8361 = nameof(CS8361); //A conditional expression cannot be used directly in a string interpolation because the ':' ends the interpolation.Parenthesize the conditional expression. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider() - { - } - // CS8361 is a syntax error and it is unlikely that there is more than one CS8361 at a time. public override FixAllProvider? GetFixAllProvider() => null; diff --git a/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs index 6ec47426307a4..c476de4e37ebe 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs @@ -12,14 +12,10 @@ namespace Microsoft.CodeAnalysis.CSharp.ConflictMarkerResolution; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConflictMarkerResolution), Shared] -internal class CSharpResolveConflictMarkerCodeFixProvider : AbstractResolveConflictMarkerCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpResolveConflictMarkerCodeFixProvider() + : AbstractResolveConflictMarkerCodeFixProvider(CSharpSyntaxKinds.Instance, CS8300) { private const string CS8300 = nameof(CS8300); // Merge conflict marker encountered - - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpResolveConflictMarkerCodeFixProvider() - : base(CSharpSyntaxKinds.Instance, CS8300) - { - } } diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs index 2007769def97e..b39e9e57791f8 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs @@ -21,13 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertNamespace; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertNamespace), Shared] -internal class ConvertNamespaceCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConvertNamespaceCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConvertNamespaceCodeFixProvider() - { - } public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseBlockScopedNamespaceDiagnosticId, IDEDiagnosticIds.UseFileScopedNamespaceDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs index 97263cf4f55c8..43785bf880ddb 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs @@ -27,14 +27,10 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression; using Constants = ConvertSwitchStatementToExpressionConstants; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertSwitchStatementToExpression), Shared] -internal sealed partial class ConvertSwitchStatementToExpressionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class ConvertSwitchStatementToExpressionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConvertSwitchStatementToExpressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConvertSwitchStatementToExpressionDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs index c5cc94a864422..897a55d2ad9c3 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs @@ -16,19 +16,15 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.ConvertToAsync; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertToAsync), Shared] -internal class CSharpConvertToAsyncMethodCodeFixProvider : AbstractConvertToAsyncCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpConvertToAsyncMethodCodeFixProvider() : AbstractConvertToAsyncCodeFixProvider { /// /// Cannot await void. /// private const string CS4008 = nameof(CS4008); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpConvertToAsyncMethodCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS4008]; protected override async Task GetDescriptionAsync( diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs index 0db46321a101d..9bbbf1903eb6e 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.Composition; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Host.Mef; @@ -15,16 +14,12 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertToRecord; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertToRecord), Shared] -internal class CSharpConvertToRecordCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpConvertToRecordCodeFixProvider() : CodeFixProvider { private const string CS8865 = nameof(CS8865); // Only records may inherit from records. - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpConvertToRecordCodeFixProvider() - { - } - public override FixAllProvider? GetFixAllProvider() => null; diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs index 715736b25f3a1..7eebb4cffc71d 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs @@ -15,15 +15,11 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertTypeOfToNameOf; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertTypeOfToNameOf), Shared] -internal class CSharpConvertTypeOfToNameOfCodeFixProvider : AbstractConvertTypeOfToNameOfCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpConvertTypeOfToNameOfCodeFixProvider() : AbstractConvertTypeOfToNameOfCodeFixProvider< MemberAccessExpressionSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpConvertTypeOfToNameOfCodeFixProvider() - { - } - protected override string GetCodeFixTitle() => CSharpCodeFixesResources.Convert_typeof_to_nameof; diff --git a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs index 2abf253e24c64..ec24c4ed1a0ee 100644 --- a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.LanguageService; @@ -26,19 +25,14 @@ namespace Microsoft.CodeAnalysis.CSharp.DisambiguateSameVariable; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.DisambiguateSameVariable), Shared] -internal class CSharpDisambiguateSameVariableCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpDisambiguateSameVariableCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS1717 = nameof(CS1717); // Assignment made to same variable; did you mean to assign something else? private const string CS1718 = nameof(CS1718); // Comparison made to same variable; did you mean to compare something else? - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpDisambiguateSameVariableCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } - = [CS1717, CS1718]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS1717, CS1718]; public override async Task RegisterCodeFixesAsync(CodeFixContext context) { diff --git a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs index 9ddd508ced16f..718b8dd754b94 100644 --- a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs @@ -17,7 +17,9 @@ namespace Microsoft.CodeAnalysis.CSharp.DocumentationComments; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddDocCommentNodes), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal class CSharpAddDocCommentNodesCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddDocCommentNodesCodeFixProvider() : AbstractAddDocCommentNodesCodeFixProvider { /// @@ -25,12 +27,6 @@ internal class CSharpAddDocCommentNodesCodeFixProvider /// private const string CS1573 = nameof(CS1573); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddDocCommentNodesCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1573]; protected override string NodeName { get; } = "param"; diff --git a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs index f17292e1b14a3..057f99d094f6e 100644 --- a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs @@ -6,7 +6,6 @@ using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.DocumentationComments; @@ -14,7 +13,9 @@ namespace Microsoft.CodeAnalysis.CSharp.DocumentationComments; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveDocCommentNode), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal class CSharpRemoveDocCommentNodeCodeFixProvider : +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveDocCommentNodeCodeFixProvider() : AbstractRemoveDocCommentNodeCodeFixProvider { /// @@ -32,12 +33,6 @@ internal class CSharpRemoveDocCommentNodeCodeFixProvider : /// private const string CS1710 = nameof(CS1710); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveDocCommentNodeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1571, CS1572, CS1710]; protected override string DocCommentSignifierToken { get; } = "///"; diff --git a/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs index d549187a6f015..f9f3deda2e29a 100644 --- a/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs @@ -13,15 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.FileHeaders; /// /// Implements a code fix for file header diagnostics. /// -[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FileHeader)] -[Shared] -internal class CSharpFileHeaderCodeFixProvider : AbstractFileHeaderCodeFixProvider +[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FileHeader), Shared] +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFileHeaderCodeFixProvider() : AbstractFileHeaderCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFileHeaderCodeFixProvider() - { - } - protected override AbstractFileHeaderHelper FileHeaderHelper => CSharpFileHeaderHelper.Instance; } diff --git a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs index e6666760eb187..f49ac21d07316 100644 --- a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; @@ -19,19 +18,14 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.FixIncorrectConstraint; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixIncorrectConstraint), Shared] -internal class CSharpFixIncorrectConstraintCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFixIncorrectConstraintCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS9010 = nameof(CS9010); // Keyword 'enum' cannot be used as a constraint.Did you mean 'struct, System.Enum'? Net6 C:\github\repo_find_refs\Net6\Class1.cs 1 Active private const string CS9011 = nameof(CS9011); // 'delegate' cannot be used as a constraint.Did you mean 'System.Delegate'? Net6 C:\github\repo_find_refs\Net6\Class1.cs 1 Active - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFixIncorrectConstraintCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds - => [CS9010, CS9011]; + public override ImmutableArray FixableDiagnosticIds => [CS9010, CS9011]; private static bool TryGetConstraint( Diagnostic diagnostic, diff --git a/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs index f0daf69247ea2..6353bff86f3f5 100644 --- a/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,20 +23,16 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.FixReturnType; /// Helps fix void-returning methods or local functions to return a correct type. /// [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixReturnType), Shared] -internal class CSharpFixReturnTypeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFixReturnTypeCodeFixProvider() + : SyntaxEditorBasedCodeFixProvider(supportsFixAll: false) { // error CS0127: Since 'M()' returns void, a return keyword must not be followed by an object expression // error CS1997: Since 'M()' is an async method that returns 'Task', a return keyword must not be followed by an object expression // error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement public override ImmutableArray FixableDiagnosticIds => ["CS0127", "CS1997", "CS0201"]; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFixReturnTypeCodeFixProvider() - : base(supportsFixAll: false) - { - } - public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; diff --git a/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs index 1a10b3216eec0..c066622935221 100644 --- a/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs @@ -3,9 +3,7 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Composition; -using System.Text; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.ForEachCast; @@ -15,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.ForEachCast; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ForEachCast), Shared] -internal class CSharpForEachCastCodeFixProvider : AbstractForEachCastCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpForEachCastCodeFixProvider() : AbstractForEachCastCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpForEachCastCodeFixProvider() - { - } - protected override ITypeSymbol GetForEachElementType( SemanticModel semanticModel, CommonForEachStatementSyntax forEachStatement) { diff --git a/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs index 78aede7a1ed01..911afb37bef69 100644 --- a/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs @@ -12,13 +12,9 @@ namespace Microsoft.CodeAnalysis.CodeStyle; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixFormatting), Shared] -internal class CSharpFormattingCodeFixProvider : AbstractFormattingCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFormattingCodeFixProvider() : AbstractFormattingCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFormattingCodeFixProvider() - { - } - protected override ISyntaxFormatting SyntaxFormatting => CSharpSyntaxFormatting.Instance; } diff --git a/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs b/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs index b821a7fcfd42c..f83c0483fbbae 100644 --- a/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs +++ b/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; namespace Microsoft.CodeAnalysis.CSharp.GenerateConstructor; diff --git a/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs index a1a9c282c4214..cfc813e2319e6 100644 --- a/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Shared.Extensions; @@ -15,16 +14,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.HideBase; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddNew), Shared] -internal partial class HideBaseCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class HideBaseCodeFixProvider() : CodeFixProvider { internal const string CS0108 = nameof(CS0108); // 'SomeClass.SomeMember' hides inherited member 'SomeClass.SomeMember'. Use the new keyword if hiding was intended. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public HideBaseCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS0108]; public override FixAllProvider GetFixAllProvider() diff --git a/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs index 49732b79122a2..526ca834a7acd 100644 --- a/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs @@ -18,7 +18,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Formatting; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Text; @@ -28,14 +27,10 @@ namespace Microsoft.CodeAnalysis.CSharp.InlineDeclaration; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.InlineDeclaration), Shared] -internal partial class CSharpInlineDeclarationCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpInlineDeclarationCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpInlineDeclarationCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.InlineDeclarationDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs index fe53a9bf2da42..00ce0cc496c32 100644 --- a/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -25,14 +24,10 @@ namespace Microsoft.CodeAnalysis.CSharp.InvokeDelegateWithConditionalAccess; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.InvokeDelegateWithConditionalAccess), Shared] -internal partial class InvokeDelegateWithConditionalAccessCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class InvokeDelegateWithConditionalAccessCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public InvokeDelegateWithConditionalAccessCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.InvokeDelegateWithConditionalAccessId]; // Filter out the diagnostics we created for the faded out code. We don't want diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs index dba1cfc6890d8..9a25f4ae39100 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs @@ -22,7 +22,9 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.Iterator; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ChangeToYield), Shared] -internal class CSharpAddYieldCodeFixProvider : AbstractIteratorCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddYieldCodeFixProvider() : AbstractIteratorCodeFixProvider { /// /// CS0029: Cannot implicitly convert from type 'x' to 'y' @@ -34,12 +36,6 @@ internal class CSharpAddYieldCodeFixProvider : AbstractIteratorCodeFixProvider /// private const string CS0266 = nameof(CS0266); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddYieldCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get { return [CS0029, CS0266]; } diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs index 3043fe7f66fa2..7f62a82ff0a1a 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs @@ -21,23 +21,16 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.Iterator; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ChangeReturnType), Shared] -internal class CSharpChangeToIEnumerableCodeFixProvider : AbstractIteratorCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpChangeToIEnumerableCodeFixProvider() : AbstractIteratorCodeFixProvider { /// /// CS1624: The body of 'x' cannot be an iterator block because 'y' is not an iterator interface type /// private const string CS1624 = nameof(CS1624); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpChangeToIEnumerableCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds - { - get { return [CS1624]; } - } + public override ImmutableArray FixableDiagnosticIds => [CS1624]; protected override async Task GetCodeFixAsync(SyntaxNode root, SyntaxNode node, Document document, Diagnostic diagnostics, CancellationToken cancellationToken) { diff --git a/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs index 233c98d80d709..2a99380b0e0b8 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs @@ -13,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeFieldReadonly; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeFieldReadonly), Shared] -internal class CSharpMakeFieldReadonlyCodeFixProvider : AbstractMakeFieldReadonlyCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeFieldReadonlyCodeFixProvider() : AbstractMakeFieldReadonlyCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeFieldReadonlyCodeFixProvider() - { - } - protected override SyntaxNode? GetInitializerNode(VariableDeclaratorSyntax declaration) => declaration.Initializer?.Value; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs index 949282ecddc0f..980bfb21c6060 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs @@ -2,13 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; @@ -17,14 +15,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeLocalFunctionStatic; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeLocalFunctionStatic), Shared] -internal class MakeLocalFunctionStaticCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class MakeLocalFunctionStaticCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public MakeLocalFunctionStaticCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.MakeLocalFunctionStaticDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs index 7ba958a71a6da..46b3d5b773af4 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs @@ -20,16 +20,12 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeLocalFunctionStatic; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.PassInCapturedVariables), Shared] -internal sealed class PassInCapturedVariablesAsArgumentsCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class PassInCapturedVariablesAsArgumentsCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS8421 = nameof(CS8421); // A static local function can't contain a reference to . - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public PassInCapturedVariablesAsArgumentsCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS8421]; public override Task RegisterCodeFixesAsync(CodeFixContext context) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs index 9497c77015b2e..457ed7d684699 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -22,18 +21,13 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.MakeMemberRequired; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeMemberRequired), Shared] [ExtensionOrder(Before = PredefinedCodeFixProviderNames.DeclareAsNullable)] -internal sealed class CSharpMakeMemberRequiredCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeMemberRequiredCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS8618 = nameof(CS8618); // Non-nullable variable must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring it as nullable. - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeMemberRequiredCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS8618]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS8618]; public override async Task RegisterCodeFixesAsync(CodeFixContext context) { diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs index 8c747b4a83ddd..ee9773795d40a 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Host.Mef; @@ -15,16 +14,11 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeMemberStatic; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeMemberStatic), Shared] -internal sealed class CSharpMakeMemberStaticCodeFixProvider : AbstractMakeMemberStaticCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeMemberStaticCodeFixProvider() : AbstractMakeMemberStaticCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeMemberStaticCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - ["CS0708"]; + public override ImmutableArray FixableDiagnosticIds { get; } = ["CS0708"]; protected override bool TryGetMemberDeclaration(SyntaxNode node, [NotNullWhen(true)] out SyntaxNode? memberDeclaration) { diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs index c24bdc78fec87..186ac162813d4 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs @@ -21,7 +21,9 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeMethodAsynchronous; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddAsync), Shared] -internal class CSharpMakeMethodAsynchronousCodeFixProvider : AbstractMakeMethodAsynchronousCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeMethodAsynchronousCodeFixProvider() : AbstractMakeMethodAsynchronousCodeFixProvider { private const string CS4032 = nameof(CS4032); // The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. private const string CS4033 = nameof(CS4033); // The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. @@ -30,12 +32,6 @@ internal class CSharpMakeMethodAsynchronousCodeFixProvider : AbstractMakeMethodA private static readonly SyntaxToken s_asyncKeywordWithSpace = AsyncKeyword.WithoutTrivia().WithTrailingTrivia(Space); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeMethodAsynchronousCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS4032, CS4033, CS4034, CS0246]; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs index 35a8ac00ac066..de80287f51aa6 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs @@ -18,16 +18,12 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeMethodSynchronous; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeMethodSynchronous), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddImport)] -internal class CSharpMakeMethodSynchronousCodeFixProvider : AbstractMakeMethodSynchronousCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeMethodSynchronousCodeFixProvider() : AbstractMakeMethodSynchronousCodeFixProvider { private const string CS1998 = nameof(CS1998); // This async method lacks 'await' operators and will run synchronously. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeMethodSynchronousCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1998]; protected override bool IsAsyncSupportingFunctionSyntax(SyntaxNode node) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs index 61ca1362d13fe..6ae9aebe5a155 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -13,22 +12,17 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp.MakeRefStruct; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeRefStruct), Shared] -internal class MakeRefStructCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class MakeRefStructCodeFixProvider() : CodeFixProvider { // Error CS8345: Field or auto-implemented property cannot be of certain type unless it is an instance member of a ref struct. private const string CS8345 = nameof(CS8345); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public MakeRefStructCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS8345]; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs index 848b7bc5a181e..1eddec0d520e9 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -20,17 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.MakeStatementAsynchronous; using static CSharpSyntaxTokens; -using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeStatementAsynchronous), Shared] -internal class CSharpMakeStatementAsynchronousCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeStatementAsynchronousCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeStatementAsynchronousCodeFixProvider() - { - } - // error CS8414: foreach statement cannot operate on variables of type 'IAsyncEnumerable' because 'IAsyncEnumerable' does not contain a public instance definition for 'GetEnumerator'. Did you mean 'await foreach'? // error CS8418: 'IAsyncDisposable': type used in a using statement must be implicitly convertible to 'System.IDisposable'. Did you mean 'await using' rather than 'using'? public sealed override ImmutableArray FixableDiagnosticIds => ["CS8414", "CS8418"]; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs index db0495d70e4d6..b9b1909edbdc0 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeStructFieldsWritable; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeStructFieldsWritable), Shared] -internal class CSharpMakeStructFieldsWritableCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeStructFieldsWritableCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeStructFieldsWritableCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.MakeStructFieldsWritable]; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs index 3f21860c25103..697d799433afc 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; @@ -18,14 +17,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeStructReadOnly; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeStructReadOnly), Shared] -internal sealed class CSharpMakeStructReadOnlyCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeStructReadOnlyCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeStructReadOnlyCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.MakeStructReadOnlyDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs index 3cf6b45ddf1e2..0ec6147a8c1e5 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -13,14 +12,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeTypeAbstract; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeTypeAbstract), Shared] -internal sealed class CSharpMakeTypeAbstractCodeFixProvider : AbstractMakeTypeAbstractCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeTypeAbstractCodeFixProvider() : AbstractMakeTypeAbstractCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeTypeAbstractCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = ["CS0513"]; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs index be903b4c152b7..a8ca5d41a8a4a 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs @@ -12,16 +12,11 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeTypePartial; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeTypePartial), Shared] -internal sealed class CSharpMakeTypePartialCodeFixProvider : AbstractMakeTypePartialCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeTypePartialCodeFixProvider() : AbstractMakeTypePartialCodeFixProvider { private const string CS0260 = nameof(CS0260); // Missing partial modifier on declaration of type 'C'; another partial declaration of this type exists - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeTypePartialCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS0260]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS0260]; } diff --git a/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs index e5d5a6a13936a..81777d0d08087 100644 --- a/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs @@ -12,11 +12,6 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.MatchFolderAndNamespace; [Export(typeof(CSharpChangeNamespaceToMatchFolderCodeFixProvider))] [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ChangeNamespaceToMatchFolder), Shared] -internal class CSharpChangeNamespaceToMatchFolderCodeFixProvider : AbstractChangeNamespaceToMatchFolderCodeFixProvider -{ - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpChangeNamespaceToMatchFolderCodeFixProvider() - { - } -} +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpChangeNamespaceToMatchFolderCodeFixProvider() : AbstractChangeNamespaceToMatchFolderCodeFixProvider; diff --git a/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs index c0463c723161f..6657044d72b52 100644 --- a/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs @@ -28,9 +28,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MisplacedUsingDirectives; /// /// Implements a code fix for all misplaced using statements. /// -[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MoveMisplacedUsingDirectives)] -[Shared] -internal sealed partial class MisplacedUsingDirectivesCodeFixProvider : CodeFixProvider +[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MoveMisplacedUsingDirectives), Shared] +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class MisplacedUsingDirectivesCodeFixProvider() : CodeFixProvider { private static readonly SyntaxAnnotation s_usingPlacementCodeFixAnnotation = new(nameof(s_usingPlacementCodeFixAnnotation)); @@ -40,12 +41,6 @@ internal sealed partial class MisplacedUsingDirectivesCodeFixProvider : CodeFixP private static readonly SyntaxAnnotation s_warningAnnotation = WarningAnnotation.Create( CSharpAnalyzersResources.Warning_colon_Moving_using_directives_may_change_code_meaning); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public MisplacedUsingDirectivesCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.MoveMisplacedUsingDirectivesDiagnosticId]; public override FixAllProvider GetFixAllProvider() diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs index 0efae742c6ca0..91f10bc2d37bd 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Linq; @@ -22,14 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ArrowExpressionClausePlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ArrowExpressionClausePlacement), Shared] -internal sealed class ArrowExpressionClausePlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ArrowExpressionClausePlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ArrowExpressionClausePlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ArrowExpressionClausePlacementDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs index 8889157d918c2..50cce8f2d95b2 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Linq; @@ -22,14 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ConditionalExpressionPlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConditionalExpressionPlacement), Shared] -internal sealed class ConditionalExpressionPlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConditionalExpressionPlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConditionalExpressionPlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConditionalExpressionPlacementDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs index 8fbb8bcdb29fc..6f37b38c9fce5 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs @@ -21,14 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ConsecutiveBracePlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConsecutiveBracePlacement), Shared] -internal sealed class ConsecutiveBracePlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConsecutiveBracePlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConsecutiveBracePlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConsecutiveBracePlacementDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs index 7e012daf50346..fdb85c447f743 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs @@ -20,14 +20,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ConstructorInitializerPlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConstructorInitializerPlacement), Shared] -internal sealed class ConstructorInitializerPlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConstructorInitializerPlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConstructorInitializerPlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConstructorInitializerPlacementDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs index 45709ce592734..bf6a8be42bb2e 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs @@ -22,14 +22,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.EmbeddedStatementPlacement; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.EmbeddedStatementPlacement), Shared] -internal sealed class EmbeddedStatementPlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class EmbeddedStatementPlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public EmbeddedStatementPlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.EmbeddedStatementPlacementDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs index 85de50c8f00fc..850b1c3761a3e 100644 --- a/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs @@ -5,11 +5,8 @@ using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CodeStyle; -using Microsoft.CodeAnalysis.CSharp.CodeStyle; using Microsoft.CodeAnalysis.CSharp.LanguageService; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.OrderModifiers; @@ -17,17 +14,13 @@ namespace Microsoft.CodeAnalysis.CSharp.OrderModifiers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.OrderModifiers), Shared] -internal sealed class CSharpOrderModifiersCodeFixProvider : AbstractOrderModifiersCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpOrderModifiersCodeFixProvider() + : AbstractOrderModifiersCodeFixProvider(CSharpSyntaxFacts.Instance, CSharpOrderModifiersHelper.Instance) { private const string CS0267 = nameof(CS0267); // The 'partial' modifier can only appear immediately before 'class', 'record', 'struct', 'interface', or 'void' - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpOrderModifiersCodeFixProvider() - : base(CSharpSyntaxFacts.Instance, CSharpOrderModifiersHelper.Instance) - { - } - protected override CodeStyleOption2 GetCodeStyleOption(AnalyzerOptionsProvider options) => ((CSharpAnalyzerOptionsProvider)options).PreferredModifierOrder; diff --git a/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs index b1691743e92e2..4ef787adcc086 100644 --- a/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs @@ -18,19 +18,15 @@ namespace Microsoft.CodeAnalysis.CSharp.PopulateSwitch; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.PopulateSwitchExpression), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal class CSharpPopulateSwitchExpressionCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpPopulateSwitchExpressionCodeFixProvider() : AbstractPopulateSwitchExpressionCodeFixProvider< ExpressionSyntax, SwitchExpressionSyntax, SwitchExpressionArmSyntax, MemberAccessExpressionSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpPopulateSwitchExpressionCodeFixProvider() - { - } - protected override SwitchExpressionArmSyntax CreateDefaultSwitchArm(SyntaxGenerator generator, Compilation compilation) => SwitchExpressionArm(DiscardPattern(), Exception(generator, compilation)); diff --git a/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs index dd3003ee9a437..f6f075d708741 100644 --- a/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs @@ -14,14 +14,10 @@ namespace Microsoft.CodeAnalysis.CSharp.QualifyMemberAccess; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.QualifyMemberAccess), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.RemoveUnnecessaryCast)] -internal class CSharpQualifyMemberAccessCodeFixProvider : AbstractQualifyMemberAccessCodeFixprovider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpQualifyMemberAccessCodeFixProvider() : AbstractQualifyMemberAccessCodeFixprovider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpQualifyMemberAccessCodeFixProvider() - { - } - protected override SimpleNameSyntax? GetNode(Diagnostic diagnostic, CancellationToken cancellationToken) { var node = diagnostic.Location.FindNode(getInnermostNodeForTie: true, cancellationToken); diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs index 0a453ff0458ed..15e80e1eee832 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs @@ -19,16 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveAsyncModifier), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.MakeMethodSynchronous)] -internal partial class CSharpRemoveAsyncModifierCodeFixProvider : AbstractRemoveAsyncModifierCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpRemoveAsyncModifierCodeFixProvider() : AbstractRemoveAsyncModifierCodeFixProvider { private const string CS1998 = nameof(CS1998); // This async method lacks 'await' operators and will run synchronously. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveAsyncModifierCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1998]; protected override bool IsAsyncSupportingFunctionSyntax(SyntaxNode node) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs index daab59954822b..685d47fe4f6cb 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs @@ -21,17 +21,13 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveConfusingSuppression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveConfusingSuppression), Shared] -internal sealed partial class CSharpRemoveConfusingSuppressionCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpRemoveConfusingSuppressionCodeFixProvider() : CodeFixProvider { public const string RemoveOperator = nameof(RemoveOperator); public const string NegateExpression = nameof(NegateExpression); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveConfusingSuppressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.RemoveConfusingSuppressionForIsExpressionDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs index 8d1d8c756f031..4bab16a5e36b9 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -20,16 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveInKeyword; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveIn), Shared] -internal class RemoveInKeywordCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class RemoveInKeywordCodeFixProvider() : CodeFixProvider { private const string CS1615 = nameof(CS1615); // Argument 1 may not be passed with the 'in' keyword - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public RemoveInKeywordCodeFixProvider() - { - } - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs index 6fb3710f7ea06..6a0863a16dbc4 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -18,16 +17,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.RemoveNewModifier; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveNew), Shared] -internal class RemoveNewModifierCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class RemoveNewModifierCodeFixProvider() : CodeFixProvider { private const string CS0109 = nameof(CS0109); // The member 'SomeClass.SomeMember' does not hide an accessible member. The new keyword is not required. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public RemoveNewModifierCodeFixProvider() - { - } - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs index 2b2a2f999063c..726efeaf9df28 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs @@ -2,14 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Simplification.Simplifiers; @@ -25,14 +22,10 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryCast; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryCast), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal partial class CSharpRemoveUnnecessaryCastCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpRemoveUnnecessaryCastCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnnecessaryCastCodeFixProvider() - { - } - public sealed override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.RemoveUnnecessaryCastDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs index 14ae92e57b383..bb128253e29e2 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs @@ -5,11 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -17,19 +14,14 @@ using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryDiscardDesignation; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryDiscardDesignation), Shared] -internal partial class CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.RemoveUnnecessaryDiscardDesignationDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs index e1e0760dbc711..4afff26be42b2 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; @@ -15,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryImports; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryImports), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddMissingReference)] -internal class CSharpRemoveUnnecessaryImportsCodeFixProvider : AbstractRemoveUnnecessaryImportsCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveUnnecessaryImportsCodeFixProvider() : AbstractRemoveUnnecessaryImportsCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnnecessaryImportsCodeFixProvider() - { - } - protected override string GetTitle() => CSharpCodeFixesResources.Remove_unnecessary_usings; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs index 3eadd802378e5..d219c3bd03a0b 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs @@ -5,10 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -16,21 +14,16 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryLambdaExpression; using static CSharpRemoveUnnecessaryLambdaExpressionDiagnosticAnalyzer; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryLambdaExpression), Shared] -internal partial class CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.RemoveUnnecessaryLambdaExpressionDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs index 204c4c17a38f3..bd7830b81c497 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Threading; @@ -14,15 +12,11 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryParentheses; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryParentheses), Shared] -internal class CSharpRemoveUnnecessaryParenthesesCodeFixProvider : - AbstractRemoveUnnecessaryParenthesesCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveUnnecessaryParenthesesCodeFixProvider() + : AbstractRemoveUnnecessaryParenthesesCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnnecessaryParenthesesCodeFixProvider() - { - } - protected override bool CanRemoveParentheses(SyntaxNode current, SemanticModel semanticModel, CancellationToken cancellationToken) => current switch { diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs index 1cf3df3dd320a..6fa5f28aa5519 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs @@ -19,16 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnusedLocalFunction; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnusedLocalFunction), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddImport)] -internal class CSharpRemoveUnusedLocalFunctionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveUnusedLocalFunctionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS8321 = nameof(CS8321); // The local function 'X' is declared but never used - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnusedLocalFunctionCodeFixProvider() - { - } - public sealed override ImmutableArray FixableDiagnosticIds => [CS8321]; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs index a9d4d39ed68d7..5a22dd0173095 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs @@ -2,27 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - +using System; using System.Collections.Generic; using System.Composition; -using Microsoft.CodeAnalysis.RemoveUnusedMembers; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.RemoveUnusedMembers; namespace Microsoft.CodeAnalysis.CSharp.RemoveUnusedMembers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnusedMembers), Shared] -internal class CSharpRemoveUnusedMembersCodeFixProvider : AbstractRemoveUnusedMembersCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpRemoveUnusedMembersCodeFixProvider() : AbstractRemoveUnusedMembersCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveUnusedMembersCodeFixProvider() - { - } - /// /// This method adjusts the to remove based on whether or not all variable declarators /// within a field declaration should be removed, diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs index d80b9b34b4eaa..434d14f295da9 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Composition; using System.Diagnostics; @@ -25,17 +23,13 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnusedParametersAndValues; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnusedValues), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddImport)] -internal class CSharpRemoveUnusedValuesCodeFixProvider : - AbstractRemoveUnusedValuesCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnusedValuesCodeFixProvider() - { - } - protected override ISyntaxFormatting GetSyntaxFormatting() => CSharpSyntaxFormatting.Instance; @@ -45,10 +39,10 @@ protected override BlockSyntax WrapWithBlockIfNecessary(IEnumerable node.Identifier; - protected override LocalDeclarationStatementSyntax GetCandidateLocalDeclarationForRemoval(VariableDeclaratorSyntax declarator) + protected override LocalDeclarationStatementSyntax? GetCandidateLocalDeclarationForRemoval(VariableDeclaratorSyntax declarator) => declarator.Parent?.Parent as LocalDeclarationStatementSyntax; - protected override SyntaxNode TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName) + protected override SyntaxNode? TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName) { switch (node.Kind()) { @@ -95,7 +89,7 @@ protected override SyntaxNode TryUpdateNameForFlaggedNode(SyntaxNode node, Synta } } - protected override SyntaxNode TryUpdateParentOfUpdatedNode(SyntaxNode parent, SyntaxNode newNameNode, SyntaxEditor editor, ISyntaxFacts syntaxFacts, SemanticModel semanticModel) + protected override SyntaxNode? TryUpdateParentOfUpdatedNode(SyntaxNode parent, SyntaxNode newNameNode, SyntaxEditor editor, ISyntaxFacts syntaxFacts, SemanticModel semanticModel) { if (newNameNode.IsKind(SyntaxKind.DiscardDesignation)) { @@ -183,7 +177,7 @@ protected override void InsertAtStartOfSwitchCaseBlockForDeclarationInCaseLabelO { // Switch section without any statements is an error case. // Insert before containing switch statement. - editor.InsertBefore(switchCaseBlock.Parent, declarationStatement); + editor.InsertBefore(switchCaseBlock.GetRequiredParent(), declarationStatement); } } diff --git a/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs index 5d042bc0fe210..c5ba3aa3475e7 100644 --- a/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs @@ -20,19 +20,14 @@ namespace Microsoft.CodeAnalysis.CSharp.ReplaceDefaultLiteral; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ReplaceDefaultLiteral), Shared] -internal sealed class CSharpReplaceDefaultLiteralCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpReplaceDefaultLiteralCodeFixProvider() : CodeFixProvider { private const string CS8313 = nameof(CS8313); // A default literal 'default' is not valid as a case constant. Use another literal (e.g. '0' or 'null') as appropriate. If you intended to write the default label, use 'default:' without 'case'. private const string CS8505 = nameof(CS8505); // A default literal 'default' is not valid as a pattern. Use another literal (e.g. '0' or 'null') as appropriate. To match everything, use a discard pattern 'var _'. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpReplaceDefaultLiteralCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS8313, CS8505]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS8313, CS8505]; public override FixAllProvider? GetFixAllProvider() { diff --git a/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs index e701351b66dc5..7f8021ce4da77 100644 --- a/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Text; @@ -15,16 +13,12 @@ namespace Microsoft.CodeAnalysis.CSharp.SimplifyInterpolation; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.SimplifyInterpolation), Shared] -internal class CSharpSimplifyInterpolationCodeFixProvider : AbstractSimplifyInterpolationCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpSimplifyInterpolationCodeFixProvider() : AbstractSimplifyInterpolationCodeFixProvider< InterpolationSyntax, ExpressionSyntax, InterpolationAlignmentClauseSyntax, InterpolationFormatClauseSyntax, InterpolatedStringExpressionSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpSimplifyInterpolationCodeFixProvider() - { - } - protected override AbstractSimplifyInterpolationHelpers GetHelpers() => CSharpSimplifyInterpolationHelpers.Instance; protected override InterpolationSyntax WithExpression(InterpolationSyntax interpolation, ExpressionSyntax expression) @@ -33,7 +27,7 @@ protected override InterpolationSyntax WithExpression(InterpolationSyntax interp protected override InterpolationSyntax WithAlignmentClause(InterpolationSyntax interpolation, InterpolationAlignmentClauseSyntax alignmentClause) => interpolation.WithAlignmentClause(alignmentClause); - protected override InterpolationSyntax WithFormatClause(InterpolationSyntax interpolation, InterpolationFormatClauseSyntax formatClause) + protected override InterpolationSyntax WithFormatClause(InterpolationSyntax interpolation, InterpolationFormatClauseSyntax? formatClause) => interpolation.WithFormatClause(formatClause); protected override string Escape(InterpolatedStringExpressionSyntax interpolatedString, string formatString) diff --git a/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs index 6d70c1b191fa6..ea9061d1df6eb 100644 --- a/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs @@ -13,13 +13,9 @@ namespace Microsoft.CodeAnalysis.CSharp.SimplifyLinqExpression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.SimplifyLinqExpression), Shared] -internal sealed class CSharpSimplifyLinqExpressionCodeFixProvider : AbstractSimplifyLinqExpressionCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpSimplifyLinqExpressionCodeFixProvider() : AbstractSimplifyLinqExpressionCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpSimplifyLinqExpressionCodeFixProvider() - { - } - protected override ISyntaxFacts SyntaxFacts => CSharpSyntaxFacts.Instance; } diff --git a/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs index 894b5a51e583a..521cbb3b76809 100644 --- a/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -23,14 +22,10 @@ namespace Microsoft.CodeAnalysis.CSharp.SimplifyPropertyPattern; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.SimplifyPropertyPattern), Shared] -internal class CSharpSimplifyPropertyPatternCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpSimplifyPropertyPatternCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpSimplifyPropertyPatternCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.SimplifyPropertyPatternDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs index 2bd72a73938e3..b9294d8b975de 100644 --- a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; @@ -19,18 +18,13 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.TransposeRecordKeyword; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.TransposeRecordKeyword), Shared] -internal class CSharpTransposeRecordKeywordCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpTransposeRecordKeywordCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS9012 = nameof(CS9012); // Unexpected keyword 'record'. Did you mean 'record struct' or 'record class'? - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpTransposeRecordKeywordCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds - => [CS9012]; + public override ImmutableArray FixableDiagnosticIds => [CS9012]; private static bool TryGetRecordDeclaration( Diagnostic diagnostic, CancellationToken cancellationToken, [NotNullWhen(true)] out RecordDeclarationSyntax? recordDeclaration) diff --git a/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs index fa04bf91c8e1f..24f9abc726fcd 100644 --- a/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs @@ -12,18 +12,13 @@ namespace Microsoft.CodeAnalysis.CSharp.UnsealClass; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UnsealClass), Shared] -internal sealed class CSharpUnsealClassCodeFixProvider : AbstractUnsealClassCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUnsealClassCodeFixProvider() : AbstractUnsealClassCodeFixProvider { private const string CS0509 = nameof(CS0509); // 'D': cannot derive from sealed type 'C' - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUnsealClassCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS0509]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS0509]; protected override string TitleFormat => CSharpCodeFixesResources.Unseal_class_0; } diff --git a/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs index 5cc5d41e433ad..4c7fe2d7c1435 100644 --- a/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs @@ -13,16 +13,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UpdateProjectToAllowUnsafe; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UpdateProjectToAllowUnsafe), Shared] -internal class CSharpUpdateProjectToAllowUnsafeCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUpdateProjectToAllowUnsafeCodeFixProvider() : CodeFixProvider { private const string CS0227 = nameof(CS0227); // error CS0227: Unsafe code may only appear if compiling with /unsafe - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUpdateProjectToAllowUnsafeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS0227]; diff --git a/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs index fcdabb3ea4274..f76ddccb4aa3f 100644 --- a/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs @@ -13,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UpgradeProject; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UpgradeProject), Shared] -internal class CSharpUpgradeProjectCodeFixProvider : AbstractUpgradeProjectCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUpgradeProjectCodeFixProvider() : AbstractUpgradeProjectCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUpgradeProjectCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [ "CS8022", diff --git a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs index 1539083103c96..a2d4a0770d575 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs @@ -14,16 +14,11 @@ namespace Microsoft.CodeAnalysis.CSharp.UseCompoundAssignment; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseCompoundAssignment), Shared] -internal class CSharpUseCompoundAssignmentCodeFixProvider - : AbstractUseCompoundAssignmentCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseCompoundAssignmentCodeFixProvider() + : AbstractUseCompoundAssignmentCodeFixProvider(Utilities.Kinds) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseCompoundAssignmentCodeFixProvider() - : base(Utilities.Kinds) - { - } - protected override SyntaxToken Token(SyntaxKind kind) => SyntaxFactory.Token(kind); diff --git a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs index de964491ae666..a9ec9d8f034e8 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -25,14 +24,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseCompoundAssignment; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseCompoundCoalesceAssignment), Shared] -internal class CSharpUseCompoundCoalesceAssignmentCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseCompoundCoalesceAssignmentCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseCompoundCoalesceAssignmentCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseCoalesceCompoundAssignmentDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs index f92caeab2fe45..ba4a932007522 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs @@ -17,15 +17,11 @@ namespace Microsoft.CodeAnalysis.CSharp.UseConditionalExpression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseConditionalExpressionForReturn), Shared] -internal partial class CSharpUseConditionalExpressionForReturnCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpUseConditionalExpressionForReturnCodeFixProvider() : AbstractUseConditionalExpressionForReturnCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseConditionalExpressionForReturnCodeFixProvider() - { - } - protected override ISyntaxFacts SyntaxFacts => CSharpSyntaxFacts.Instance; diff --git a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs index 7b9bdb36fc3ee..ddc9d75b782ab 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs @@ -2,11 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Formatting.Rules; +using Microsoft.CodeAnalysis.Shared.Extensions; using static Microsoft.CodeAnalysis.UseConditionalExpression.UseConditionalExpressionCodeFixHelpers; namespace Microsoft.CodeAnalysis.CSharp.UseConditionalExpression; @@ -32,9 +31,9 @@ private MultiLineConditionalExpressionFormattingRule() } private static bool IsQuestionOrColonOfNewConditional(SyntaxToken token) - => token.Kind() is SyntaxKind.QuestionToken or SyntaxKind.ColonToken && token.Parent.HasAnnotation(SpecializedFormattingAnnotation); + => token.Kind() is SyntaxKind.QuestionToken or SyntaxKind.ColonToken && token.GetRequiredParent().HasAnnotation(SpecializedFormattingAnnotation); - public override AdjustNewLinesOperation GetAdjustNewLinesOperation( + public override AdjustNewLinesOperation? GetAdjustNewLinesOperation( in SyntaxToken previousToken, in SyntaxToken currentToken, in NextGetAdjustNewLinesOperation nextOperation) { if (IsQuestionOrColonOfNewConditional(currentToken)) diff --git a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs index 202e5e056442c..2ffc570085015 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +23,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseDeconstruction; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseDeconstruction), Shared] -internal sealed class CSharpUseDeconstructionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseDeconstructionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseDeconstructionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseDeconstructionDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs index f181a58a5be65..880a706cd682c 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseDefaultLiteral; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseDefaultLiteral), Shared] -internal partial class CSharpUseDefaultLiteralCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpUseDefaultLiteralCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseDefaultLiteralCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseDefaultLiteralDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs index 18f715432edf0..be2159b0fecd3 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -18,16 +17,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UseExplicitTypeForConst; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseExplicitTypeForConst), Shared] -internal sealed class UseExplicitTypeForConstCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseExplicitTypeForConstCodeFixProvider() : CodeFixProvider { private const string CS0822 = nameof(CS0822); // Implicitly-typed variables cannot be constant - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseExplicitTypeForConstCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS0822]; public override FixAllProvider? GetFixAllProvider() diff --git a/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs index 75c711fece736..e786ec9531600 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -56,7 +54,7 @@ protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) { - var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); + var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var accessorLists = new HashSet(); foreach (var diagnostic in diagnostics) diff --git a/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs index 3b51259a77378..7cc54114e6761 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs @@ -5,31 +5,23 @@ using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.CSharp.CodeFixes.UseExpressionBodyForLambda; -using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; -using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Shared.Extensions; namespace Microsoft.CodeAnalysis.CSharp.UseExpressionBodyForLambda; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseExpressionBodyForLambda), Shared] -internal sealed class UseExpressionBodyForLambdaCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseExpressionBodyForLambdaCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseExpressionBodyForLambdaCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseExpressionBodyForLambdaExpressionsDiagnosticId]; public override Task RegisterCodeFixesAsync(CodeFixContext context) diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs index 453c9ed5f7092..6bc18e8e3d139 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Simplification; @@ -22,18 +21,14 @@ namespace Microsoft.CodeAnalysis.CSharp.UseImplicitObjectCreation; -using static SyntaxFactory; using static CSharpUseImplicitObjectCreationDiagnosticAnalyzer; +using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseImplicitObjectCreation), Shared] -internal class CSharpUseImplicitObjectCreationCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseImplicitObjectCreationCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseImplicitObjectCreationCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseImplicitObjectCreationDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs index 7ae79431b5afb..6bbaee842ad75 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics; @@ -10,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -26,14 +24,10 @@ namespace Microsoft.CodeAnalysis.CSharp.TypeStyle; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseExplicitType), Shared] -internal class UseExplicitTypeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseExplicitTypeCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseExplicitTypeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseExplicitTypeDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs index 7d443979d010c..9e7e7aefb59f8 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs @@ -2,34 +2,24 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.TypeStyle; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseImplicitType), Shared] -internal class UseImplicitTypeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseImplicitTypeCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseImplicitTypeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseImplicitTypeDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs index 16429204d2f7f..01b8a9424b779 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs @@ -2,15 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -23,14 +19,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIndexOrRangeOperator; using static CodeFixHelpers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIndexOperator), Shared] -internal class CSharpUseIndexOperatorCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseIndexOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseIndexOperatorCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseIndexOperatorDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs index ae163dd59f6f9..493607317a70b 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,20 +23,16 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIndexOrRangeOperator; using static CodeFixHelpers; -using static CSharpUseRangeOperatorDiagnosticAnalyzer; using static CSharpSyntaxTokens; +using static CSharpUseRangeOperatorDiagnosticAnalyzer; using static Helpers; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseRangeOperator), Shared] -internal class CSharpUseRangeOperatorCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseRangeOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseRangeOperatorCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseRangeOperatorDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs index 62b9558db992e..4bfd30a9f3ebf 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs index e9870962cfc1b..8cbfb46647a21 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; @@ -13,14 +11,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseInferredMemberName; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseInferredMemberName), Shared] -internal sealed class CSharpUseInferredMemberNameCodeFixProvider : AbstractUseInferredMemberNameCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseInferredMemberNameCodeFixProvider() : AbstractUseInferredMemberNameCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseInferredMemberNameCodeFixProvider() - { - } - protected override void LanguageSpecificRemoveSuggestedNode(SyntaxEditor editor, SyntaxNode node) => editor.RemoveNode(node, SyntaxRemoveOptions.KeepExteriorTrivia | SyntaxRemoveOptions.AddElasticMarker); } diff --git a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs index e6f9c13a3b0ee..a099c36cde8f4 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs @@ -2,21 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.UseInterpolatedVerbatimString; @@ -24,16 +18,11 @@ namespace Microsoft.CodeAnalysis.CSharp.UseInterpolatedVerbatimString; /// Converts a verbatim interpolated string @$"" to an interpolated verbatim string $@"" /// [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseInterpolatedVerbatimString), Shared] -internal partial class CSharpUseInterpolatedVerbatimStringCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpUseInterpolatedVerbatimStringCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseInterpolatedVerbatimStringCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds - => ["CS8401"]; + public override ImmutableArray FixableDiagnosticIds => ["CS8401"]; private const string InterpolatedVerbatimText = "$@\""; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs index 8b0f7f4352440..2cc538d91b2c4 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -25,14 +24,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; using static UseIsNullCheckHelpers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIsNullCheckForCastAndEqualityOperator), Shared] -internal class CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseIsNullCheckDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs index 94f65c24eb81a..8e545e1dc054c 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; @@ -18,7 +16,9 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; using static UseIsNullCheckHelpers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIsNullCheckForReferenceEquals), Shared] -internal class CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider() : AbstractUseIsNullCheckForReferenceEqualsCodeFixProvider { private static readonly LiteralExpressionSyntax s_nullLiteralExpression @@ -27,12 +27,6 @@ private static readonly LiteralExpressionSyntax s_nullLiteralExpression private static readonly ConstantPatternSyntax s_nullLiteralPattern = ConstantPattern(s_nullLiteralExpression); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider() - { - } - protected override string GetTitle(bool negated, ParseOptions options) => UseIsNullCheckHelpers.GetTitle(negated, options); diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs index 9e8d38a5f5f36..5c49751d76deb 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs @@ -5,10 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -22,16 +20,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNullCheckOverTypeCheck), Shared] -internal sealed class CSharpUseNullCheckOverTypeCheckCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseNullCheckOverTypeCheckCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private static readonly ConstantPatternSyntax s_nullConstantPattern = ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression)); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseNullCheckOverTypeCheckCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseNullCheckOverTypeCheckDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs index 233060a239f19..931722e8eb838 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs @@ -12,7 +12,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.CSharp.CodeGeneration; @@ -31,16 +30,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UseLocalFunction; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseLocalFunction), Shared] -internal class CSharpUseLocalFunctionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseLocalFunctionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private static readonly TypeSyntax s_objectType = PredefinedType(ObjectKeyword); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseLocalFunctionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseLocalFunctionDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs index 4f4ecf47dbc53..56a91d73f3a41 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.UseNameofInAttribute; using Microsoft.CodeAnalysis.Diagnostics; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.UseNameofInAttribute; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNameofInAttribute), Shared] -internal sealed class CSharpUseNameofInAttributeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseNameofInAttributeCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseNameofInAttributeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseNameofInAttributeDiagnosticId]; public override Task RegisterCodeFixesAsync(CodeFixContext context) diff --git a/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs index 43774aabce8e5..84b3074c92ac6 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs @@ -12,7 +12,9 @@ namespace Microsoft.CodeAnalysis.CSharp.UseNullPropagation; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNullPropagation), Shared] -internal class CSharpUseNullPropagationCodeFixProvider : AbstractUseNullPropagationCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseNullPropagationCodeFixProvider() : AbstractUseNullPropagationCodeFixProvider< SyntaxKind, ExpressionSyntax, StatementSyntax, @@ -27,12 +29,6 @@ internal class CSharpUseNullPropagationCodeFixProvider : AbstractUseNullPropagat ExpressionStatementSyntax, BracketedArgumentListSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseNullPropagationCodeFixProvider() - { - } - protected override bool TryGetBlock(SyntaxNode? statement, [NotNullWhen(true)] out StatementSyntax? block) { if (statement is BlockSyntax statementBlock) diff --git a/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs index c096ad0701ea7..04467a74c3815 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs @@ -17,7 +17,9 @@ namespace Microsoft.CodeAnalysis.CSharp.UseObjectInitializer; using ObjectInitializerMatch = Match; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseObjectInitializer), Shared] -internal sealed class CSharpUseObjectInitializerCodeFixProvider : +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseObjectInitializerCodeFixProvider() : AbstractUseObjectInitializerCodeFixProvider< SyntaxKind, ExpressionSyntax, @@ -29,12 +31,6 @@ internal sealed class CSharpUseObjectInitializerCodeFixProvider : VariableDeclaratorSyntax, CSharpUseNamedMemberInitializerAnalyzer> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseObjectInitializerCodeFixProvider() - { - } - protected override CSharpUseNamedMemberInitializerAnalyzer GetAnalyzer() => CSharpUseNamedMemberInitializerAnalyzer.Allocate(); diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs index c5f2bdfd401d3..e77d07be2fd57 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs @@ -2,10 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; @@ -24,21 +22,17 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternCombinators; -using static SyntaxFactory; using static AnalyzedPattern; +using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternCombinators), Shared] -internal class CSharpUsePatternCombinatorsCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUsePatternCombinatorsCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string SafeEquivalenceKey = nameof(CSharpUsePatternCombinatorsCodeFixProvider) + "_safe"; private const string UnsafeEquivalenceKey = nameof(CSharpUsePatternCombinatorsCodeFixProvider) + "_unsafe"; - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUsePatternCombinatorsCodeFixProvider() - { - } - private static SyntaxKind MapToSyntaxKind(BinaryOperatorKind kind) { return kind switch diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs index 0b98dabe808a6..a148b464e4ead 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +23,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternMatchingAsAndMemberAccess), Shared] -internal partial class CSharpAsAndMemberAccessCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpAsAndMemberAccessCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpAsAndMemberAccessCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UsePatternMatchingAsAndMemberAccessDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs index 6844779691092..c46ae30e09d37 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +23,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternMatchingAsAndNullCheck), Shared] -internal partial class CSharpAsAndNullCheckCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpAsAndNullCheckCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAsAndNullCheckCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.InlineAsTypeCheckId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs index bbf9084d3e89d..d234b3148fd34 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs @@ -2,16 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +20,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternMatchingIsAndCastCheck), Shared] -internal partial class CSharpIsAndCastCheckCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpIsAndCastCheckCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpIsAndCastCheckCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.InlineIsTypeCheckId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs index 4f10d8cdcad1d..1a3f54bbdcb20 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.CodeGeneration; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNotPattern), Shared] -internal sealed class CSharpUseNotPatternCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseNotPatternCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseNotPatternCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseNotPatternDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs index 74953322bd152..f2feec8761fe0 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs @@ -8,11 +8,9 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.LanguageService; @@ -31,14 +29,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseSimpleUsingStatement; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseSimpleUsingStatement), Shared] -internal class UseSimpleUsingStatementCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class UseSimpleUsingStatementCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public UseSimpleUsingStatementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseSimpleUsingStatementDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs index ce4845dc99f36..598b1cdca3762 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs @@ -2,14 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -22,14 +20,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseThrowExpression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseThrowExpression), Shared] -internal partial class UseThrowExpressionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class UseThrowExpressionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseThrowExpressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseThrowExpressionDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs index 1435cb8ad5c8a..deff3bf44e9f2 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs @@ -5,11 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -17,21 +14,16 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.UseTupleSwap; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseTupleSwap), Shared] -internal partial class CSharpUseTupleSwapCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpUseTupleSwapCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseTupleSwapCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseTupleSwapDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs index 3a241ce78237a..f82a29f839e6e 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -24,17 +23,13 @@ namespace Microsoft.CodeAnalysis.CSharp.UseUtf8StringLiteral; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseUtf8StringLiteral), Shared] -internal sealed class UseUtf8StringLiteralCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class UseUtf8StringLiteralCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const char QuoteCharacter = '"'; private const string Suffix = "u8"; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public UseUtf8StringLiteralCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseUtf8StringLiteralDiagnosticId]; diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs index fe31e1baf04c7..1b23c3f0ee10b 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs @@ -73,7 +73,7 @@ public sealed override ImmutableArray FixableDiagnosticIds /// /// Flagged node containing the identifier token to be replaced. /// New identifier token - protected abstract SyntaxNode TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName); + protected abstract SyntaxNode? TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName); /// /// Gets the identifier token for the iteration variable of the given foreach statement node. @@ -742,7 +742,7 @@ bool ShouldRemoveStatement(TLocalDeclarationStatementSyntax localDeclarationStat } } - protected abstract TLocalDeclarationStatementSyntax GetCandidateLocalDeclarationForRemoval(TVariableDeclaratorSyntax declarator); + protected abstract TLocalDeclarationStatementSyntax? GetCandidateLocalDeclarationForRemoval(TVariableDeclaratorSyntax declarator); private async Task PostProcessDocumentAsync( Document document,