未验证 提交 195ddaf9 编写于 作者: M Manish Vasani 提交者: GitHub

Merge pull request #40448 from Evangelink/codefix-CS0513

Add code fix for CS0513
// Licensed to the .NET Foundation under one or more agreements.
// 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.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.MakeClassAbstract;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MakeClassAbstract
{
public class MakeClassAbstractTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
=> (null, new CSharpMakeClassAbstractCodeFixProvider());
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestMethod()
{
await TestInRegularAndScript1Async(
@"
public class Foo
{
public abstract void [|M|]();
}",
@"
public abstract class Foo
{
public abstract void M();
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestMethodEnclosingClassWithoutAccessibility()
{
await TestInRegularAndScript1Async(
@"
class Foo
{
public abstract void [|M|]();
}",
@"
abstract class Foo
{
public abstract void M();
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestMethodEnclosingClassDocumentationComment()
{
await TestInRegularAndScript1Async(
@"
/// <summary>
/// Some class comment.
/// </summary>
public class Foo
{
public abstract void [|M|]();
}",
@"
/// <summary>
/// Some class comment.
/// </summary>
public abstract class Foo
{
public abstract void M();
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestPropertyGetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
{
public abstract object P { [|get|]; }
}",
@"
public abstract class Foo
{
public abstract object P { get; }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestPropertySetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
{
public abstract object P { [|set|]; }
}",
@"
public abstract class Foo
{
public abstract object P { set; }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestIndexerGetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
{
public abstract object this[object o] { [|get|]; }
}",
@"
public abstract class Foo
{
public abstract object this[object o] { get; }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestIndexerSetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
{
public abstract object this[object o] { [|set|]; }
}",
@"
public abstract class Foo
{
public abstract object this[object o] { set; }
}");
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/41654"), Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestPartialClass()
{
await TestInRegularAndScript1Async(
@"
public partial class Foo
{
public abstract void [|M|]();
}
public partial class Foo
{
}",
@"
public partial abstract class Foo
{
public abstract void M();
}
public partial class Foo
{
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestEventAdd()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
{
public abstract event System.EventHandler E { [|add|]; }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestEventRemove()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
{
public abstract event System.EventHandler E { [|remove|]; }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestMethodWithBody()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
{
public abstract int [|M|]() => 3;
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestPropertyGetterWithArrowBody()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
{
public abstract int [|P|] => 3;
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestPropertyGetterWithBody()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
{
public abstract int P
{
[|get|] { return 1; }
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestStructNestedInClass()
{
await TestMissingInRegularAndScriptAsync(
@"
public class C
{
public struct S
{
public abstract void [|Foo|]();
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task TestMethodEnclosingClassStatic()
{
await TestMissingInRegularAndScriptAsync(
@"
public static class Foo
{
public abstract void [|M|]();
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)]
public async Task FixAll()
{
await TestInRegularAndScript1Async(
@"namespace NS
{
using System;
public class C1
{
public abstract void {|FixAllInDocument:|}M();
public abstract object P { get; set; }
public abstract object this[object o] { get; set; }
}
public class C2
{
public abstract void M();
}
public class C3
{
public class InnerClass
{
public abstract void M();
}
}
}",
@"namespace NS
{
using System;
public abstract class C1
{
public abstract void M();
public abstract object P { get; set; }
public abstract object this[object o] { get; set; }
}
public abstract class C2
{
public abstract void M();
}
public class C3
{
public abstract class InnerClass
{
public abstract void M();
}
}
}");
}
}
}
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics
Imports Microsoft.CodeAnalysis.VisualBasic.MakeClassAbstract
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.MakeClassAbstract
Public Class MakeClassAbstractTests
Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest
Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace) As (DiagnosticAnalyzer, CodeFixProvider)
Return (Nothing, New VisualBasicMakeClassAbstractCodeFixProvider())
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestMethod_CodeFix() As Task
Await TestInRegularAndScript1Async("
Public Class [|Foo|]
Public MustOverride Sub M()
End Class",
"
Public MustOverride Class Foo
Public MustOverride Sub M()
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestMethodEnclosingClassWithoutAccessibility_NoCodeFix() As Task
Await TestMissingInRegularAndScriptAsync("
Class Foo
Public MustOverride Sub [|M|]()
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestMethodEnclosingClassDocumentationComment() As Task
Await TestMissingInRegularAndScriptAsync("
''' <summary>
''' Some class comment.
''' </summary>
Public Class Foo
Public MustOverride Sub [|M|]()
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestProperty() As Task
Await TestMissingInRegularAndScriptAsync("
Public Class Foo
Public MustOverride Property [|P|] As Object
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestIndexer() As Task
Await TestMissingInRegularAndScriptAsync("
Public Class Foo
Default Public MustOverride Property [|Item|](ByVal o As Object) As Object
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestEvent() As Task
Await TestMissingInRegularAndScriptAsync("
Public Class Foo
Public MustOverride Custom Event [|E|] As EventHandler
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestMethodWithBody() As Task
Await TestMissingInRegularAndScriptAsync("
Public Class Foo
Public MustOverride Function [|M|]() As Integer
Return 3
End Function
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestPropertyWithBody() As Task
Await TestMissingInRegularAndScriptAsync(
"
Public Class Foo
Public MustOverride ReadOnly Property [|P|] As Integer
Get
Return 3
End Get
End Property
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestStructNestedInClass() As Task
Await TestMissingInRegularAndScriptAsync(
"
Public Class C
Public Structure S
Public MustOverride Sub [|Foo|]()
End Structure
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function TestMethodEnclosingClassStatic() As Task
Await TestMissingInRegularAndScriptAsync(
"
Public Static Class Foo
Public MustOverride Sub [|M|]()
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeClassAbstract)>
Public Async Function FixAll() As Task
Await TestMissingInRegularAndScriptAsync("
Namespace NS
Public Class C1
Public MustOverride Sub {|FixAllInDocument:M|}()
Public MustOverride Property P As Object
Default Public MustOverride Property Item(ByVal o As Object) As Object
End Class
Public Class C2
Public MustOverride Sub M()
End Class
Public Class C3
Public Class InnerClass
Public MustOverride Sub M()
End Class
End Class
End Namespace")
End Function
End Class
End Namespace
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.MakeClassAbstract;
namespace Microsoft.CodeAnalysis.CSharp.MakeClassAbstract
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CSharpMakeClassAbstractCodeFixProvider)), Shared]
internal sealed class CSharpMakeClassAbstractCodeFixProvider : AbstractMakeClassAbstractCodeFixProvider<ClassDeclarationSyntax>
{
[ImportingConstructor]
[SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
public CSharpMakeClassAbstractCodeFixProvider()
{
}
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(
"CS0513" // 'C.M()' is abstract but it is contained in non-abstract class 'C'
);
protected override bool IsValidRefactoringContext(SyntaxNode? node, [NotNullWhen(true)] out ClassDeclarationSyntax? classDeclaration)
{
classDeclaration = null;
switch (node?.Kind())
{
case SyntaxKind.MethodDeclaration:
var method = (MethodDeclarationSyntax)node;
if (method.Body != null || method.ExpressionBody != null)
{
return false;
}
break;
case SyntaxKind.GetAccessorDeclaration:
case SyntaxKind.SetAccessorDeclaration:
var accessor = (AccessorDeclarationSyntax)node;
if (accessor.Body != null || accessor.ExpressionBody != null)
{
return false;
}
break;
default:
return false;
}
var enclosingType = node.FirstAncestorOrSelf<TypeDeclarationSyntax>();
if (!enclosingType.IsKind(SyntaxKind.ClassDeclaration))
{
return false;
}
classDeclaration = (ClassDeclarationSyntax)enclosingType;
return !classDeclaration.Modifiers.Any(SyntaxKind.AbstractKeyword) && !classDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword);
}
}
}
......@@ -2780,4 +2780,7 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<data name="Property_reference_cannot_be_updated" xml:space="preserve">
<value>Property reference cannot be updated</value>
</data>
<data name="Make_class_abstract" xml:space="preserve">
<value>Make class 'abstract'</value>
</data>
</root>
\ No newline at end of file
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.MakeClassAbstract
{
internal abstract class AbstractMakeClassAbstractCodeFixProvider<TClassDeclarationSyntax> : SyntaxEditorBasedCodeFixProvider
where TClassDeclarationSyntax : SyntaxNode
{
protected abstract bool IsValidRefactoringContext(SyntaxNode? node, out TClassDeclarationSyntax? classDeclaration);
internal sealed override CodeFixCategory CodeFixCategory => CodeFixCategory.Compile;
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
{
if (IsValidRefactoringContext(context.Diagnostics[0].Location?.FindNode(context.CancellationToken), out _))
{
context.RegisterCodeFix(
new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics[0], c)),
context.Diagnostics);
}
return Task.CompletedTask;
}
protected sealed override Task FixAllAsync(Document document, ImmutableArray<Diagnostic> diagnostics, SyntaxEditor editor,
CancellationToken cancellationToken)
{
for (var i = 0; i < diagnostics.Length; i++)
{
if (IsValidRefactoringContext(diagnostics[i].Location?.FindNode(cancellationToken), out var classDeclaration))
{
editor.ReplaceNode(classDeclaration,
(currentClassDeclaration, generator) => generator.WithModifiers(currentClassDeclaration, DeclarationModifiers.Abstract));
}
}
return Task.CompletedTask;
}
private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(FeaturesResources.Make_class_abstract, createChangedDocument, FeaturesResources.Make_class_abstract)
{
}
}
}
}
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Nastavit jako statickou</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Als statisch festlegen</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Hacer estático</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Rendre statique</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Imposta come statici</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">静的にする</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">정적으로 만들기</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Ustaw jako statyczne</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Tornar estático</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Сделать статическим</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">Statik yap</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">设为静态</target>
......
......@@ -525,6 +525,11 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma
<target state="new">Invalid group name: Group names must begin with a word character</target>
<note>This is an error message shown to the user when they write an invalid Regular Expression. Example: (?&lt;a &gt;a)</note>
</trans-unit>
<trans-unit id="Make_class_abstract">
<source>Make class 'abstract'</source>
<target state="new">Make class 'abstract'</target>
<note />
</trans-unit>
<trans-unit id="Make_member_static">
<source>Make static</source>
<target state="translated">使其變成靜態</target>
......
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports System.Collections.Immutable
Imports System.Composition
Imports System.Diagnostics.CodeAnalysis
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.MakeClassAbstract
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.MakeClassAbstract
<ExportCodeFixProvider(LanguageNames.VisualBasic, Name:=NameOf(VisualBasicMakeClassAbstractCodeFixProvider)), [Shared]>
Friend NotInheritable Class VisualBasicMakeClassAbstractCodeFixProvider
Inherits AbstractMakeClassAbstractCodeFixProvider(Of ClassStatementSyntax)
<ImportingConstructor>
<SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification:="Used in test code: https://github.com/dotnet/roslyn/issues/42814")>
Public Sub New()
End Sub
Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String) =
ImmutableArray.Create(
"BC31411"
)
Protected Overrides Function IsValidRefactoringContext(node As SyntaxNode, ByRef classDeclaration As ClassStatementSyntax) As Boolean
If node Is Nothing OrElse Not (node.IsKind(SyntaxKind.ClassStatement)) Then
Return False
End If
classDeclaration = CType(node, ClassStatementSyntax)
Return Not (classDeclaration.Modifiers.Any(SyntaxKind.MustInheritKeyword) OrElse classDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword))
End Function
End Class
End Namespace
......@@ -113,6 +113,7 @@ public static class Features
public const string CodeActionsInvertLogical = "CodeActions.InvertLogical";
public const string CodeActionsInvokeDelegateWithConditionalAccess = "CodeActions.InvokeDelegateWithConditionalAccess";
public const string CodeActionsLambdaSimplifier = "CodeActions.LambdaSimplifier";
public const string CodeActionsMakeClassAbstract = "CodeActions.MakeClassAbstract";
public const string CodeActionsMakeFieldReadonly = "CodeActions.MakeFieldReadonly";
public const string CodeActionsMakeLocalFunctionStatic = "CodeActions.MakeLocalFunctionStatic";
public const string CodeActionsMakeMethodAsynchronous = "CodeActions.MakeMethodAsynchronous";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册