-
Notifications
You must be signed in to change notification settings - Fork 507
/
ModifierOrderHelper.cs
80 lines (69 loc) · 2.86 KB
/
ModifierOrderHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#nullable disable
namespace StyleCop.Analyzers.OrderingRules
{
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Lightup;
internal static class ModifierOrderHelper
{
/// <summary>
/// Represents modifier type for implementing SA1206 rule.
/// </summary>
internal enum ModifierType
{
/// <summary>
/// Represents default value.
/// </summary>
None,
/// <summary>
/// Represents any of access modifiers, i.e <see langword="public"/>, <see langword="protected"/>, <see langword="internal"/>, <see langword="private"/>, <see langword="file"/>.
/// </summary>
Access,
/// <summary>
/// Represents <see langword="static"/> modifier.
/// </summary>
Static,
/// <summary>
/// Represents other modifiers, i.e <see langword="partial"/>, <see langword="virtual"/>, <see langword="abstract"/>, <see langword="override"/>, <see langword="extern"/>, <see langword="unsafe"/>, <see langword="new"/>, <see langword="async"/>, <see langword="const"/>, <see langword="sealed"/>, <see langword="readonly"/>, <see langword="volatile"/>, <see langword="fixed"/>, <see langword="ref"/>.
/// </summary>
Other,
}
internal static ModifierType GetModifierType(SyntaxToken modifier)
{
var result = default(ModifierType);
switch (modifier.Kind())
{
case SyntaxKind.PublicKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.InternalKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKindEx.FileKeyword:
result = ModifierType.Access;
break;
case SyntaxKind.StaticKeyword:
result = ModifierType.Static;
break;
case SyntaxKind.VirtualKeyword:
case SyntaxKind.AbstractKeyword:
case SyntaxKind.OverrideKeyword:
case SyntaxKind.ExternKeyword:
case SyntaxKind.UnsafeKeyword:
case SyntaxKind.NewKeyword:
case SyntaxKind.SealedKeyword:
case SyntaxKind.ReadOnlyKeyword:
case SyntaxKind.VolatileKeyword:
case SyntaxKind.FixedKeyword:
case SyntaxKind.ConstKeyword:
case SyntaxKind.AsyncKeyword:
case SyntaxKind.PartialKeyword:
case SyntaxKind.RefKeyword:
case SyntaxKindEx.RequiredKeyword:
result = ModifierType.Other;
break;
}
return result;
}
}
}