5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2009 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
29
namespace ICSharpCode.NRefactory.CSharp
31
public class Identifier : AstNode
33
public new static readonly Identifier Null = new NullIdentifier ();
34
sealed class NullIdentifier : Identifier
36
public override bool IsNull {
42
public override void AcceptVisitor (IAstVisitor visitor)
46
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
51
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
56
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
58
return other == null || other.IsNull;
62
public override NodeType NodeType {
64
return NodeType.Token;
70
get { return this.name; }
73
throw new ArgumentNullException("value");
79
TextLocation startLocation;
80
public override TextLocation StartLocation {
86
const uint verbatimBit = 1u << AstNodeFlagsUsedBits;
88
public bool IsVerbatim {
90
return (flags & verbatimBit) != 0;
97
flags &= ~verbatimBit;
101
public override TextLocation EndLocation {
103
return new TextLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length + (IsVerbatim ? 1 : 0));
109
this.name = string.Empty;
112
protected Identifier (string name, TextLocation location)
115
throw new ArgumentNullException("name");
117
this.startLocation = location;
120
public static Identifier Create (string name)
122
return Create (name, TextLocation.Empty);
125
public static Identifier Create (string name, TextLocation location)
127
if (string.IsNullOrEmpty(name))
128
return Identifier.Null;
130
return new Identifier (name.Substring (1), new TextLocation (location.Line, location.Column + 1)) { IsVerbatim = true };
132
return new Identifier (name, location);
135
public static Identifier Create (string name, TextLocation location, bool isVerbatim)
137
if (string.IsNullOrEmpty (name))
138
return Identifier.Null;
141
return new Identifier (name, location) { IsVerbatim = true };
142
return new Identifier (name, location);
145
public override void AcceptVisitor (IAstVisitor visitor)
147
visitor.VisitIdentifier (this);
150
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
152
return visitor.VisitIdentifier (this);
155
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
157
return visitor.VisitIdentifier (this, data);
160
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
162
Identifier o = other as Identifier;
163
return o != null && !o.IsNull && MatchString(this.Name, o.Name);
b'\\ No newline at end of file'