|
1 | 1 | // Copyright (c) Contributors to the New StyleCop Analyzers project. |
2 | 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. |
3 | 3 |
|
4 | | -#nullable disable |
5 | | - |
6 | 4 | namespace StyleCop.Analyzers.OrderingRules |
7 | 5 | { |
8 | 6 | using System.Collections.Immutable; |
@@ -74,7 +72,7 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen |
74 | 72 | var keywordToken = typeDeclarationNode.Keyword; |
75 | 73 |
|
76 | 74 | var replacementModifiers = DeclarationModifiersHelper.AddModifiers(typeDeclarationNode.Modifiers, ref keywordToken, accessModifierKinds); |
77 | | - var replacementNode = ReplaceModifiers(typeDeclarationNode, replacementModifiers); |
| 75 | + var replacementNode = (TypeDeclarationSyntax)typeDeclarationNode.WithModifiers(replacementModifiers); |
78 | 76 | replacementNode = ReplaceKeyword(replacementNode, keywordToken); |
79 | 77 | var newSyntaxRoot = syntaxRoot.ReplaceNode(typeDeclarationNode, replacementNode); |
80 | 78 | return document.WithSyntaxRoot(newSyntaxRoot); |
@@ -102,26 +100,6 @@ private static ImmutableArray<SyntaxKind> GetMissingAccessModifiers(Accessibilit |
102 | 100 | } |
103 | 101 | } |
104 | 102 |
|
105 | | - // This code was copied from the Roslyn code base (and slightly modified). It can be removed if |
106 | | - // TypeDeclarationSyntaxExtensions.WithModifiers is made public (Roslyn issue #2186) |
107 | | - private static TypeDeclarationSyntax ReplaceModifiers(TypeDeclarationSyntax node, SyntaxTokenList modifiers) |
108 | | - { |
109 | | - switch (node.Kind()) |
110 | | - { |
111 | | - case SyntaxKind.ClassDeclaration: |
112 | | - return ((ClassDeclarationSyntax)node).WithModifiers(modifiers); |
113 | | - case SyntaxKind.InterfaceDeclaration: |
114 | | - return ((InterfaceDeclarationSyntax)node).WithModifiers(modifiers); |
115 | | - case SyntaxKind.StructDeclaration: |
116 | | - return ((StructDeclarationSyntax)node).WithModifiers(modifiers); |
117 | | - case SyntaxKindEx.RecordDeclaration: |
118 | | - case SyntaxKindEx.RecordStructDeclaration: |
119 | | - return ((RecordDeclarationSyntaxWrapper)node).WithModifiers(modifiers); |
120 | | - } |
121 | | - |
122 | | - return node; |
123 | | - } |
124 | | - |
125 | 103 | // This code was copied from the Roslyn code base (and slightly modified). It can be removed if |
126 | 104 | // TypeDeclarationSyntaxExtensions.WithModifiers is made public (Roslyn issue #2186) |
127 | 105 | private static TypeDeclarationSyntax ReplaceKeyword(TypeDeclarationSyntax node, SyntaxToken keyword) |
|
0 commit comments