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
public override TextLocation EndLocation {
46
return new TextLocation (StartLocation.Line, StartLocation.Column + GetModifierLength (Modifier));
50
public override string ToString(CSharpFormattingOptions formattingOptions)
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, null)
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");
128
public static int GetModifierLength(Modifiers modifier)
131
case Modifiers.Private:
132
return "private".Length;
133
case Modifiers.Internal:
134
return "internal".Length;
135
case Modifiers.Protected:
136
return "protected".Length;
137
case Modifiers.Public:
138
return "public".Length;
139
case Modifiers.Abstract:
140
return "abstract".Length;
141
case Modifiers.Virtual:
142
return "virtual".Length;
143
case Modifiers.Sealed:
144
return "sealed".Length;
145
case Modifiers.Static:
146
return "static".Length;
147
case Modifiers.Override:
148
return "override".Length;
149
case Modifiers.Readonly:
150
return "readonly".Length;
151
case Modifiers.Const:
152
return "const".Length;
155
case Modifiers.Partial:
156
return "partial".Length;
157
case Modifiers.Extern:
158
return "extern".Length;
159
case Modifiers.Volatile:
160
return "volatile".Length;
161
case Modifiers.Unsafe:
162
return "unsafe".Length;
163
case Modifiers.Async:
164
return "async".Length;
166
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
169
throw new NotSupportedException("Invalid value for Modifiers");
b'\\ No newline at end of file'