提交 51672e53 编写于 作者: Y Yair Halberstadt 提交者: Shen Chen

Pull Members Up: A couple of fixes to pull to base class as abstract (#35331)

* Make methods overrides when pulling to base class with the make abstract option.
Remove abstract methods when pulling to base class with the make abstract option.

* Fix broken Unit tests

* Simplify code to add override modifier based on Code Review

* don't use generic ReplaceNode where not necessary in MembersPuller.PullMembersIntoClassAsync
上级 0427bb25
......@@ -1732,7 +1732,7 @@ public abstract class Base
public class TestClass : Base
{
public void TestMeth[||]od()
public override void TestMeth[||]od()
{
System.Console.WriteLine(""Hello World"");
}
......@@ -1767,7 +1767,6 @@ public abstract class Base
public abstract class TestClass : Base
{
public abstract void TestMethod();
}
}";
await TestWithPullMemberDialogAsync(testText, expected, new (string, bool)[] { ("TestMethod", true) }, index: 0);
......@@ -2173,7 +2172,7 @@ abstract class B
class D : B
{
int X => 7;
override int X => 7;
}";
await TestWithPullMemberDialogAsync(testText, expected, selection: new[] { ("X", true) }, index: 1);
}
......@@ -2249,7 +2248,7 @@ public abstract class BaseClass
public class TestClass : BaseClass
{
public event EventHandler Event1
public override event EventHandler Event1
{
add
{
......
......@@ -254,20 +254,26 @@ private static ISymbol GetSymbolsToPullUp(MemberAnalysisResult analysisResult)
var newDestination = codeGenerationService.AddMembers(destinationSyntaxNode, pullUpMembersSymbols, options: options);
// Remove some original members since we are pulling members into class.
// Note: If user chooses to make the member abstract, then the original member won't be touched,
// It will just pull a abstract declaration up to destination.
// Note: If the user chooses to make the member abstract, then the original member will be changed to an override,
// and it will pull an abstract declaration up to the destination.
// But if the member is abstract itself, it will still be removed.
foreach (var analysisResult in result.MemberAnalysisResults)
{
if (!analysisResult.MakeMemberDeclarationAbstract)
foreach (var syntax in symbolToDeclarations[analysisResult.Member])
{
foreach (var syntax in symbolToDeclarations[analysisResult.Member])
var originalMemberEditor = await solutionEditor.GetDocumentEditorAsync(
solution.GetDocumentId(syntax.SyntaxTree),
cancellationToken).ConfigureAwait(false);
if (!analysisResult.MakeMemberDeclarationAbstract || analysisResult.Member.IsAbstract)
{
var originalMemberEditor = await solutionEditor.GetDocumentEditorAsync(
solution.GetDocumentId(syntax.SyntaxTree),
cancellationToken).ConfigureAwait(false);
originalMemberEditor.RemoveNode(originalMemberEditor.Generator.GetDeclaration(syntax));
}
else
{
var declarationSyntax = originalMemberEditor.Generator.GetDeclaration(syntax);
originalMemberEditor.ReplaceNode(declarationSyntax, (node, generator) => generator.WithModifiers(node, DeclarationModifiers.Override));
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册