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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects/MonoDevelop.Projects.Parser/ClassWrapper.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
 
// ClassWrapper.cs
2
 
//
3
 
// Author:
4
 
//   Lluis Sanchez Gual <lluis@novell.com>
5
 
//
6
 
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
7
 
//
8
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
 
// of this software and associated documentation files (the "Software"), to deal
10
 
// in the Software without restriction, including without limitation the rights
11
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 
// copies of the Software, and to permit persons to whom the Software is
13
 
// furnished to do so, subject to the following conditions:
14
 
//
15
 
// The above copyright notice and this permission notice shall be included in
16
 
// all copies or substantial portions of the Software.
17
 
//
18
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 
// THE SOFTWARE.
25
 
//
26
 
//
27
 
 
28
 
 
29
 
using System;
30
 
using MonoDevelop.Core;
31
 
 
32
 
namespace MonoDevelop.Projects.Parser
33
 
{
34
 
        // This IClass implementation gets its information from a ClassEntry.
35
 
        // However, ClassEntry does not have all information of a class, it
36
 
        // only has the name, namespace and some flags. All the other information
37
 
        // (fields, methods, etc) is stored in the pidb file at a position
38
 
        // stored in the ClassEntry. However, in some cases the information
39
 
        // in ClassEntry is enough. For example, for displaying the contents
40
 
        // of the code completion list (which only shows the type name and kind).
41
 
        // For those cases, the code completion database will create a ClassWrapper,
42
 
        // which already has the basic information from ClassEntry and which
43
 
        // will lazily load all the missing information from the pidb file.
44
 
        
45
 
        class ClassWrapper: IClass
46
 
        {
47
 
                ClassEntry entry;
48
 
                CodeCompletionDatabase db;
49
 
                string ns;
50
 
                string name;
51
 
                IClass wrapped;
52
 
                bool loaded;
53
 
                
54
 
                public ClassWrapper (CodeCompletionDatabase db, ClassEntry entry)
55
 
                {
56
 
                        this.entry = entry;
57
 
                        this.db = db;
58
 
                        this.name = entry.Name;
59
 
                        this.ns = entry.NamespaceRef.FullName;
60
 
                }
61
 
                
62
 
                IClass Wrapped {
63
 
                        get {
64
 
                                // If the wrapper is required, it means that the user is trying to get some
65
 
                                // information not available in ClassEntry. In this case, read the full
66
 
                                // clas from the database.
67
 
                                if (!loaded) {
68
 
                                        loaded = true;
69
 
                                        try {
70
 
                                                wrapped = db.ReadClass (entry);
71
 
                                                entry.AttachClass (wrapped);
72
 
                                        } catch (Exception ex) {
73
 
                                                LoggingService.LogError (ex.ToString ());
74
 
                                        }
75
 
                                }
76
 
                                return wrapped;
77
 
                        }
78
 
                }
79
 
                
80
 
                public string FullyQualifiedName {
81
 
                        get {
82
 
                                if (ns != null && ns.Length > 0)
83
 
                                        return string.Concat (ns, ".", name);
84
 
                                else
85
 
                                        return name;
86
 
                        }
87
 
                }
88
 
                
89
 
                public string Name {
90
 
                        get { return name; }
91
 
                }
92
 
                
93
 
                public string Namespace {
94
 
                        get { return ns; }
95
 
                }
96
 
                
97
 
                public ClassType ClassType {
98
 
                        get { return entry.ClassType; }
99
 
                }               
100
 
                
101
 
                public ICompilationUnit CompilationUnit {
102
 
                        get {
103
 
                                if (HasContent (ContentFlags.HasCompilationUnit))
104
 
                                        return Wrapped.CompilationUnit;
105
 
                                else
106
 
                                        return null;
107
 
                        }
108
 
                }
109
 
                
110
 
                public virtual CombineEntry SourceProject {
111
 
                        get {
112
 
                                if (db is ProjectCodeCompletionDatabase)
113
 
                                        return ((ProjectCodeCompletionDatabase)db).Project;
114
 
                                else
115
 
                                        return null;
116
 
                        }
117
 
                }
118
 
                
119
 
                public IRegion Region {
120
 
                        get {
121
 
                                if (HasContent (ContentFlags.HasRegion))
122
 
                                        return Wrapped.Region;
123
 
                                else
124
 
                                        return null;
125
 
                        }
126
 
                }
127
 
                
128
 
                public IRegion BodyRegion {
129
 
                        get {
130
 
                                if (HasContent (ContentFlags.HasBodyRegion))
131
 
                                        return Wrapped.BodyRegion;
132
 
                                else
133
 
                                        return null;
134
 
                        }
135
 
                }
136
 
                
137
 
                // For classes composed by several files, returns all parts of the class
138
 
                public IClass[] Parts {
139
 
                        get {
140
 
                                if (HasContent (ContentFlags.HasParts))
141
 
                                        return Wrapped.Parts;
142
 
                                else
143
 
                                        return new IClass [0];
144
 
                        }
145
 
                }
146
 
                
147
 
                public GenericParameterList GenericParameters {
148
 
                        get {
149
 
                                if (HasContent (ContentFlags.HasGenericParams))
150
 
                                        return Wrapped.GenericParameters;
151
 
                                else
152
 
                                        return null;
153
 
                        }
154
 
                }
155
 
                
156
 
                public ReturnTypeList BaseTypes {
157
 
                        get {
158
 
                                if (HasContent (ContentFlags.HasBaseTypes))
159
 
                                        return Wrapped.BaseTypes;
160
 
                                else
161
 
                                        return new ReturnTypeList ();
162
 
                        }
163
 
                }
164
 
                
165
 
                public ClassCollection InnerClasses {
166
 
                        get {
167
 
                                if (HasContent (ContentFlags.HasInnerClasses))
168
 
                                        return Wrapped.InnerClasses;
169
 
                                else
170
 
                                        return new ClassCollection ();
171
 
                        }
172
 
                }
173
 
 
174
 
                public FieldCollection Fields {
175
 
                        get {
176
 
                                if (HasContent (ContentFlags.HasFields))
177
 
                                        return Wrapped.Fields;
178
 
                                else
179
 
                                        return new FieldCollection (this);
180
 
                        }
181
 
                }
182
 
 
183
 
                public PropertyCollection Properties {
184
 
                        get {
185
 
                                if (HasContent (ContentFlags.HasProperties))
186
 
                                        return Wrapped.Properties;
187
 
                                else
188
 
                                        return new PropertyCollection (this);
189
 
                        }
190
 
                }
191
 
 
192
 
                public IndexerCollection Indexer {
193
 
                        get {
194
 
                                if (HasContent (ContentFlags.HasIndexers))
195
 
                                        return Wrapped.Indexer;
196
 
                                else
197
 
                                        return new IndexerCollection (this);
198
 
                        }
199
 
                }
200
 
 
201
 
                public MethodCollection Methods {
202
 
                        get {
203
 
                                if (HasContent (ContentFlags.HasMethods))
204
 
                                        return Wrapped.Methods;
205
 
                                else
206
 
                                        return new MethodCollection (this);
207
 
                        }
208
 
                }
209
 
 
210
 
                public EventCollection Events {
211
 
                        get {
212
 
                                if (HasContent (ContentFlags.HasEvents))
213
 
                                        return Wrapped.Events;
214
 
                                else
215
 
                                        return new EventCollection (this);
216
 
                        }
217
 
                }
218
 
 
219
 
                public object DeclaredIn {
220
 
                        get { return null; } // Inner classes are never wrapped
221
 
                }
222
 
                
223
 
                public AttributeSectionCollection Attributes {
224
 
                        get {
225
 
                                if (HasContent (ContentFlags.HasAttributes))
226
 
                                        return Wrapped.Attributes;
227
 
                                else
228
 
                                        return new AttributeSectionCollection ();
229
 
                        }
230
 
                }
231
 
 
232
 
                public string Documentation {
233
 
                        get {
234
 
                                if (HasContent (ContentFlags.HasDocumentation))
235
 
                                        return Wrapped.Documentation;
236
 
                                else
237
 
                                        return string.Empty;
238
 
                        }
239
 
                }
240
 
                
241
 
                bool HasContent (ContentFlags cf)
242
 
                {
243
 
                        return (entry.ContentFlags & cf) != 0 && Wrapped != null;
244
 
                }
245
 
                
246
 
                public ModifierEnum Modifiers {
247
 
                        get { return entry.Modifiers; }
248
 
                }
249
 
                
250
 
                public bool IsAbstract {
251
 
                        get {
252
 
                                return (Modifiers & ModifierEnum.Abstract) == ModifierEnum.Abstract;
253
 
                        }
254
 
                }
255
 
 
256
 
                public bool IsSealed {
257
 
                        get {
258
 
                                return (Modifiers & ModifierEnum.Sealed) == ModifierEnum.Sealed;
259
 
                        }
260
 
                }
261
 
 
262
 
                public bool IsStatic {
263
 
                        get {
264
 
                                return (Modifiers & ModifierEnum.Static) == ModifierEnum.Static;
265
 
                        }
266
 
                }
267
 
 
268
 
                public bool IsVirtual {
269
 
                        get {
270
 
                                return (Modifiers & ModifierEnum.Virtual) == ModifierEnum.Virtual;
271
 
                        }
272
 
                }
273
 
 
274
 
                public bool IsPublic {
275
 
                        get {
276
 
                                return (Modifiers & ModifierEnum.Public) == ModifierEnum.Public;
277
 
                        }
278
 
                }
279
 
 
280
 
                public bool IsProtected {
281
 
                        get {
282
 
                                return (Modifiers & ModifierEnum.Protected) == ModifierEnum.Protected;
283
 
                        }
284
 
                }
285
 
 
286
 
                public bool IsPrivate {
287
 
                        get {
288
 
                                return (Modifiers & ModifierEnum.Private) == ModifierEnum.Private;
289
 
                        }
290
 
                }
291
 
 
292
 
                public bool IsInternal {
293
 
                        get {
294
 
                                return (Modifiers & ModifierEnum.Internal) == ModifierEnum.Internal;
295
 
                        }
296
 
                }
297
 
 
298
 
                public bool IsProtectedAndInternal {
299
 
                        get {
300
 
                                return (Modifiers & (ModifierEnum.Internal | ModifierEnum.Protected)) == (ModifierEnum.Internal | ModifierEnum.Protected);
301
 
                        }
302
 
                }
303
 
 
304
 
                public bool IsProtectedOrInternal {
305
 
                        get {
306
 
                                return (Modifiers & ModifierEnum.ProtectedOrInternal) == ModifierEnum.ProtectedOrInternal;
307
 
                        }
308
 
                }
309
 
 
310
 
                public bool IsLiteral {
311
 
                        get {
312
 
                                return (Modifiers & ModifierEnum.Const) == ModifierEnum.Const;
313
 
                        }
314
 
                }
315
 
 
316
 
                public bool IsReadonly {
317
 
                        get {
318
 
                                return (Modifiers & ModifierEnum.Readonly) == ModifierEnum.Readonly;
319
 
                        }
320
 
                }
321
 
 
322
 
                public bool IsOverride {
323
 
                        get {
324
 
                                return (Modifiers & ModifierEnum.Override) == ModifierEnum.Override;
325
 
                        }
326
 
                }
327
 
 
328
 
                public bool IsFinal {
329
 
                        get {
330
 
                                return (Modifiers & ModifierEnum.Final) == ModifierEnum.Final;
331
 
                        }
332
 
                }
333
 
 
334
 
                public bool IsSpecialName {
335
 
                        get {
336
 
                                return (Modifiers & ModifierEnum.SpecialName) == ModifierEnum.SpecialName;
337
 
                        }
338
 
                }
339
 
 
340
 
                public bool IsNew {
341
 
                        get {
342
 
                                return (Modifiers & ModifierEnum.New) == ModifierEnum.New;
343
 
                        }
344
 
                }
345
 
                
346
 
                public int CompareTo (object ob)
347
 
                {
348
 
                        if (Wrapped != null)
349
 
                                return Wrapped.CompareTo (ob);
350
 
                        else
351
 
                                return 1;
352
 
                }
353
 
        }
354
 
}