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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Projects.Dom.Serialization/StatsVisitor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// StatsVisitor.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System.Collections.Generic;
 
28
using MonoDevelop.Projects.Dom.Parser;
 
29
 
 
30
namespace MonoDevelop.Projects.Dom
 
31
{
 
32
        class StatsVisitor: IDomVisitor<string,INode>
 
33
        {
 
34
                ProjectDomStats stats;
 
35
                public IReturnType[] SharedTypes;
 
36
                
 
37
                public int ReturnTypeCount;
 
38
                public List<string> Failures = new List<string> ();
 
39
                
 
40
                public StatsVisitor (ProjectDomStats stats)
 
41
                {
 
42
                        this.stats = stats;
 
43
                }
 
44
                
 
45
                public void Reset ()
 
46
                {
 
47
                        Failures.Clear ();
 
48
                        ReturnTypeCount = 0;
 
49
                }
 
50
                
 
51
                public virtual INode Visit (ICompilationUnit unit, string data)
 
52
                {
 
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/");
 
59
                        return null;
 
60
                }
 
61
                
 
62
                public virtual INode Visit (IAttribute attribute, string data)
 
63
                {
 
64
                        data += attribute.Name + "/";
 
65
                        stats.Attributes++;
 
66
                        if (attribute.AttributeType != null)
 
67
                                attribute.AttributeType.AcceptVisitor (this, data + "AttributeType/");
 
68
                        return null;
 
69
                }
 
70
                
 
71
                protected void VisitMember (IMember source, string data)
 
72
                {
 
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");
 
79
                }
 
80
                
 
81
                public virtual INode Visit (IType type, string data)
 
82
                {
 
83
                        data += type.FullName + "/";
 
84
                        VisitMember (type, data);
 
85
 
 
86
                        foreach (ITypeParameter param in type.TypeParameters)
 
87
                                Visit (param, data + "TypeParameters/");
 
88
 
 
89
                        if (type.BaseType != null)
 
90
                                type.BaseType.AcceptVisitor (this, data + "BaseType/");
 
91
 
 
92
                        foreach (IReturnType iface in type.ImplementedInterfaces)
 
93
                                iface.AcceptVisitor (this, data + "ImplementedInterfaces/");
 
94
 
 
95
                        foreach (IMember member in type.Members)
 
96
                                member.AcceptVisitor (this, data + "Members/");
 
97
                        
 
98
                        return null;
 
99
                }
 
100
                
 
101
                public virtual INode Visit (IField field, string data)
 
102
                {
 
103
                        data += field.Name + "/";
 
104
                        stats.Fields++;
 
105
                        VisitMember (field, data);
 
106
                        return null;
 
107
                }
 
108
                
 
109
                public virtual INode Visit (IMethod source, string data)
 
110
                {
 
111
                        data += source.Name + "()/";
 
112
                        stats.Methods++;
 
113
                        VisitMember (source, data);
 
114
                        
 
115
                        foreach (ITypeParameter tp in source.TypeParameters)
 
116
                                Visit (tp, data + "TypeParameters/");
 
117
                        
 
118
                        foreach (IParameter parameter in source.Parameters)
 
119
                                parameter.AcceptVisitor (this, data + "Parameters/");
 
120
                        
 
121
                        return null;
 
122
                }
 
123
                
 
124
                public virtual INode Visit (IProperty source, string data)
 
125
                {
 
126
                        data += source.Name + "/";
 
127
                        stats.Properties++;
 
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/");
 
134
                        
 
135
                        foreach (IParameter parameter in source.Parameters)
 
136
                                parameter.AcceptVisitor (this, data + "Parameters/");
 
137
                        return null;
 
138
                }
 
139
                
 
140
                public virtual INode Visit (IEvent source, string data)
 
141
                {
 
142
                        data += source.Name + "/";
 
143
                        stats.Events++;
 
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/");
 
151
                        return null;
 
152
                }
 
153
                
 
154
                protected virtual IReturnTypePart Visit (IReturnTypePart returnTypePart, string data)
 
155
                {
 
156
                        data += returnTypePart.Name + "/";
 
157
                        stats.ReturnTypeParts++;
 
158
                        foreach (IReturnType ga in returnTypePart.GenericArguments)
 
159
                                ga.AcceptVisitor (this, data + "GenericArguments/");
 
160
                        return null;
 
161
                }
 
162
                
 
163
                public virtual INode Visit (IReturnType type, string data)
 
164
                {
 
165
                        ReturnTypeCount++;
 
166
                        stats.ReturnTypes++;
 
167
                        
 
168
                        foreach (IReturnTypePart p in type.Parts)
 
169
                                Visit (p, data + "Part/");
 
170
                        
 
171
                        foreach (IReturnType rt in SharedTypes) {
 
172
                                if (object.ReferenceEquals (rt, type))
 
173
                                        return null;
 
174
                        }
 
175
 
 
176
                        var sysRt = DomReturnType.GetSharedReturnType (type, true);
 
177
                        if (sysRt != null) {
 
178
                                if (object.ReferenceEquals (sysRt, type))
 
179
                                        return null;
 
180
                        }
 
181
                        
 
182
                        Failures.Add (data + type.ToInvariantString ());
 
183
                        return null;
 
184
                }
 
185
                
 
186
                public virtual INode Visit (IParameter source, string data)
 
187
                {
 
188
                        data += source.Name + "/";
 
189
                        stats.Parameters++;
 
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/");
 
194
                        return null;
 
195
                }
 
196
                
 
197
                public virtual INode Visit (IUsing u, string data)
 
198
                {
 
199
                        data += u.ToString () + "/";
 
200
                        foreach (KeyValuePair<string, IReturnType> val in u.Aliases)
 
201
                                val.Value.AcceptVisitor (this, data + "Aliases/");
 
202
                        return null;
 
203
                }
 
204
                
 
205
                public virtual INode Visit (Namespace namesp, string data)
 
206
                {
 
207
                        data += namesp.Name + "/";
 
208
                        VisitMember (namesp, data);
 
209
                        return null;
 
210
                }
 
211
                
 
212
                public virtual INode Visit (LocalVariable var, string data)
 
213
                {
 
214
                        data += var.Name + "/";
 
215
                        var.ReturnType.AcceptVisitor (this, data);
 
216
                        return null;
 
217
                }
 
218
                
 
219
                protected virtual ITypeParameter Visit (ITypeParameter type, string data)
 
220
                {
 
221
                        data += type.Name;
 
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/");
 
226
                        return null;
 
227
                }       
 
228
        }
 
229
}