PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB/Ast/Identifier.cs

http://github.com/icsharpcode/ILSpy
C# | 96 lines | 76 code | 15 blank | 5 comment | 10 complexity | 614ade0f9ec205f633bf07c6fed28b17 MD5 | raw file
 1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 2// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
 3
 4using System;
 5
 6namespace ICSharpCode.NRefactory.VB.Ast
 7{
 8	/// <summary>
 9	/// Represents an identifier in VB.
10	/// </summary>
11	public class Identifier : AstNode
12	{
13		public static readonly new Identifier Null = new NullIdentifier ();
14		class NullIdentifier : Identifier
15		{
16			public override bool IsNull {
17				get {
18					return true;
19				}
20			}
21			
22			public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
23			{
24				return default (S);
25			}
26			
27			protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
28			{
29				return other == null || other.IsNull;
30			}
31		}
32		
33		string name;
34		
35		public string Name {
36			get { return name; }
37			set {
38				if (value == null)
39					throw new ArgumentNullException("value");
40				name = value;
41			}
42		}
43		
44		public TypeCode TypeCharacter { get; set; }
45		
46		TextLocation startLocation;
47		public override TextLocation StartLocation {
48			get {
49				return startLocation;
50			}
51		}
52		
53		public override TextLocation EndLocation {
54			get {
55				return new TextLocation (StartLocation.Line, StartLocation.Column + Name.Length);
56			}
57		}
58		
59		private Identifier()
60		{
61			this.name = string.Empty;
62		}
63		
64		public Identifier (string name, TextLocation location)
65		{
66			if (name == null)
67				throw new ArgumentNullException("name");
68			this.Name = name;
69			this.startLocation = location;
70		}
71		
72		public static implicit operator Identifier(string name)
73		{
74			return new Identifier(name, TextLocation.Empty);
75		}
76		
77		protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
78		{
79			var node = other as Identifier;
80			return node != null
81				&& MatchString(node.name, name)
82				&& node.TypeCharacter == TypeCharacter;
83		}
84		
85		public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
86		{
87			return visitor.VisitIdentifier(this, data);
88		}
89		
90		public override string ToString()
91		{
92			return string.Format("{0}",
93			                     name);
94		}
95	}
96}