2
// CSharpModifierToken.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using System.Collections.Generic;
30
namespace ICSharpCode.NRefactory.CSharp
32
public class CSharpModifierToken : CSharpTokenNode
36
public Modifiers Modifier {
37
get { return modifier; }
40
this.modifier = value;
44
protected override int TokenLength {
46
return GetModifierName (modifier).Length;
50
public override string GetText (CSharpFormattingOptions formattingOptions = null)
52
return GetModifierName (Modifier);
55
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
57
CSharpModifierToken o = other as CSharpModifierToken;
58
return o != null && this.modifier == o.modifier;
61
// Not worth using a dictionary for such few elements.
62
// This table is sorted in the order that modifiers should be output when generating code.
63
static readonly Modifiers[] allModifiers = {
64
Modifiers.Public, Modifiers.Protected, Modifiers.Private, Modifiers.Internal,
67
Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override,
68
Modifiers.Readonly, Modifiers.Volatile,
69
Modifiers.Extern, Modifiers.Partial, Modifiers.Const,
74
public static IEnumerable<Modifiers> AllModifiers {
75
get { return allModifiers; }
78
public CSharpModifierToken (TextLocation location, Modifiers modifier) : base (location)
80
this.Modifier = modifier;
83
public static string GetModifierName(Modifiers modifier)
86
case Modifiers.Private:
88
case Modifiers.Internal:
90
case Modifiers.Protected:
92
case Modifiers.Public:
94
case Modifiers.Abstract:
96
case Modifiers.Virtual:
98
case Modifiers.Sealed:
100
case Modifiers.Static:
102
case Modifiers.Override:
104
case Modifiers.Readonly:
106
case Modifiers.Const:
110
case Modifiers.Partial:
112
case Modifiers.Extern:
114
case Modifiers.Volatile:
116
case Modifiers.Unsafe:
118
case Modifiers.Async:
121
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
124
throw new NotSupportedException("Invalid value for Modifiers");
b'\\ No newline at end of file'