/NRefactory/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs

http://github.com/icsharpcode/ILSpy · C# · 78 lines · 57 code · 11 blank · 10 comment · 8 complexity · ac7b8305472d6c50779f4c4a805eb3af 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. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using ICSharpCode.NRefactory.PatternMatching;
  8. namespace ICSharpCode.NRefactory.VB.Ast
  9. {
  10. /// <summary>
  11. /// Namespace Name
  12. /// Members
  13. /// End Namespace
  14. /// </summary>
  15. public class NamespaceDeclaration : AstNode
  16. {
  17. public static readonly Role<AstNode> MemberRole = CompilationUnit.MemberRole;
  18. public string Name {
  19. get {
  20. StringBuilder builder = new StringBuilder();
  21. foreach (Identifier identifier in GetChildrenByRole (Roles.Identifier)) {
  22. if (builder.Length > 0)
  23. builder.Append ('.');
  24. builder.Append (identifier.Name);
  25. }
  26. return builder.ToString ();
  27. }
  28. set {
  29. GetChildrenByRole(Roles.Identifier).ReplaceWith(value.Split('.').Select(ident => new Identifier (ident, TextLocation.Empty)));
  30. }
  31. }
  32. public AstNodeCollection<Identifier> Identifiers {
  33. get { return GetChildrenByRole (Roles.Identifier); }
  34. }
  35. /// <summary>
  36. /// Gets the full namespace name (including any parent namespaces)
  37. /// </summary>
  38. public string FullName {
  39. get {
  40. NamespaceDeclaration parentNamespace = Parent as NamespaceDeclaration;
  41. if (parentNamespace != null)
  42. return BuildQualifiedName (parentNamespace.FullName, Name);
  43. return Name;
  44. }
  45. }
  46. public AstNodeCollection<AstNode> Members {
  47. get { return GetChildrenByRole(MemberRole); }
  48. }
  49. public static string BuildQualifiedName (string name1, string name2)
  50. {
  51. if (string.IsNullOrEmpty (name1))
  52. return name2;
  53. if (string.IsNullOrEmpty (name2))
  54. return name1;
  55. return name1 + "." + name2;
  56. }
  57. public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
  58. {
  59. return visitor.VisitNamespaceDeclaration(this, data);
  60. }
  61. protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
  62. {
  63. NamespaceDeclaration o = other as NamespaceDeclaration;
  64. return o != null && MatchString(this.Name, o.Name) && this.Members.DoMatch(o.Members, match);
  65. }
  66. }
  67. };