~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.CSharp/Ast/Identifier.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// Identifier.cs
 
3
//
 
4
// Author:
 
5
//       Mike Krüger <mkrueger@novell.com>
 
6
// 
 
7
// Copyright (c) 2009 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
 
 
27
using System;
 
28
 
 
29
namespace ICSharpCode.NRefactory.CSharp
 
30
{
 
31
        public class Identifier : AstNode
 
32
        {
 
33
                public new static readonly Identifier Null = new NullIdentifier ();
 
34
                sealed class NullIdentifier : Identifier
 
35
                {
 
36
                        public override bool IsNull {
 
37
                                get {
 
38
                                        return true;
 
39
                                }
 
40
                        }
 
41
                        
 
42
                        public override void AcceptVisitor (IAstVisitor visitor)
 
43
                        {
 
44
                        }
 
45
                        
 
46
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
47
                        {
 
48
                                return default (T);
 
49
                        }
 
50
                        
 
51
                        public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
52
                        {
 
53
                                return default (S);
 
54
                        }
 
55
                        
 
56
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
57
                        {
 
58
                                return other == null || other.IsNull;
 
59
                        }
 
60
                }
 
61
                
 
62
                public override NodeType NodeType {
 
63
                        get {
 
64
                                return NodeType.Token;
 
65
                        }
 
66
                }
 
67
                
 
68
                string name;
 
69
                public string Name {
 
70
                        get { return this.name; }
 
71
                        set {
 
72
                                if (value == null)
 
73
                                        throw new ArgumentNullException("value");
 
74
                                ThrowIfFrozen();
 
75
                                this.name = value;
 
76
                        }
 
77
                }
 
78
                
 
79
                TextLocation startLocation;
 
80
                public override TextLocation StartLocation {
 
81
                        get {
 
82
                                return startLocation;
 
83
                        }
 
84
                }
 
85
                
 
86
                const uint verbatimBit = 1u << AstNodeFlagsUsedBits;
 
87
                
 
88
                public bool IsVerbatim {
 
89
                        get {
 
90
                                return (flags & verbatimBit) != 0;
 
91
                        }
 
92
                        set {
 
93
                                ThrowIfFrozen();
 
94
                                if (value)
 
95
                                        flags |= verbatimBit;
 
96
                                else
 
97
                                        flags &= ~verbatimBit;
 
98
                        }
 
99
                }
 
100
                
 
101
                public override TextLocation EndLocation {
 
102
                        get {
 
103
                                return new TextLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length + (IsVerbatim ? 1 : 0));
 
104
                        }
 
105
                }
 
106
                
 
107
                Identifier ()
 
108
                {
 
109
                        this.name = string.Empty;
 
110
                }
 
111
                
 
112
                protected Identifier (string name, TextLocation location)
 
113
                {
 
114
                        if (name == null)
 
115
                                throw new ArgumentNullException("name");
 
116
                        this.Name = name;
 
117
                        this.startLocation = location;
 
118
                }
 
119
 
 
120
                public static Identifier Create (string name)
 
121
                {
 
122
                        return Create (name, TextLocation.Empty);
 
123
                }
 
124
 
 
125
                public static Identifier Create (string name, TextLocation location)
 
126
                {
 
127
                        if (string.IsNullOrEmpty(name))
 
128
                                return Identifier.Null;
 
129
                        if (name[0] == '@')
 
130
                                return new Identifier (name.Substring (1), new TextLocation (location.Line, location.Column + 1)) { IsVerbatim = true };
 
131
                        else
 
132
                                return new Identifier (name, location);
 
133
                }
 
134
                
 
135
                public static Identifier Create (string name, TextLocation location, bool isVerbatim)
 
136
                {
 
137
                        if (string.IsNullOrEmpty (name))
 
138
                                return Identifier.Null;
 
139
                        
 
140
                        if (isVerbatim)
 
141
                                return new Identifier (name, location) { IsVerbatim = true };
 
142
                        return new Identifier (name, location);
 
143
                }
 
144
                
 
145
                public override void AcceptVisitor (IAstVisitor visitor)
 
146
                {
 
147
                        visitor.VisitIdentifier (this);
 
148
                }
 
149
                
 
150
                public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
151
                {
 
152
                        return visitor.VisitIdentifier (this);
 
153
                }
 
154
                
 
155
                public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
156
                {
 
157
                        return visitor.VisitIdentifier (this, data);
 
158
                }
 
159
                
 
160
                protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
161
                {
 
162
                        Identifier o = other as Identifier;
 
163
                        return o != null && !o.IsNull && MatchString(this.Name, o.Name);
 
164
                }
 
165
        }
 
166
}
 
 
b'\\ No newline at end of file'