Skip to content

Commit 4078a22

Browse files
Update
1 parent 99029ec commit 4078a22

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/AttributesOnSeparateLines.cs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Collections.Immutable;
43
using System.Composition;
54
using System.Linq;
@@ -48,8 +47,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
4847
attributeList = attributeList.Parent;
4948
}
5049

51-
// Get the class, method or property adjacent to the AttributeList
52-
if (attributeList?.Parent is not SyntaxNode parentDeclaration)
50+
// Get the member declaration adjacent to the AttributeList
51+
if (attributeList?.Parent is not MemberDeclarationSyntax parentDeclaration)
5352
{
5453
return;
5554
}
@@ -63,12 +62,12 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
6362
diagnostic);
6463
}
6564

66-
private static async Task<Document> PutOnSeparateLine(Document document, SyntaxNode parentDeclaration, CancellationToken cancellationToken)
65+
private static async Task<Document> PutOnSeparateLine(Document document, MemberDeclarationSyntax parentDeclaration, CancellationToken cancellationToken)
6766
{
6867
var attributeLists = new SyntaxList<AttributeListSyntax>();
6968

7069
// put every attribute into it's own attributelist eg.: [A,B,C] => [A][B][C]
71-
foreach (AttributeSyntax attribute in GetAttributeListSyntaxes(parentDeclaration).SelectMany(l => l.Attributes))
70+
foreach (AttributeSyntax attribute in parentDeclaration.AttributeLists.SelectMany(l => l.Attributes))
7271
{
7372
attributeLists = attributeLists.Add(
7473
SyntaxFactory.AttributeList(
@@ -80,7 +79,7 @@ private static async Task<Document> PutOnSeparateLine(Document document, SyntaxN
8079
}
8180

8281
// the formatter-annotation will wrap every attribute on a separate line
83-
SyntaxNode newNode = BuildNodeWithAttributeLists(parentDeclaration, attributeLists)
82+
MemberDeclarationSyntax newNode = parentDeclaration.WithAttributeLists(attributeLists)
8483
.WithAdditionalAnnotations(Formatter.Annotation);
8584

8685
// Replace the old local declaration with the new local declaration.
@@ -90,23 +89,5 @@ private static async Task<Document> PutOnSeparateLine(Document document, SyntaxN
9089

9190
return document.WithSyntaxRoot(newRoot);
9291
}
93-
94-
private static IEnumerable<AttributeListSyntax> GetAttributeListSyntaxes(SyntaxNode node)
95-
{
96-
return node switch
97-
{
98-
MemberDeclarationSyntax m => m.AttributeLists,
99-
_ => Enumerable.Empty<AttributeListSyntax>(),
100-
};
101-
}
102-
103-
private static SyntaxNode BuildNodeWithAttributeLists(SyntaxNode node, SyntaxList<AttributeListSyntax> attributeLists)
104-
{
105-
return node switch
106-
{
107-
MemberDeclarationSyntax m => m.WithAttributeLists(attributeLists),
108-
_ => node,
109-
};
110-
}
11192
}
11293
}

0 commit comments

Comments
 (0)