|
| 1 | +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
| 2 | +// Licensed under the MIT License. See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +namespace StyleCop.Analyzers.Lightup |
| 5 | +{ |
| 6 | + using System; |
| 7 | + using Microsoft.CodeAnalysis; |
| 8 | + using Microsoft.CodeAnalysis.CSharp.Syntax; |
| 9 | + |
| 10 | + internal static class MemberDeclarationSyntaxExtensions |
| 11 | + { |
| 12 | + private static readonly Func<MemberDeclarationSyntax, SyntaxList<AttributeListSyntax>> AttributeListsAccessor; |
| 13 | + private static readonly Func<MemberDeclarationSyntax, SyntaxTokenList> ModifiersAccessor; |
| 14 | + private static readonly Func<MemberDeclarationSyntax, SyntaxList<AttributeListSyntax>, MemberDeclarationSyntax> WithAttributeListsAccessor; |
| 15 | + private static readonly Func<MemberDeclarationSyntax, SyntaxTokenList, MemberDeclarationSyntax> WithModifiersAccessor; |
| 16 | + |
| 17 | + static MemberDeclarationSyntaxExtensions() |
| 18 | + { |
| 19 | + AttributeListsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor<MemberDeclarationSyntax, SyntaxList<AttributeListSyntax>>(typeof(MemberDeclarationSyntax), nameof(AttributeLists)); |
| 20 | + ModifiersAccessor = LightupHelpers.CreateSyntaxPropertyAccessor<MemberDeclarationSyntax, SyntaxTokenList>(typeof(MemberDeclarationSyntax), nameof(Modifiers)); |
| 21 | + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor<MemberDeclarationSyntax, SyntaxList<AttributeListSyntax>>(typeof(MemberDeclarationSyntax), nameof(AttributeLists)); |
| 22 | + WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor<MemberDeclarationSyntax, SyntaxTokenList>(typeof(MemberDeclarationSyntax), nameof(Modifiers)); |
| 23 | + } |
| 24 | + |
| 25 | + public static SyntaxList<AttributeListSyntax> AttributeLists(this MemberDeclarationSyntax syntax) |
| 26 | + { |
| 27 | + return AttributeListsAccessor(syntax); |
| 28 | + } |
| 29 | + |
| 30 | + public static SyntaxTokenList Modifiers(this MemberDeclarationSyntax syntax) |
| 31 | + { |
| 32 | + return ModifiersAccessor(syntax); |
| 33 | + } |
| 34 | + |
| 35 | + public static MemberDeclarationSyntax WithAttributeLists(this MemberDeclarationSyntax syntax, SyntaxList<AttributeListSyntax> attributeLists) |
| 36 | + { |
| 37 | + return WithAttributeListsAccessor(syntax, attributeLists); |
| 38 | + } |
| 39 | + |
| 40 | + public static MemberDeclarationSyntax WithModifiers(this MemberDeclarationSyntax syntax, SyntaxTokenList modifiers) |
| 41 | + { |
| 42 | + return WithModifiersAccessor(syntax, modifiers); |
| 43 | + } |
| 44 | + |
| 45 | + public static MemberDeclarationSyntax AddAttributeLists(this MemberDeclarationSyntax syntax, params AttributeListSyntax[] items) |
| 46 | + { |
| 47 | + return syntax.WithAttributeLists(syntax.AttributeLists().AddRange(items)); |
| 48 | + } |
| 49 | + |
| 50 | + public static MemberDeclarationSyntax AddModifiers(this MemberDeclarationSyntax syntax, params SyntaxToken[] items) |
| 51 | + { |
| 52 | + return syntax.WithModifiers(syntax.Modifiers().AddRange(items)); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments