Browse Source

Added Metrics tab which contains Treemap.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6431 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Tomáš Linhart 15 years ago
parent
commit
6af05c8c90
  1. 6
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 2
      src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs
  3. 2
      src/AddIns/Analysis/CodeQuality/Src/Event.cs
  4. 4
      src/AddIns/Analysis/CodeQuality/Src/Field.cs
  5. 43
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  6. 63
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs
  7. 4
      src/AddIns/Analysis/CodeQuality/Src/Method.cs
  8. 14
      src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs
  9. 4
      src/AddIns/Analysis/CodeQuality/Src/Namespace.cs
  10. 2
      src/AddIns/Analysis/CodeQuality/Src/Type.cs

6
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj

@ -83,6 +83,9 @@ @@ -83,6 +83,9 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Controls.DataVisualization.Toolkit">
<HintPath>..\..\..\Libraries\WPFToolkit\System.Windows.Controls.DataVisualization.Toolkit.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
@ -101,6 +104,9 @@ @@ -101,6 +104,9 @@
<Reference Include="WPFExtensions">
<HintPath>..\..\..\Libraries\GraphSharp\WPFExtensions.dll</HintPath>
</Reference>
<Reference Include="WPFToolkit">
<HintPath>..\..\..\Libraries\WPFToolkit\WPFToolkit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="Src\App.xaml">

2
src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs

@ -281,7 +281,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls @@ -281,7 +281,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
public void MouseWheelLeft()
{
SetVerticalOffset(HorizontalOffset + 4);
SetVerticalOffset(HorizontalOffset - 4);
}
public void MouseWheelRight()

2
src/AddIns/Analysis/CodeQuality/Src/Event.cs

@ -23,7 +23,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -23,7 +23,7 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <summary>
/// Type which owns this event
/// </summary>
public Type Owner { get; set; }
public Type DeclaringType { get; set; }
public Event()
{

4
src/AddIns/Analysis/CodeQuality/Src/Field.cs

@ -23,7 +23,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -23,7 +23,7 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <summary>
/// Type which owns this field
/// </summary>
public Type Owner { get; set; }
public Type DeclaringType { get; set; }
/// <summary>
/// Whether the field is event
@ -74,7 +74,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -74,7 +74,7 @@ namespace ICSharpCode.CodeQualityAnalysis
{
FieldType = null;
IsEvent = false;
Owner = null;
DeclaringType = null;
GenericTypes = new HashSet<Type>();
Dependency = null;

43
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml

@ -6,6 +6,7 @@ @@ -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 @@ @@ -103,6 +104,48 @@
<TabItem Header="Dependency Matrix">
<Graph:TreeMatrixControl x:Name="matrixControl"></Graph:TreeMatrixControl>
</TabItem>
<TabItem Header="Metrics">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ToolBarTray Background="White" Grid.Row="0" Grid.Column="0">
<ToolBar>
<TextBlock Text="Level: " />
<ComboBox IsEditable="False" x:Name="cbxMetrixLevel" IsDropDownOpen="True" Width="150" SelectionChanged="MetricLevel_SelectionChanged">
<ComboBoxItem Name="assembly">Assembly</ComboBoxItem>
<ComboBoxItem Name="namespace">Namespace</ComboBoxItem>
<ComboBoxItem Name="type">Type</ComboBoxItem>
<ComboBoxItem Name="field">Field</ComboBoxItem>
<ComboBoxItem Name="method">Method</ComboBoxItem>
</ComboBox>
<TextBlock Text="Metric: " />
<ComboBox Width="200" x:Name="cbxMetrics" SelectionChanged="Metrics_SelectionChanged" />
</ToolBar>
</ToolBarTray>
<datavis:TreeMap x:Name="treemap" Grid.Row="1" Grid.Column="0">
<datavis:TreeMap.ItemDefinition>
<datavis:TreeMapItemDefinition ValuePath="Instructions.Count">
<DataTemplate>
<Border Background="AliceBlue" BorderBrush="Black" BorderThickness="1" ToolTipService.ToolTip="{Binding ToolTip}">
<StackPanel>
<TextBlock Text="{Binding DeclaringType.Name}" />
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap"/>
</StackPanel>
</Border>
</DataTemplate>
</datavis:TreeMapItemDefinition>
</datavis:TreeMap.ItemDefinition>
</datavis:TreeMap>
</Grid>
</TabItem>
</TabControl>
<StatusBar Grid.Row="1">
<StatusBarItem HorizontalAlignment="Left" x:Name="progressBar" Visibility="Hidden">

63
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs

@ -3,26 +3,15 @@ using System.Collections.Generic; @@ -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 @@ -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;
}
}
}
}
}

4
src/AddIns/Analysis/CodeQuality/Src/Method.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -49,7 +49,7 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <summary>
/// Type which owns this method
/// </summary>
public Type Owner { get; set; }
public Type DeclaringType { get; set; }
/// <summary>
/// Whether the method is constructor or not
@ -122,7 +122,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -122,7 +122,7 @@ namespace ICSharpCode.CodeQualityAnalysis
GenericReturnTypes = new HashSet<Type>();
ReturnType = null;
Owner = null;
DeclaringType = null;
IsReturnTypeGenericInstance = false;

14
src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs

@ -244,7 +244,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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();

4
src/AddIns/Analysis/CodeQuality/Src/Namespace.cs

@ -181,7 +181,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -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 @@ -199,7 +199,7 @@ namespace ICSharpCode.CodeQualityAnalysis
}
}
if (this.Types.Contains(field.Owner))
if (this.Types.Contains(field.DeclaringType))
relationship.Relationships.Add(RelationshipType.Contains);
}

2
src/AddIns/Analysis/CodeQuality/Src/Type.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -19,7 +19,7 @@ namespace ICSharpCode.CodeQualityAnalysis
public ISet<Type> NestedTypes { get; private set; }
/// <summary>
/// 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.
/// </summary>
public Type DeclaringType { get; set; }

Loading…
Cancel
Save