PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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