~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.CodeMetrics/MonoDevelop.CodeMetrics/CodeMetricsServices.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// CodeMetricsServices.cs
 
3
//  
 
4
// Author:
 
5
//       nikhil <${AuthorEmail}>
 
6
// 
 
7
// Copyright (c) 2009 nikhil
 
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;
 
28
using System.Collections.Generic;
 
29
using System.Text;
 
30
using Gtk;
 
31
 
 
32
using MonoDevelop.Core;
 
33
 
 
34
using MonoDevelop.Ide.Gui;
 
35
using MonoDevelop.Projects;
 
36
using MonoDevelop.Projects.Dom;
 
37
using MonoDevelop.Projects.Dom.Parser;
 
38
using MonoDevelop.Projects.Dom.Output;
 
39
 
 
40
using Mono.TextEditor;
 
41
 
 
42
using ICSharpCode.NRefactory.Ast;
 
43
using ICSharpCode.NRefactory.AstBuilder;
 
44
 
 
45
namespace MonoDevelop.CodeMetrics
 
46
{
 
47
        public class CodeMetricsService
 
48
        {
 
49
                public static void AddTypes (ProjectProperties projectprop, MetricsContext ctx)
 
50
                {
 
51
                        ProjectDom dom = ProjectDomService.GetProjectDom (projectprop.Project);
 
52
                        foreach (IType ob in dom.Types) {
 
53
                                projectprop.AddInstance(ob);
 
54
                        }
 
55
                }
 
56
                
 
57
                internal static void ProcessInnerTypes(ProjectProperties projprop)
 
58
                {
 
59
                        foreach (var namesp in projprop.Namespaces) {
 
60
                                namesp.Value.ProcessClasses();
 
61
                                projprop.CyclometricComplexity += namesp.Value.CyclometricComplexity;
 
62
                                projprop.LOCReal += namesp.Value.LOCReal;
 
63
                                projprop.LOCComments += namesp.Value.LOCComments;
 
64
                        }
 
65
                        foreach (var cls in projprop.Classes) {
 
66
                                cls.Value.ProcessInnerClasses();
 
67
                                projprop.CyclometricComplexity += cls.Value.CyclometricComplexity;
 
68
                                projprop.LOCReal += cls.Value.LOCReal;
 
69
                                projprop.LOCComments += cls.Value.LOCComments;
 
70
                        }       
 
71
                }
 
72
                
 
73
                public static string GenerateAssemblyMetricText()
 
74
                {
 
75
                        // TODO General stuff about the assembly
 
76
                        return "";
 
77
                }
 
78
                
 
79
                public static string GenerateTypeMetricText(IProperties item)
 
80
                {
 
81
                        if(item is NamespaceProperties){
 
82
                                
 
83
                                return GenerateNamespaceMetricText((NamespaceProperties)item).ToString();
 
84
                                
 
85
                        } else if (item is MethodProperties) {
 
86
                                
 
87
                                return GenerateMethodMetricText((MethodProperties)item).ToString();
 
88
                                
 
89
                        } else if (item is ClassProperties) {
 
90
                                
 
91
                                return GenerateClassMetricText((ClassProperties)item).ToString();
 
92
                                
 
93
                        } else if (item is InterfaceProperties) {
 
94
                                
 
95
                                return GenerateInterfaceMetricText((InterfaceProperties)item).ToString();
 
96
                                
 
97
                        } else if (item is EnumProperties) {
 
98
                                
 
99
                                return GenerateEnumMetricText((EnumProperties)item).ToString();
 
100
                                
 
101
                        } else if (item is DelegateProperties) {
 
102
                                
 
103
                                return GenerateDelegateMetricText((DelegateProperties)item).ToString();
 
104
                                
 
105
                        } else if (item is StructProperties) {
 
106
                                
 
107
                                return GenerateStructMetricText((StructProperties)item).ToString();
 
108
                        
 
109
                        }
 
110
                        
 
111
                        return "NULL";
 
112
                }
 
113
                
 
114
                private static StringBuilder GenerateNamespaceMetricText(NamespaceProperties item)
 
115
                {
 
116
                        StringBuilder results = new StringBuilder();
 
117
                        results.Append(GettextCatalog.GetString("\nName : ") + item.FullName);
 
118
                        results.Append(GettextCatalog.GetString("\nTotal number of classes : ") + item.Classes.Count);
 
119
                        results.Append(GettextCatalog.GetString("\nTotal number of methods : ") + item.MethodCount);
 
120
                        results.Append(GettextCatalog.GetString("\nTotal number of fields : ") + item.FieldCount);
 
121
                        results.Append(GettextCatalog.GetString("\nClass Coupling : ") + item.ClassCoupling);
 
122
                        return results;
 
123
                }
 
124
                
 
125
                private static StringBuilder GenerateClassMetricText(ClassProperties item)
 
126
                {
 
127
                        StringBuilder results = new StringBuilder();
 
128
                        results.Append(GettextCatalog.GetString("\nName : ") + item.FullName);
 
129
                        results.Append(GettextCatalog.GetString("\nDepth of inheritance : ") + item.DepthOfInheritance);
 
130
                        results.Append(GettextCatalog.GetString("\nNumber of children : ") + item.FanOut);
 
131
                        results.Append(GettextCatalog.GetString("\nAfferent Coupling : ") + item.AfferentCoupling);
 
132
                        results.Append(GettextCatalog.GetString("\nEfferent Coupling : ") + item.EfferentCoupling);
 
133
                        results.Append(GettextCatalog.GetString("\nData abstraction coupling : ") + item.DataAbstractionCoupling);
 
134
                        results.Append(GettextCatalog.GetString("\nConstructors : ") + item.ConstructorCount);
 
135
                        results.Append(GettextCatalog.GetString("\nDelegates : ") + item.DelegateCount);
 
136
                        results.Append(GettextCatalog.GetString("\nEvents : ") + item.EventCount);
 
137
                        results.Append(GettextCatalog.GetString("\nFields : ") + item.FieldCount);
 
138
                        results.Append(GettextCatalog.GetString("\nInner classes : ") + item.InnerClassCount);
 
139
                        results.Append(GettextCatalog.GetString("\nStructs : ") + item.StructCount);
 
140
                        results.Append(GettextCatalog.GetString("\nMethods : ") + item.MethodCount);
 
141
                        results.Append(GettextCatalog.GetString("\nProperties : ") + item.Class.PropertyCount);
 
142
                        results.Append(GettextCatalog.GetString("\nLack of cohesion of methods : ") + item.LCOM);
 
143
                        results.Append(GettextCatalog.GetString("\nLack of cohesion of methods (Henderson-Sellers) : ") + item.LCOM_HS);
 
144
                        return results;
 
145
                }
 
146
                
 
147
                private static StringBuilder GenerateMethodMetricText(MethodProperties item)
 
148
                {
 
149
                        StringBuilder results = new StringBuilder();
 
150
                        results.Append(GettextCatalog.GetString("\nName : " + item.FullName));
 
151
                        results.Append(GettextCatalog.GetString("\nTotal number of local variables : " + item.NumberOfVariables));
 
152
                        results.Append(GettextCatalog.GetString("\nTotal number of parameters : " + item.ParameterCount));
 
153
                        results.Append(GettextCatalog.GetString("\nAfferent Coupling : " + item.AfferentCoupling));
 
154
                        results.Append(GettextCatalog.GetString("\nEfferent Coupling : " + item.EfferentCoupling));
 
155
                        
 
156
                        return results;
 
157
                }
 
158
                
 
159
                private static StringBuilder GenerateStructMetricText (StructProperties item)
 
160
                {
 
161
                        StringBuilder results = new StringBuilder();
 
162
                        results.Append(GettextCatalog.GetString("\nName : " + item.FullName));
 
163
                        results.Append(GettextCatalog.GetString("\nTotal number of fields : " + item.Struct.FieldCount));
 
164
                        results.Append(GettextCatalog.GetString("\nTotal number of properties : " + item.Struct.PropertyCount));
 
165
                        return results;
 
166
                }
 
167
                
 
168
                private static StringBuilder GenerateInterfaceMetricText (InterfaceProperties item)
 
169
                {
 
170
                        StringBuilder results = new StringBuilder();
 
171
                        results.Append(GettextCatalog.GetString("\nName : " + item.FullName));
 
172
                        results.Append(GettextCatalog.GetString("\nTotal number of properties : " + item.Interface.PropertyCount));
 
173
                        results.Append(GettextCatalog.GetString("\nTotal number of methods : " + item.Interface.MethodCount));
 
174
                        return results;
 
175
                }
 
176
                
 
177
                private static StringBuilder GenerateDelegateMetricText (DelegateProperties item)
 
178
                {
 
179
                        StringBuilder results = new StringBuilder();
 
180
                        results.Append(GettextCatalog.GetString("\nName : " + item.FullName));
 
181
                        results.Append(GettextCatalog.GetString("\nReturn Type : " + item.Delegate.ReturnType));
 
182
                        results.Append(GettextCatalog.GetString("\nTotal number of parameters : " + item.Delegate.Parameters.Count));
 
183
                        return results;
 
184
                }
 
185
                
 
186
                private static StringBuilder GenerateEnumMetricText (EnumProperties item)
 
187
                {
 
188
                        StringBuilder results = new StringBuilder();
 
189
                        results.Append(GettextCatalog.GetString("\nName : " + item.FullName));
 
190
                        results.Append(GettextCatalog.GetString("\nTotal number of inner types : " + item.Enum.InnerTypeCount));
 
191
                        return results;
 
192
                }
 
193
        }
 
194
}