~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects/MonoDevelop.Projects.Parser/NamespaceEntry.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// NamespaceEntry.cs
3
 
//
4
 
// Author:
5
 
//   Lluis Sanchez Gual
6
 
//
7
 
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8
 
//
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:
16
 
// 
17
 
// The above copyright notice and this permission notice shall be
18
 
// included in all copies or substantial portions of the Software.
19
 
// 
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.
27
 
//
28
 
 
29
 
 
30
 
using System;
31
 
using System.Collections;
32
 
using System.Collections.Generic;
33
 
using MonoDevelop.Projects;
34
 
using MonoDevelop.Projects.Parser;
35
 
 
36
 
namespace MonoDevelop.Projects.Parser
37
 
{
38
 
        [Serializable]
39
 
        internal class NamespaceEntry
40
 
        {
41
 
                Hashtable contents = new Hashtable ();
42
 
                NamespaceEntry parent;
43
 
                string name;
44
 
                
45
 
                // This is the case insensitive version of the hashtable.
46
 
                // It is constructed only when needed.
47
 
                [NonSerialized] Hashtable contents_ci;
48
 
                
49
 
                public NamespaceEntry (NamespaceEntry parent, string name)
50
 
                {
51
 
                        this.parent = parent;
52
 
                        this.name = name;
53
 
                }
54
 
                
55
 
                public string FullName {
56
 
                        get {
57
 
                                if (parent != null) {
58
 
                                        string bn = parent.FullName;
59
 
                                        if (bn.Length > 0)
60
 
                                                return string.Concat (bn, ".", name);
61
 
                                        else
62
 
                                                return name;
63
 
                                }
64
 
                                else
65
 
                                        return string.Empty;
66
 
                        }
67
 
                }
68
 
                
69
 
                public IEnumerable<ClassEntry> GetAllClasses ()
70
 
                {
71
 
                        foreach (object ob in contents.Values) {
72
 
                                if (ob is ClassEntry)
73
 
                                        yield return (ClassEntry)ob;
74
 
                                else if (ob is NamespaceEntry) {
75
 
                                        foreach (ClassEntry ce in ((NamespaceEntry)ob).GetAllClasses ())
76
 
                                                yield return ce;
77
 
                                }
78
 
                        }
79
 
                }
80
 
                
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.
83
 
                
84
 
                public NamespaceEntry GetNamespace (string ns, bool caseSensitive)
85
 
                {
86
 
                        NamespaceEntry ne = contents[ns] as NamespaceEntry;
87
 
                        if (ne != null || caseSensitive) return ne;
88
 
                        
89
 
                        if (contents_ci == null) BuildCaseInsensitiveTable ();
90
 
                        return contents_ci[ns] as NamespaceEntry;
91
 
                }
92
 
                
93
 
                public ClassEntry GetClass (string name, bool caseSensitive)
94
 
                {
95
 
                        ClassEntry ne = contents[name] as ClassEntry;
96
 
                        if (ne != null || caseSensitive) return ne;
97
 
                        
98
 
                        if (contents_ci == null) BuildCaseInsensitiveTable ();
99
 
                        return contents_ci[name] as ClassEntry;
100
 
                }
101
 
                
102
 
                public void Add (string name, object value)
103
 
                {
104
 
                        contents [name] = value;
105
 
                        if (contents_ci != null)
106
 
                                contents_ci [name] = value;
107
 
                }
108
 
                
109
 
                public void Remove (string name)
110
 
                {
111
 
                        contents.Remove (name);
112
 
                        contents_ci = null;
113
 
                }
114
 
                
115
 
                public ICollection Contents
116
 
                {
117
 
                        get { return contents; }
118
 
                }
119
 
                
120
 
                public int ContentCount
121
 
                {
122
 
                        get { return contents.Count; }
123
 
                }
124
 
                
125
 
                public void Clean ()
126
 
                {
127
 
                        ArrayList todel = new ArrayList ();
128
 
                        foreach (DictionaryEntry en in contents)
129
 
                        {
130
 
                                NamespaceEntry h = en.Value as NamespaceEntry;
131
 
                                if (h != null) {
132
 
                                        h.Clean ();
133
 
                                        if (h.ContentCount == 0) todel.Add (en.Key);
134
 
                                }
135
 
                        }
136
 
                        
137
 
                        if (todel.Count > 0)
138
 
                        {
139
 
                                contents_ci = null;
140
 
                                foreach (string key in todel)
141
 
                                        contents.Remove (key);
142
 
                        }
143
 
                }
144
 
                
145
 
                void BuildCaseInsensitiveTable ()
146
 
                {
147
 
                        contents_ci = new Hashtable (StringComparer.CurrentCultureIgnoreCase);
148
 
                        foreach (DictionaryEntry en in contents)
149
 
                                contents_ci.Add (en.Key, en.Value);
150
 
                }
151
 
        }
152
 
}