7
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using System.Collections;
32
using System.Collections.Generic;
34
using MonoDevelop.Projects;
36
namespace MonoDevelop.Projects.Dom.Serialization
39
internal class NamespaceEntry
41
Hashtable contents = new Hashtable ();
42
NamespaceEntry parent;
48
// This is the case insensitive version of the hashtable.
49
// It is constructed only when needed.
50
[NonSerialized] Hashtable contents_ci;
52
public NamespaceEntry (NamespaceEntry parent, string name)
58
public string FullName {
64
if (string.IsNullOrEmpty (parent.name))
65
return fullName = name;
66
NamespaceEntry p = parent;
67
StringBuilder sb = new StringBuilder (name);
69
sb.Insert (0, ".").Insert (0, p.name);
71
} while (p != null && !string.IsNullOrEmpty (p.name));
73
return fullName = sb.ToString ();;
80
public IEnumerable<ClassEntry> GetAllClasses ()
82
foreach (object ob in contents.Values) {
84
yield return (ClassEntry)ob;
85
else if (ob is NamespaceEntry) {
86
foreach (ClassEntry ce in ((NamespaceEntry)ob).GetAllClasses ())
92
// All methods with the caseSensitive parameter, first check for an
93
// exact match, and if not found, they try with the case insensitive table.
95
public NamespaceEntry GetNamespace (string ns, bool caseSensitive)
97
NamespaceEntry ne = contents[ns] as NamespaceEntry;
98
if (ne != null || caseSensitive) return ne;
100
if (contents_ci == null) BuildCaseInsensitiveTable ();
101
return contents_ci[ns] as NamespaceEntry;
104
public ClassEntry GetClass (string name, int genericArgumentCount, bool caseSensitive)
106
string fullName = ParserDatabase.GetDecoratedName (name, genericArgumentCount);
107
ClassEntry ne = contents[fullName] as ClassEntry;
108
if (ne != null || caseSensitive) return ne;
110
if (contents_ci == null) BuildCaseInsensitiveTable ();
111
return contents_ci[fullName] as ClassEntry;
114
public void Add (NamespaceEntry value)
117
contents [value.name] = value;
118
if (contents_ci != null)
119
contents_ci [value.name] = value;
122
public void Add (ClassEntry value)
124
string name = ParserDatabase.GetDecoratedName (value);
126
contents [name] = value;
127
if (contents_ci != null)
128
contents_ci [name] = value;
131
public void Remove (NamespaceEntry name)
133
contents.Remove (name);
137
public void Remove (ClassEntry entry)
139
contents.Remove (ParserDatabase.GetDecoratedName (entry));
143
public ICollection Contents
145
get { return contents; }
148
public int ContentCount
150
get { return contents.Count; }
155
ArrayList todel = new ArrayList ();
156
foreach (DictionaryEntry en in contents)
158
NamespaceEntry h = en.Value as NamespaceEntry;
161
if (h.ContentCount == 0) todel.Add (en.Key);
168
foreach (string key in todel)
169
contents.Remove (key);
173
void BuildCaseInsensitiveTable ()
175
contents_ci = new Hashtable (StringComparer.CurrentCultureIgnoreCase);
176
foreach (DictionaryEntry en in contents)
177
contents_ci.Add (en.Key, en.Value);