~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/CSharpBinding/MonoDevelop.CSharp.Ast/CSharpModifierToken.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
Import upstream version 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// CSharpModifierToken.cs
 
3
//  
 
4
// Author:
 
5
//       Mike Krüger <mkrueger@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using System.Collections.Generic;
 
28
using MonoDevelop.Projects.Dom;
 
29
 
 
30
namespace MonoDevelop.CSharp.Ast
 
31
{
 
32
        public class CSharpModifierToken : CSharpTokenNode
 
33
        {
 
34
                Modifiers modifier;
 
35
                
 
36
                public Modifiers Modifier {
 
37
                        get { return modifier; }
 
38
                        set {
 
39
                                modifier = value;
 
40
                                if (!lengthTable.TryGetValue (modifier, out tokenLength))
 
41
                                        throw new InvalidOperationException ("Modifier " + modifier + " is invalid.");
 
42
                        }
 
43
                }
 
44
                
 
45
                static Dictionary<Modifiers, int> lengthTable = new Dictionary<Modifiers, int> () {
 
46
                        { Modifiers.Public, "public".Length },
 
47
                        { Modifiers.Protected, "protected".Length },
 
48
                        { Modifiers.Private, "private".Length },
 
49
                        { Modifiers.Internal, "internal".Length },
 
50
                        { Modifiers.New, "new".Length },
 
51
                        { Modifiers.Unsafe, "unsafe".Length },
 
52
                        { Modifiers.Abstract, "abstract".Length },
 
53
                        { Modifiers.Virtual, "virtual".Length },
 
54
                        { Modifiers.Sealed, "sealed".Length },
 
55
                        { Modifiers.Static, "static".Length },
 
56
                        { Modifiers.Override, "override".Length },
 
57
                        { Modifiers.Readonly, "readonly".Length },
 
58
                        { Modifiers.Volatile, "volatile".Length },
 
59
                        { Modifiers.Extern, "extern".Length },
 
60
                        { Modifiers.Partial, "partial".Length },
 
61
                        { Modifiers.Const, "const".Length },
 
62
                };
 
63
                
 
64
                public static ICollection<Modifiers> AllModifiers {
 
65
                        get { return lengthTable.Keys; }
 
66
                }
 
67
                
 
68
                public CSharpModifierToken (AstLocation location, Modifiers modifier) : base (location, 0)
 
69
                {
 
70
                        this.Modifier = modifier;
 
71
                }
 
72
                
 
73
                public static string GetModifierName(Modifiers modifier)
 
74
                {
 
75
                        switch (modifier) {
 
76
                                case Modifiers.Private:
 
77
                                        return "private";
 
78
                                case Modifiers.Internal:
 
79
                                        return "internal";
 
80
                                case Modifiers.Protected:
 
81
                                        return "protected";
 
82
                                case Modifiers.Public:
 
83
                                        return "public";
 
84
                                case Modifiers.Abstract:
 
85
                                        return "abstract";
 
86
                                case Modifiers.Virtual:
 
87
                                        return "virtual";
 
88
                                case Modifiers.Sealed:
 
89
                                        return "sealed";
 
90
                                case Modifiers.Static:
 
91
                                        return "static";
 
92
                                case Modifiers.Override:
 
93
                                        return "override";
 
94
                                case Modifiers.Readonly:
 
95
                                        return "readonly";
 
96
                                case Modifiers.Const:
 
97
                                        return "const";
 
98
                                case Modifiers.New:
 
99
                                        return "new";
 
100
                                case Modifiers.Partial:
 
101
                                        return "partial";
 
102
                                case Modifiers.Extern:
 
103
                                        return "extern";
 
104
                                case Modifiers.Volatile:
 
105
                                        return "volatile";
 
106
                                case Modifiers.Unsafe:
 
107
                                        return "unsafe";
 
108
                                case Modifiers.Fixed:
 
109
                                        return "fixed";
 
110
                                default:
 
111
                                        throw new NotSupportedException("Invalid value for Modifiers");
 
112
                        }
 
113
                }
 
114
        }
 
115
}
 
 
b'\\ No newline at end of file'