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;
33
using MonoDevelop.Projects;
34
using MonoDevelop.Projects.Parser;
36
namespace MonoDevelop.Projects.Parser
39
internal class NamespaceEntry
41
Hashtable contents = new Hashtable ();
42
NamespaceEntry parent;
45
// This is the case insensitive version of the hashtable.
46
// It is constructed only when needed.
47
[NonSerialized] Hashtable contents_ci;
49
public NamespaceEntry (NamespaceEntry parent, string name)
55
public string FullName {
58
string bn = parent.FullName;
60
return string.Concat (bn, ".", name);
69
public IEnumerable<ClassEntry> GetAllClasses ()
71
foreach (object ob in contents.Values) {
73
yield return (ClassEntry)ob;
74
else if (ob is NamespaceEntry) {
75
foreach (ClassEntry ce in ((NamespaceEntry)ob).GetAllClasses ())
81
// All methods with the caseSensitive parameter, first check for an
82
// exact match, and if not found, they try with the case insensitive table.
84
public NamespaceEntry GetNamespace (string ns, bool caseSensitive)
86
NamespaceEntry ne = contents[ns] as NamespaceEntry;
87
if (ne != null || caseSensitive) return ne;
89
if (contents_ci == null) BuildCaseInsensitiveTable ();
90
return contents_ci[ns] as NamespaceEntry;
93
public ClassEntry GetClass (string name, bool caseSensitive)
95
ClassEntry ne = contents[name] as ClassEntry;
96
if (ne != null || caseSensitive) return ne;
98
if (contents_ci == null) BuildCaseInsensitiveTable ();
99
return contents_ci[name] as ClassEntry;
102
public void Add (string name, object value)
104
contents [name] = value;
105
if (contents_ci != null)
106
contents_ci [name] = value;
109
public void Remove (string name)
111
contents.Remove (name);
115
public ICollection Contents
117
get { return contents; }
120
public int ContentCount
122
get { return contents.Count; }
127
ArrayList todel = new ArrayList ();
128
foreach (DictionaryEntry en in contents)
130
NamespaceEntry h = en.Value as NamespaceEntry;
133
if (h.ContentCount == 0) todel.Add (en.Key);
140
foreach (string key in todel)
141
contents.Remove (key);
145
void BuildCaseInsensitiveTable ()
147
contents_ci = new Hashtable (StringComparer.CurrentCultureIgnoreCase);
148
foreach (DictionaryEntry en in contents)
149
contents_ci.Add (en.Key, en.Value);