4
// Lluis Sanchez Gual <lluis@novell.com>
6
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
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:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
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
30
using MonoDevelop.Core;
32
namespace MonoDevelop.Projects.Parser
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.
45
class ClassWrapper: IClass
48
CodeCompletionDatabase db;
54
public ClassWrapper (CodeCompletionDatabase db, ClassEntry entry)
58
this.name = entry.Name;
59
this.ns = entry.NamespaceRef.FullName;
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.
70
wrapped = db.ReadClass (entry);
71
entry.AttachClass (wrapped);
72
} catch (Exception ex) {
73
LoggingService.LogError (ex.ToString ());
80
public string FullyQualifiedName {
82
if (ns != null && ns.Length > 0)
83
return string.Concat (ns, ".", name);
93
public string Namespace {
97
public ClassType ClassType {
98
get { return entry.ClassType; }
101
public ICompilationUnit CompilationUnit {
103
if (HasContent (ContentFlags.HasCompilationUnit))
104
return Wrapped.CompilationUnit;
110
public virtual CombineEntry SourceProject {
112
if (db is ProjectCodeCompletionDatabase)
113
return ((ProjectCodeCompletionDatabase)db).Project;
119
public IRegion Region {
121
if (HasContent (ContentFlags.HasRegion))
122
return Wrapped.Region;
128
public IRegion BodyRegion {
130
if (HasContent (ContentFlags.HasBodyRegion))
131
return Wrapped.BodyRegion;
137
// For classes composed by several files, returns all parts of the class
138
public IClass[] Parts {
140
if (HasContent (ContentFlags.HasParts))
141
return Wrapped.Parts;
143
return new IClass [0];
147
public GenericParameterList GenericParameters {
149
if (HasContent (ContentFlags.HasGenericParams))
150
return Wrapped.GenericParameters;
156
public ReturnTypeList BaseTypes {
158
if (HasContent (ContentFlags.HasBaseTypes))
159
return Wrapped.BaseTypes;
161
return new ReturnTypeList ();
165
public ClassCollection InnerClasses {
167
if (HasContent (ContentFlags.HasInnerClasses))
168
return Wrapped.InnerClasses;
170
return new ClassCollection ();
174
public FieldCollection Fields {
176
if (HasContent (ContentFlags.HasFields))
177
return Wrapped.Fields;
179
return new FieldCollection (this);
183
public PropertyCollection Properties {
185
if (HasContent (ContentFlags.HasProperties))
186
return Wrapped.Properties;
188
return new PropertyCollection (this);
192
public IndexerCollection Indexer {
194
if (HasContent (ContentFlags.HasIndexers))
195
return Wrapped.Indexer;
197
return new IndexerCollection (this);
201
public MethodCollection Methods {
203
if (HasContent (ContentFlags.HasMethods))
204
return Wrapped.Methods;
206
return new MethodCollection (this);
210
public EventCollection Events {
212
if (HasContent (ContentFlags.HasEvents))
213
return Wrapped.Events;
215
return new EventCollection (this);
219
public object DeclaredIn {
220
get { return null; } // Inner classes are never wrapped
223
public AttributeSectionCollection Attributes {
225
if (HasContent (ContentFlags.HasAttributes))
226
return Wrapped.Attributes;
228
return new AttributeSectionCollection ();
232
public string Documentation {
234
if (HasContent (ContentFlags.HasDocumentation))
235
return Wrapped.Documentation;
241
bool HasContent (ContentFlags cf)
243
return (entry.ContentFlags & cf) != 0 && Wrapped != null;
246
public ModifierEnum Modifiers {
247
get { return entry.Modifiers; }
250
public bool IsAbstract {
252
return (Modifiers & ModifierEnum.Abstract) == ModifierEnum.Abstract;
256
public bool IsSealed {
258
return (Modifiers & ModifierEnum.Sealed) == ModifierEnum.Sealed;
262
public bool IsStatic {
264
return (Modifiers & ModifierEnum.Static) == ModifierEnum.Static;
268
public bool IsVirtual {
270
return (Modifiers & ModifierEnum.Virtual) == ModifierEnum.Virtual;
274
public bool IsPublic {
276
return (Modifiers & ModifierEnum.Public) == ModifierEnum.Public;
280
public bool IsProtected {
282
return (Modifiers & ModifierEnum.Protected) == ModifierEnum.Protected;
286
public bool IsPrivate {
288
return (Modifiers & ModifierEnum.Private) == ModifierEnum.Private;
292
public bool IsInternal {
294
return (Modifiers & ModifierEnum.Internal) == ModifierEnum.Internal;
298
public bool IsProtectedAndInternal {
300
return (Modifiers & (ModifierEnum.Internal | ModifierEnum.Protected)) == (ModifierEnum.Internal | ModifierEnum.Protected);
304
public bool IsProtectedOrInternal {
306
return (Modifiers & ModifierEnum.ProtectedOrInternal) == ModifierEnum.ProtectedOrInternal;
310
public bool IsLiteral {
312
return (Modifiers & ModifierEnum.Const) == ModifierEnum.Const;
316
public bool IsReadonly {
318
return (Modifiers & ModifierEnum.Readonly) == ModifierEnum.Readonly;
322
public bool IsOverride {
324
return (Modifiers & ModifierEnum.Override) == ModifierEnum.Override;
328
public bool IsFinal {
330
return (Modifiers & ModifierEnum.Final) == ModifierEnum.Final;
334
public bool IsSpecialName {
336
return (Modifiers & ModifierEnum.SpecialName) == ModifierEnum.SpecialName;
342
return (Modifiers & ModifierEnum.New) == ModifierEnum.New;
346
public int CompareTo (object ob)
349
return Wrapped.CompareTo (ob);