5
// Lluis Sanchez Gual <lluis@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
27
using System.Collections.Generic;
28
using MonoDevelop.Projects.Dom.Parser;
30
namespace MonoDevelop.Projects.Dom
32
class StatsVisitor: IDomVisitor<string,INode>
34
ProjectDomStats stats;
35
public IReturnType[] SharedTypes;
37
public int ReturnTypeCount;
38
public List<string> Failures = new List<string> ();
40
public StatsVisitor (ProjectDomStats stats)
51
public virtual INode Visit (ICompilationUnit unit, string data)
53
foreach (IUsing u in unit.Usings)
54
u.AcceptVisitor (this, data + "Usings/");
55
foreach (IAttribute a in unit.Attributes)
56
a.AcceptVisitor (this, data + "Attributes/");
57
foreach (IType t in unit.Types)
58
t.AcceptVisitor (this, data + "Types/");
62
public virtual INode Visit (IAttribute attribute, string data)
64
data += attribute.Name + "/";
66
if (attribute.AttributeType != null)
67
attribute.AttributeType.AcceptVisitor (this, data + "AttributeType/");
71
protected void VisitMember (IMember source, string data)
73
if (source.ReturnType != null)
74
source.ReturnType.AcceptVisitor (this, data + "RT/");
75
foreach (IReturnType rt in source.ExplicitInterfaces)
76
rt.AcceptVisitor (this, data + "Interfaces/");
77
foreach (IAttribute attr in source.Attributes)
78
attr.AcceptVisitor (this, data + "Attributes");
81
public virtual INode Visit (IType type, string data)
83
data += type.FullName + "/";
84
VisitMember (type, data);
86
foreach (ITypeParameter param in type.TypeParameters)
87
Visit (param, data + "TypeParameters/");
89
if (type.BaseType != null)
90
type.BaseType.AcceptVisitor (this, data + "BaseType/");
92
foreach (IReturnType iface in type.ImplementedInterfaces)
93
iface.AcceptVisitor (this, data + "ImplementedInterfaces/");
95
foreach (IMember member in type.Members)
96
member.AcceptVisitor (this, data + "Members/");
101
public virtual INode Visit (IField field, string data)
103
data += field.Name + "/";
105
VisitMember (field, data);
109
public virtual INode Visit (IMethod source, string data)
111
data += source.Name + "()/";
113
VisitMember (source, data);
115
foreach (ITypeParameter tp in source.TypeParameters)
116
Visit (tp, data + "TypeParameters/");
118
foreach (IParameter parameter in source.Parameters)
119
parameter.AcceptVisitor (this, data + "Parameters/");
124
public virtual INode Visit (IProperty source, string data)
126
data += source.Name + "/";
128
if (source.ReturnType != null)
129
source.ReturnType.AcceptVisitor (this, data + "RT/");
130
foreach (IReturnType rt in source.ExplicitInterfaces)
131
rt.AcceptVisitor (this, data + "ExplicitInterfaces/");
132
foreach (IAttribute attr in source.Attributes)
133
attr.AcceptVisitor (this, data + "Attributes/");
135
foreach (IParameter parameter in source.Parameters)
136
parameter.AcceptVisitor (this, data + "Parameters/");
140
public virtual INode Visit (IEvent source, string data)
142
data += source.Name + "/";
144
VisitMember (source, data);
145
if (source.AddMethod != null)
146
source.AddMethod.AcceptVisitor (this, data + "AddMethod/");
147
if (source.RemoveMethod != null)
148
source.RemoveMethod.AcceptVisitor (this, data + "RemoveMethod/");
149
if (source.RaiseMethod != null)
150
source.RaiseMethod.AcceptVisitor (this, data + "RaiseMethod/");
154
protected virtual IReturnTypePart Visit (IReturnTypePart returnTypePart, string data)
156
data += returnTypePart.Name + "/";
157
stats.ReturnTypeParts++;
158
foreach (IReturnType ga in returnTypePart.GenericArguments)
159
ga.AcceptVisitor (this, data + "GenericArguments/");
163
public virtual INode Visit (IReturnType type, string data)
168
foreach (IReturnTypePart p in type.Parts)
169
Visit (p, data + "Part/");
171
foreach (IReturnType rt in SharedTypes) {
172
if (object.ReferenceEquals (rt, type))
176
var sysRt = DomReturnType.GetSharedReturnType (type, true);
178
if (object.ReferenceEquals (sysRt, type))
182
Failures.Add (data + type.ToInvariantString ());
186
public virtual INode Visit (IParameter source, string data)
188
data += source.Name + "/";
190
if (source.ReturnType != null)
191
source.ReturnType.AcceptVisitor (this, data + "RT/");
192
foreach (IAttribute attr in source.Attributes)
193
attr.AcceptVisitor (this, data + "Attributes/");
197
public virtual INode Visit (IUsing u, string data)
199
data += u.ToString () + "/";
200
foreach (KeyValuePair<string, IReturnType> val in u.Aliases)
201
val.Value.AcceptVisitor (this, data + "Aliases/");
205
public virtual INode Visit (Namespace namesp, string data)
207
data += namesp.Name + "/";
208
VisitMember (namesp, data);
212
public virtual INode Visit (LocalVariable var, string data)
214
data += var.Name + "/";
215
var.ReturnType.AcceptVisitor (this, data);
219
protected virtual ITypeParameter Visit (ITypeParameter type, string data)
222
foreach (IAttribute attr in type.Attributes)
223
attr.AcceptVisitor (this, data + "Attributes/");
224
foreach (IReturnType rt in type.Constraints)
225
rt.AcceptVisitor (this, data + "Constraints/");