/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. using System;
  4. namespace ICSharpCode.NRefactory.VB.Ast
  5. {
  6. /// <summary>
  7. /// Represents an identifier in VB.
  8. /// </summary>
  9. public class Identifier : AstNode
  10. {
  11. public static readonly new Identifier Null = new NullIdentifier ();
  12. class NullIdentifier : Identifier
  13. {
  14. public override bool IsNull {
  15. get {
  16. return true;
  17. }
  18. }
  19. public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
  20. {
  21. return default (S);
  22. }
  23. protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
  24. {
  25. return other == null || other.IsNull;
  26. }
  27. }
  28. string name;
  29. public string Name {
  30. get { return name; }
  31. set {
  32. if (value == null)
  33. throw new ArgumentNullException("value");
  34. name = value;
  35. }
  36. }
  37. public TypeCode TypeCharacter { get; set; }
  38. TextLocation startLocation;
  39. public override TextLocation StartLocation {
  40. get {
  41. return startLocation;
  42. }
  43. }
  44. public override TextLocation EndLocation {
  45. get {
  46. return new TextLocation (StartLocation.Line, StartLocation.Column + Name.Length);
  47. }
  48. }
  49. private Identifier()
  50. {
  51. this.name = string.Empty;
  52. }
  53. public Identifier (string name, TextLocation location)
  54. {
  55. if (name == null)
  56. throw new ArgumentNullException("name");
  57. this.Name = name;
  58. this.startLocation = location;
  59. }
  60. public static implicit operator Identifier(string name)
  61. {
  62. return new Identifier(name, TextLocation.Empty);
  63. }
  64. protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
  65. {
  66. var node = other as Identifier;
  67. return node != null
  68. && MatchString(node.name, name)
  69. && node.TypeCharacter == TypeCharacter;
  70. }
  71. public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
  72. {
  73. return visitor.VisitIdentifier(this, data);
  74. }
  75. public override string ToString()
  76. {
  77. return string.Format("{0}",
  78. name);
  79. }
  80. }
  81. }