Add code fix for CS0513#40448
Add code fix for CS0513#40448mavasani merged 10 commits intodotnet:masterfrom Evangelink:codefix-CS0513
Conversation
Make enclosing class abstract when member does not have body.
src/Features/CSharp/Portable/MakeClassAbstract/CSharpMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MakeClassAbstract/AbstractMakeClassAbstractCodeFixProvider.cs
Show resolved
Hide resolved
src/Features/Core/Portable/MakeClassAbstract/AbstractMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/MakeClassAbstract/CSharpMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MakeClassAbstract/AbstractMakeClassAbstractCodeFixProvider.cs
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/MakeClassAbstract/MakeClassAbstractTests.cs
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/MakeClassAbstract/MakeClassAbstractTests.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/MakeClassAbstract/CSharpMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MakeClassAbstract/AbstractMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
| { | ||
| var enclosingClass = declaration.FirstAncestorOrSelf<TClassDeclarationSyntax>(); | ||
| editor.ReplaceNode(enclosingClass, | ||
| (currentClassDeclaration, generator) => generator.WithModifiers(currentClassDeclaration, DeclarationModifiers.Abstract)); |
There was a problem hiding this comment.
won't this blow away other modifiers? don't you need to 'union' this with the existing mods?
There was a problem hiding this comment.
That was my thought at first but this seem to keep the existing modifiers and just apply the new one (with some validity check).
There was a problem hiding this comment.
Yes, the current behavior seems strange to me for a With method. Ideally it should overwrite, not merge. It is unlikely we would change the behavior though as it would be a breaking change.
There was a problem hiding this comment.
@mavasani Well it can simply be overwrite as we need to keep the other modifiers or am I missing something?
src/Features/Core/Portable/MakeClassAbstract/AbstractMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MakeClassAbstract/AbstractMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
|
hey @Evangelink Thanks for the PR! |
|
Missing VB impl and tests currently. Can you add those? |
|
@CyrusNajmabadi I haven't added an impl for VB.NET because I couldn't find the equivalent error in |
src/Features/CSharp/Portable/MakeClassAbstract/CSharpMakeClassAbstractCodeFixProvider.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/MakeClassAbstract/CSharpMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
|
@vatsalyaagrawal I removed the Area-Compilers label as I don't see any compiler file change. Let me know if I missed something. Thanks |
src/EditorFeatures/CSharpTest/MakeClassAbstract/MakeClassAbstractTests.cs
Show resolved
Hide resolved
src/Features/Core/Portable/MakeClassAbstract/AbstractMakeClassAbstractCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
mavasani
left a comment
There was a problem hiding this comment.
Overall LGTM. Some minor suggestions and an open question on whether the abstract modifier should be added to all declarations of a partial type.
|
@Evangelink can you please resolve conflicts and fix CI? |
|
I have "fixed" the CI but I don't understand why so many cases do not work for vbnet (including the fixall), the implementation seems to match other codefix. |
|
See #42814 |
|
@mavasani I don't understand what's going wrong with the tests/PR. I have copied the behavior/structure from the |
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MakeClassAbstract | ||
| { | ||
| public class MakeClassAbstractTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest |
There was a problem hiding this comment.
@Evangelink Can we instead just convert these tests to use the new test framework? Will that be too much work? That will avoid you having to add a public ctor for this code fixer and then suppressing RS0033.
There was a problem hiding this comment.
If https://github.com/dotnet/roslyn/pull/40448/files#r450282581 addresses the CI, it is fine to skip changing the tests for this PR.
There was a problem hiding this comment.
I have tried (if I got it right that the syntax is the same as for roslyn-analyzers) but I end-up with nuget errors: NuGet.Protocol.Core.Types.FatalProtocolException : Unable to load the service index for source https://api.nuget.org/v3/index.json.
There was a problem hiding this comment.
I think it is fine to not do this as part of this PR. You may want to file a follow-up issue with your questions. Also suggest looking at the existing tests which are already moved to new framework, for example: https://github.com/dotnet/roslyn/blob/master/src/Analyzers/CSharp/Tests/RemoveUnnecessaryImports/RemoveUnnecessaryImportsTests.cs

Make enclosing class abstract when member does not have body.
Fix #31833