Skip to content

Commit

Permalink
Merge pull request #55900 from ryzngard/issues/55544_move_type_duplic…
Browse files Browse the repository at this point in the history
…ates_assemblyattr

Remove top level attributes on MoveTypeToFile
  • Loading branch information
ryzngard authored Aug 26, 2021
2 parents b5f3439 + 2463fc7 commit b11adaa
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1479,5 +1479,187 @@ public async Task MissingInTopLevelStatementsOnly()

await TestMissingAsync(code);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
[WorkItem(55544, "https://github.com/dotnet/roslyn/issues/55544")]
public async Task MoveInNamespace_WithAttributes1()
{
var code = @"
using Sytem.Reflection;
[assembly: AssemblyCompany("")]
namespace N
{
class A
{
}
class [||]B
{
}
}";

var codeAfterMove = @"
using Sytem.Reflection;
[assembly: AssemblyCompany("")]
namespace N
{
class A
{
}
}";

var expectedDocumentName = "B.cs";
var destinationDocumentText = @"namespace N
{
class B
{
}
}";

await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
[WorkItem(55544, "https://github.com/dotnet/roslyn/issues/55544")]
public async Task MoveInNamespace_WithAttributes2()
{
var code = @"
using Sytem.Reflection;
[assembly: AssemblyCompany("")]
namespace N
{
class A
{
}
[Test]
class [||]B
{
}
}";

var codeAfterMove = @"
using Sytem.Reflection;
[assembly: AssemblyCompany("")]
namespace N
{
class A
{
}
}";

var expectedDocumentName = "B.cs";
var destinationDocumentText = @"namespace N
{
[Test]
class B
{
}
}";

await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
[WorkItem(55544, "https://github.com/dotnet/roslyn/issues/55544")]
public async Task MoveInNamespace_WithAttributes3()
{
var code = @"
namespace N
{
class A
{
}
[Test]
class [||]B
{
}
}";

var codeAfterMove = @"
namespace N
{
class A
{
}
}";

var expectedDocumentName = "B.cs";
var destinationDocumentText = @"
namespace N
{
[Test]
class B
{
}
}";

await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
[WorkItem(55544, "https://github.com/dotnet/roslyn/issues/55544")]
public async Task MoveTopLevel_WithAttributes1()
{
var code = @"
[Test]
class [||]A
{
}
class B
{
}";

var codeAfterMove = @"
class B
{
}";

var expectedDocumentName = "A.cs";
var destinationDocumentText = @"[Test]
class A
{
}
";

await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
[WorkItem(55544, "https://github.com/dotnet/roslyn/issues/55544")]
public async Task MoveTopLevel_WithAttributes2()
{
var code = @"
[Test]
class [||]A
{
}
[Test]
class B
{
}";

var codeAfterMove = @"
[Test]
class B
{
}";

var expectedDocumentName = "A.cs";
var destinationDocumentText = @"[Test]
class A
{
}
";

await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ private async Task<Document> AddNewDocumentWithSingleTypeDeclarationAsync(Docume
foreach (var member in membersToRemove)
documentEditor.RemoveNode(member, SyntaxRemoveOptions.KeepNoTrivia);

// Remove attributes from the root node as well, since those will apply as AttributeTarget.Assembly and
// don't need to be specified multiple times
documentEditor.RemoveAllAttributes(root);

var modifiedRoot = documentEditor.GetChangedRoot();
modifiedRoot = await AddFinalNewLineIfDesiredAsync(document, modifiedRoot).ConfigureAwait(false);

Expand Down

0 comments on commit b11adaa

Please sign in to comment.