5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
namespace MonoDevelop.Projects.Dom
33
/// DOM output visitor. Used for debug purposes to get a string out of a monodevelop dom object.
35
public class DomOutputVisitor : AbstractDomVisitor<object, object>
37
StringBuilder output = new StringBuilder ();
39
public string Output {
41
return this.output.ToString ();
49
return new string ('\t', indentLevel);
53
public static string GetOutput (IMember member)
55
var visitor = new DomOutputVisitor ();
56
member.AcceptVisitor (visitor, null);
57
return visitor.Output;
61
public void OututReturnType (IReturnType returnType)
63
if (returnType == null) {
64
output.Append ("<null>");
67
output.Append (returnType.ToInvariantString ());
70
public override object Visit (IAttribute attribute, object data)
72
output.Append (CurIndent);
74
output.Append (attribute.Name);
75
output.AppendLine ("]");
80
public void VisitAttributes (IMember member)
82
foreach (var attr in member.Attributes)
83
attr.AcceptVisitor (this, null);
86
public override object Visit (IEvent evt, object data)
88
VisitAttributes (evt);
89
output.Append (CurIndent);
90
output.Append (evt.Modifiers.ToString ());
91
output.Append (" event ");
92
OututReturnType (evt.ReturnType);
94
output.Append (evt.Name);
95
output.AppendLine (";");
99
public override object Visit (IField field, object data)
101
VisitAttributes (field);
102
output.Append (CurIndent);
103
output.Append (field.Modifiers.ToString ());
105
OututReturnType (field.ReturnType);
107
output.Append (field.Name);
108
output.AppendLine (";");
112
public override object Visit (IMethod method, object data)
114
VisitAttributes (method);
115
output.Append (CurIndent);
116
output.Append (method.Modifiers.ToString ());
118
OututReturnType (method.ReturnType);
120
output.Append (method.Name);
121
output.AppendLine (" { }");
125
public override object Visit (IProperty property, object data)
127
VisitAttributes (property);
128
output.Append (CurIndent);
129
output.Append (property.Modifiers.ToString ());
131
OututReturnType (property.ReturnType);
133
output.Append (property.Name);
134
output.Append (" {");
136
output.Append (" get;");
138
output.Append (" set;");
139
output.AppendLine ("}");
143
public override object Visit (IType type, object data)
145
VisitAttributes (type);
146
output.Append (CurIndent);
147
output.Append (type.Modifiers.ToString ());
149
switch (type.ClassType) {
150
case ClassType.Class:
151
output.Append ("class");
153
case ClassType.Struct:
154
output.Append ("struct");
156
case ClassType.Delegate:
157
output.Append ("delegate");
160
output.Append ("enum");
162
case ClassType.Interface:
163
output.Append ("interface");
167
output.Append (type.Name);
168
if (type.BaseTypes.Any ()) {
169
output.Append (" : ");
170
foreach (var baseType in type.BaseTypes) {
171
output.Append (baseType.ToInvariantString ());
175
output.AppendLine (" {");
177
foreach (var member in type.Members)
178
member.AcceptVisitor (this, null);
180
output.Append (CurIndent);
181
output.AppendLine ("}");