From 6af05c8c901f5ebce4c664dfdd22ff88fb774c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Linhart?= Date: Sat, 21 Aug 2010 02:52:21 +0000 Subject: [PATCH] Added Metrics tab which contains Treemap. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6431 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../CodeQuality/CodeQualityAnalysis.csproj | 6 ++ .../CodeQuality/Src/Controls/MatrixControl.cs | 2 +- src/AddIns/Analysis/CodeQuality/Src/Event.cs | 2 +- src/AddIns/Analysis/CodeQuality/Src/Field.cs | 4 +- .../Analysis/CodeQuality/Src/MainWindow.xaml | 43 +++++++++++++ .../CodeQuality/Src/MainWindow.xaml.cs | 63 +++++++++++++++---- src/AddIns/Analysis/CodeQuality/Src/Method.cs | 4 +- .../Analysis/CodeQuality/Src/MetricsReader.cs | 14 ++--- .../Analysis/CodeQuality/Src/Namespace.cs | 4 +- src/AddIns/Analysis/CodeQuality/Src/Type.cs | 2 +- 10 files changed, 117 insertions(+), 27 deletions(-) diff --git a/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj b/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj index f6d3f1a6a5..06ae9811d4 100644 --- a/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj +++ b/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj @@ -83,6 +83,9 @@ + + ..\..\..\Libraries\WPFToolkit\System.Windows.Controls.DataVisualization.Toolkit.dll + @@ -101,6 +104,9 @@ ..\..\..\Libraries\GraphSharp\WPFExtensions.dll + + ..\..\..\Libraries\WPFToolkit\WPFToolkit.dll + diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs b/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs index 9dc9e7a8ea..0ca4bf28cb 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs @@ -281,7 +281,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls public void MouseWheelLeft() { - SetVerticalOffset(HorizontalOffset + 4); + SetVerticalOffset(HorizontalOffset - 4); } public void MouseWheelRight() diff --git a/src/AddIns/Analysis/CodeQuality/Src/Event.cs b/src/AddIns/Analysis/CodeQuality/Src/Event.cs index 7ae62f3e62..3745e48c04 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Event.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Event.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.CodeQualityAnalysis /// /// Type which owns this event /// - public Type Owner { get; set; } + public Type DeclaringType { get; set; } public Event() { diff --git a/src/AddIns/Analysis/CodeQuality/Src/Field.cs b/src/AddIns/Analysis/CodeQuality/Src/Field.cs index f74e6cd9ee..193c22eaa1 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Field.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Field.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.CodeQualityAnalysis /// /// Type which owns this field /// - public Type Owner { get; set; } + public Type DeclaringType { get; set; } /// /// Whether the field is event @@ -74,7 +74,7 @@ namespace ICSharpCode.CodeQualityAnalysis { FieldType = null; IsEvent = false; - Owner = null; + DeclaringType = null; GenericTypes = new HashSet(); Dependency = null; diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml index 3e8086718e..7013aafc44 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml @@ -6,6 +6,7 @@ xmlns:Graph="clr-namespace:ICSharpCode.CodeQualityAnalysis.Controls" xmlns:src="clr-namespace:ICSharpCode.CodeQualityAnalysis" xmlns:debug="clr-namespace:System.Diagnostics;assembly=System" + xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" Title="Code Quality Analysis" DataContext="{Binding RelativeSource={RelativeSource Self}}" x:Name="root"> @@ -103,6 +104,48 @@ + + + + + + + + + + + + + + + + Assembly + Namespace + Type + Field + Method + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs index 94891105ad..b6e2f8570b 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs @@ -3,26 +3,15 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; -using System.Text; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; using GraphSharp.Controls; using ICSharpCode.CodeQualityAnalysis.Controls; -using ICSharpCode.Core.Presentation; -using ICSharpCode.WpfDesign.Designer.Controls; using Microsoft.Win32; -using Mono.Cecil; -using Mono.Cecil.Cil; -using QuickGraph; -using QuickGraph.Collections; namespace ICSharpCode.CodeQualityAnalysis { @@ -195,5 +184,57 @@ namespace ICSharpCode.CodeQualityAnalysis encoder.Save(outStream); } } + + private void MetricLevel_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + var comboBoxItem = cbxMetrixLevel.SelectedItem as ComboBoxItem; + if (comboBoxItem == null) return; + + cbxMetrics.Items.Clear(); + + var content = comboBoxItem.Content.ToString(); + + if (content == "Assembly") { + //cbxMetrics.Items.Add(new ComboBoxItem { Content = }); + } else if (content == "Namespace") { + + } else if (content == "Type") { + + } else if (content == "Field") { + + } else if (content == "Method") { + cbxMetrics.Items.Add(new ComboBoxItem { Content = "IL instructions" }); + } + } + + private void Metrics_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + var levelItem = cbxMetrixLevel.SelectedItem as ComboBoxItem; + if (levelItem == null) return; + + var level = levelItem.Content.ToString(); + + var metricItem = cbxMetrics.SelectedItem as ComboBoxItem; + if (metricItem == null) return; + + var metric = metricItem.Content.ToString(); + + if (level == "Assembly") { + //cbxMetrics.Items.Add(new ComboBoxItem { Content = }); + } else if (level == "Namespace") { + + } else if (level == "Type") { + + } else if (level == "Field") { + + } else if (level == "Method") { + if (metric == "IL instructions") { + treemap.ItemsSource = from ns in MetricsReader.MainModule.Namespaces + from type in ns.Types + from method in type.Methods + select method; + } + } + } } } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Method.cs b/src/AddIns/Analysis/CodeQuality/Src/Method.cs index 292f82e87b..f4720a7b77 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Method.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Method.cs @@ -49,7 +49,7 @@ namespace ICSharpCode.CodeQualityAnalysis /// /// Type which owns this method /// - public Type Owner { get; set; } + public Type DeclaringType { get; set; } /// /// Whether the method is constructor or not @@ -122,7 +122,7 @@ namespace ICSharpCode.CodeQualityAnalysis GenericReturnTypes = new HashSet(); ReturnType = null; - Owner = null; + DeclaringType = null; IsReturnTypeGenericInstance = false; diff --git a/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs b/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs index cd26ce8694..95ab741e0c 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs @@ -244,7 +244,7 @@ namespace ICSharpCode.CodeQualityAnalysis var e = new Event { Name = eventDefinition.Name, - Owner = type + DeclaringType = type }; type.Events.Add(e); @@ -266,7 +266,7 @@ namespace ICSharpCode.CodeQualityAnalysis (from n in type.Namespace.Module.Namespaces from t in n.Types from f in t.Fields - where f.Name == e.Name && f.Owner == e.Owner + where f.Name == e.Name && f.DeclaringType == e.DeclaringType select f).SingleOrDefault(); if (field != null) @@ -286,7 +286,7 @@ namespace ICSharpCode.CodeQualityAnalysis var field = new Field { Name = fieldDefinition.Name, - Owner = type, + DeclaringType = type, IsPublic = fieldDefinition.IsPublic, IsPrivate = fieldDefinition.IsPrivate, IsProtected = !fieldDefinition.IsPublic && !fieldDefinition.IsPrivate, @@ -326,7 +326,7 @@ namespace ICSharpCode.CodeQualityAnalysis var method = new Method { Name = FormatMethodName(methodDefinition), - Owner = type, + DeclaringType = type, IsConstructor = methodDefinition.IsConstructor, IsPublic = methodDefinition.IsPublic, IsPrivate = methodDefinition.IsPrivate, @@ -423,7 +423,7 @@ namespace ICSharpCode.CodeQualityAnalysis if (operand is MethodDefinition) { var md = operand as MethodDefinition; - var type = (from n in method.Owner.Namespace.Module.Namespaces + var type = (from n in method.DeclaringType.Namespace.Module.Namespaces from t in n.Types where t.FullName == FormatTypeName(md.DeclaringType, true) select t).SingleOrDefault(); @@ -434,14 +434,14 @@ namespace ICSharpCode.CodeQualityAnalysis where m.Name == FormatMethodName(md) select m).SingleOrDefault(); - if (findTargetMethod != null && type == method.Owner) + if (findTargetMethod != null && type == method.DeclaringType) method.MethodUses.Add(findTargetMethod); } if (operand is FieldDefinition) { var fd = operand as FieldDefinition; - var field = (from f in method.Owner.Fields + var field = (from f in method.DeclaringType.Fields where f.Name == fd.Name select f).SingleOrDefault(); diff --git a/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs b/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs index 68a673ace0..c5cfd862a9 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs @@ -181,7 +181,7 @@ namespace ICSharpCode.CodeQualityAnalysis } - if (this.Types.Contains(method.Owner)) + if (this.Types.Contains(method.DeclaringType)) relationship.Relationships.Add(RelationshipType.Contains); } @@ -199,7 +199,7 @@ namespace ICSharpCode.CodeQualityAnalysis } } - if (this.Types.Contains(field.Owner)) + if (this.Types.Contains(field.DeclaringType)) relationship.Relationships.Add(RelationshipType.Contains); } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Type.cs b/src/AddIns/Analysis/CodeQuality/Src/Type.cs index b0dd4c3ba1..f01ead0514 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Type.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Type.cs @@ -19,7 +19,7 @@ namespace ICSharpCode.CodeQualityAnalysis public ISet NestedTypes { get; private set; } /// - /// Type which owns this type. If this isn't nested type so Owner is null. + /// Type which owns this type. If this isn't nested type so DeclaringType is null. /// public Type DeclaringType { get; set; }