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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects/MonoDevelop.Projects.Dom.Output/NetAmbience.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
// NetAmbience.cs
 
3
//
 
4
// Author:
 
5
//   Mike Krüger <mkrueger@novell.com>
 
6
//
 
7
// Copyright (C) 2008 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
using System;
 
30
using System.Linq;
 
31
using System.Text;
 
32
 
 
33
namespace MonoDevelop.Projects.Dom.Output
 
34
{
 
35
        public class NetAmbience : Ambience, IDomVisitor<OutputSettings, string>
 
36
        {
 
37
                protected override IDomVisitor<OutputSettings, string> OutputVisitor {
 
38
                        get {
 
39
                                return this;
 
40
                        }
 
41
                }
 
42
                
 
43
                public NetAmbience () : base ("NET", "")
 
44
                {
 
45
                        classTypes[ClassType.Class]     = "Class";
 
46
                        classTypes[ClassType.Enum]      = "Enumeration";
 
47
                        classTypes[ClassType.Interface] = "Interface";
 
48
                        classTypes[ClassType.Struct]    = "Structure";
 
49
                        classTypes[ClassType.Delegate]  = "Delegate";
 
50
                        
 
51
                        parameterModifiers[ParameterModifiers.In]       = "In";
 
52
                        parameterModifiers[ParameterModifiers.Out]      = "Out";
 
53
                        parameterModifiers[ParameterModifiers.Ref]      = "Ref";
 
54
                        parameterModifiers[ParameterModifiers.Params]   = "Params";
 
55
                        parameterModifiers[ParameterModifiers.Optional] = "Optional";
 
56
                        
 
57
                        modifiers[Modifiers.Private]              = "Private";
 
58
                        modifiers[Modifiers.Internal]             = "Internal";
 
59
                        modifiers[Modifiers.Protected]            = "Protected";
 
60
                        modifiers[Modifiers.Public]               = "Public";
 
61
                        modifiers[Modifiers.Abstract]             = "Abstract";
 
62
                        modifiers[Modifiers.Virtual]              = "Virtual";
 
63
                        modifiers[Modifiers.Sealed]               = "Sealed";
 
64
                        modifiers[Modifiers.Static]               = "Static";
 
65
                        modifiers[Modifiers.Override]             = "Override";
 
66
                        modifiers[Modifiers.Readonly]             = "Readonly";
 
67
                        modifiers[Modifiers.Const]                = "Const";
 
68
                        modifiers[Modifiers.Partial]              = "Partial";
 
69
                        modifiers[Modifiers.Extern]               = "Extern";
 
70
                        modifiers[Modifiers.Volatile]             = "Volatile";
 
71
                        modifiers[Modifiers.Unsafe]               = "Unsafe";
 
72
                        modifiers[Modifiers.Overloads]            = "Overloads";
 
73
                        modifiers[Modifiers.WithEvents]           = "WithEvents";
 
74
                        modifiers[Modifiers.Default]              = "Default";
 
75
                        modifiers[Modifiers.Fixed]                = "Fixed";
 
76
                        modifiers[Modifiers.ProtectedAndInternal] = "Protected Internal";
 
77
                        modifiers[Modifiers.ProtectedOrInternal]  = "Internal Protected";
 
78
                }
 
79
                
 
80
                public override string SingleLineComment (string text)
 
81
                {
 
82
                        return "// " + text;
 
83
                }
 
84
 
 
85
                public override string GetString (string nameSpace, OutputSettings settings)
 
86
                {
 
87
                        StringBuilder result = new StringBuilder ();
 
88
                        result.Append (settings.EmitKeyword ("Namespace"));
 
89
                        result.Append (Format (nameSpace));
 
90
                        return result.ToString ();
 
91
                }
 
92
                
 
93
                public string Visit (ICompilationUnit unit, OutputSettings settings)
 
94
                {
 
95
                        return "NOT IMPLEMENTED";
 
96
                }
 
97
                
 
98
                public string Visit (IUsing u, OutputSettings settings)
 
99
                {
 
100
                        return "NOT IMPLEMENTED";
 
101
                }
 
102
                
 
103
                public string Visit (IProperty property, OutputSettings settings)
 
104
                {
 
105
                        StringBuilder result = new StringBuilder ();
 
106
                        result.Append (settings.EmitModifiers (base.GetString (property.Modifiers)));
 
107
                        result.Append (settings.EmitKeyword ("Property"));
 
108
                        
 
109
                        if (settings.UseFullName) {
 
110
                                result.Append (Format (property.FullName));
 
111
                        } else {
 
112
                                result.Append (Format (property.Name));
 
113
                        }
 
114
                        
 
115
                        if (settings.IncludeParameters && property.Parameters.Count > 0) {
 
116
                                result.Append (settings.Markup ("("));
 
117
                                bool first = true;
 
118
                                foreach (IParameter parameter in property.Parameters) {
 
119
                                        if (!first)
 
120
                                                result.Append (settings.Markup (", "));
 
121
                                        result.Append (GetString (parameter, settings));
 
122
                                        first = false;
 
123
                                }
 
124
                                result.Append (settings.Markup (")"));
 
125
                        }
 
126
                        if (settings.IncludeReturnType) {
 
127
                                result.Append (settings.Markup (" : "));
 
128
                                result.Append (GetString (property.ReturnType, settings));
 
129
                        }
 
130
                        return result.ToString ();
 
131
                }
 
132
                
 
133
                public string Visit (IField field, OutputSettings settings)
 
134
                {
 
135
                        StringBuilder result = new StringBuilder ();
 
136
                        
 
137
                        result.Append (settings.EmitModifiers (base.GetString (field.Modifiers)));
 
138
                        result.Append (settings.EmitKeyword ("Field"));
 
139
                        
 
140
                        if (settings.UseFullName) {
 
141
                                result.Append (Format (field.FullName));
 
142
                        } else {
 
143
                                result.Append (Format (field.Name));
 
144
                        }
 
145
                        
 
146
                        if (settings.IncludeReturnType && !field.IsLiteral) {
 
147
                                result.Append (settings.Markup (" : "));
 
148
                                result.Append (GetString (field.ReturnType, settings));
 
149
                        }
 
150
                        return result.ToString ();
 
151
                }
 
152
                
 
153
                public string Visit (IReturnType returnType, OutputSettings settings)
 
154
                {
 
155
                        return Format (settings.UseFullName ? returnType.FullName : returnType.Name);
 
156
                }
 
157
                
 
158
                public string Visit (IMethod method, OutputSettings settings)
 
159
                {
 
160
                        StringBuilder result = new StringBuilder ();
 
161
                        
 
162
                        result.Append (settings.EmitModifiers (base.GetString (method.Modifiers)));
 
163
                        result.Append (settings.EmitKeyword (method.IsConstructor ? "Constructor" : "Method"));
 
164
                        
 
165
                        result.Append (Format (settings.UseFullName ? method.FullName : method.Name));
 
166
                        
 
167
                        if (settings.IncludeParameters) {
 
168
                                result.Append (settings.Markup ("("));
 
169
                                bool first = true;
 
170
                                if (method.Parameters != null) {
 
171
                                        foreach (IParameter parameter in method.Parameters) {
 
172
                                                if (!first)
 
173
                                                        result.Append (settings.Markup (", "));
 
174
                                                result.Append (GetString (parameter, settings));
 
175
                                                first = false;
 
176
                                        }
 
177
                                }
 
178
                                result.Append (settings.Markup (")"));
 
179
                        }
 
180
                                
 
181
                        if (settings.IncludeReturnType && !method.IsConstructor) {
 
182
                                result.Append (settings.Markup (" : "));
 
183
                                result.Append (GetString (method.ReturnType, settings));
 
184
                        }
 
185
                        
 
186
                        return result.ToString ();
 
187
                }
 
188
                
 
189
                public string Visit (IParameter parameter, OutputSettings settings)
 
190
                {
 
191
                        StringBuilder result = new StringBuilder ();
 
192
                        if (settings.IncludeParameterName) {
 
193
                                result.Append (Format (parameter.Name));
 
194
                                if (settings.IncludeReturnType) {
 
195
                                        result.Append (settings.Markup (" : "));
 
196
                                        result.Append (GetString (parameter.ReturnType, settings));
 
197
                                }                               
 
198
                        } else {
 
199
                                result.Append (GetString (parameter.ReturnType, settings));
 
200
                        }
 
201
                        return result.ToString ();
 
202
                }
 
203
                
 
204
                public string Visit (IType type, OutputSettings settings)
 
205
                {
 
206
                        InstantiatedType instantiatedType = type as InstantiatedType;
 
207
                        StringBuilder result = new StringBuilder ();
 
208
                        result.Append (settings.EmitModifiers (base.GetString (type.Modifiers)));
 
209
                        result.Append (settings.EmitKeyword (GetString (type.ClassType)));
 
210
                        
 
211
                        result.Append (Format (type.Name));
 
212
                        
 
213
                        int parameterCount = type.TypeParameters.Count;
 
214
                        if (instantiatedType != null)
 
215
                                parameterCount = instantiatedType.GenericParameters.Count;
 
216
                        if (settings.IncludeGenerics && parameterCount > 0) {
 
217
                                result.Append (settings.Markup ("<"));
 
218
                                for (int i = 0; i < parameterCount; i++) {
 
219
                                        if (i > 0)
 
220
                                                result.Append (settings.Markup (", "));
 
221
                                        if (instantiatedType != null) {
 
222
                                                result.Append (instantiatedType.GenericParameters[i].AcceptVisitor (this, settings));
 
223
                                        } else {
 
224
                                                result.Append (type.TypeParameters[i].Name);
 
225
                                        }
 
226
                                }
 
227
                                result.Append (settings.Markup (">"));
 
228
                        
 
229
                        }
 
230
                        if (settings.IncludeBaseTypes && type.BaseTypes.Any ()) {
 
231
                                result.Append (settings.Markup (" : "));
 
232
                                bool first = true;
 
233
                                foreach (IReturnType baseType in type.BaseTypes) {
 
234
                                        if (baseType.FullName == "System.Object")
 
235
                                                continue;
 
236
                                        if (!first)
 
237
                                                result.Append (settings.Markup (", "));
 
238
                                        first = false;
 
239
                                        result.Append (baseType.AcceptVisitor (this, settings));
 
240
                                }
 
241
                                
 
242
                        }
 
243
                        return result.ToString ();
 
244
                }
 
245
                
 
246
                public string Visit (IAttribute attribute, OutputSettings settings)
 
247
                {
 
248
                        StringBuilder result = new StringBuilder ();
 
249
                        result.Append (settings.Markup ("["));
 
250
                        result.Append (GetString (attribute.AttributeType, settings));
 
251
                        result.Append (settings.Markup ("("));
 
252
                        bool first = true;
 
253
                        if (attribute.PositionalArguments != null) {
 
254
                                foreach (object o in attribute.PositionalArguments) {
 
255
                                        if (!first)
 
256
                                                result.Append (settings.Markup (", "));
 
257
                                        first = false;
 
258
                                        if (o is string) {
 
259
                                                result.Append (settings.Markup ("\""));
 
260
                                                result.Append (o);
 
261
                                                result.Append (settings.Markup ("\""));
 
262
                                        } else if (o is char) {
 
263
                                                result.Append (settings.Markup ("\""));
 
264
                                                result.Append (o);
 
265
                                                result.Append (settings.Markup ("\""));
 
266
                                        } else
 
267
                                                result.Append (o);
 
268
                                }
 
269
                        }
 
270
                        result.Append (settings.Markup (")]"));
 
271
                        return result.ToString ();
 
272
                }
 
273
                
 
274
                public string Visit (Namespace ns, OutputSettings settings)
 
275
                {
 
276
                        return settings.EmitKeyword ("Namespace") + ns.Name;
 
277
                }
 
278
                
 
279
                public string Visit (LocalVariable var, OutputSettings settings)
 
280
                {
 
281
                        return var.Name;
 
282
                }
 
283
                
 
284
                public string Visit (IEvent evt, OutputSettings settings)
 
285
                {
 
286
                        StringBuilder result = new StringBuilder ();
 
287
                        result.Append (settings.EmitModifiers (base.GetString (evt.Modifiers)));
 
288
                        result.Append (settings.EmitKeyword ("Event"));
 
289
                        result.Append (Format (evt.Name));
 
290
                        return result.ToString ();
 
291
                }
 
292
        }
 
293
}