Browse Source

Vertixes are clickable. Single click shows summary. Double click show internal dependency. Created a new GraphLayout component.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6043 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Tomáš Linhart 15 years ago
parent
commit
9387173428
  1. 5
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 15
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyEdge.cs
  3. 12
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraph.cs
  4. 61
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraphLayout.cs
  5. 39
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyVertex.cs
  6. 13
      src/AddIns/Analysis/CodeQuality/Src/Event.cs
  7. 16
      src/AddIns/Analysis/CodeQuality/Src/Field.cs
  8. 4
      src/AddIns/Analysis/CodeQuality/Src/IDependency.cs
  9. 14
      src/AddIns/Analysis/CodeQuality/Src/INode.cs
  10. 4
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  11. 38
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs
  12. 14
      src/AddIns/Analysis/CodeQuality/Src/Method.cs
  13. 21
      src/AddIns/Analysis/CodeQuality/Src/Module.cs
  14. 22
      src/AddIns/Analysis/CodeQuality/Src/Namespace.cs
  15. 26
      src/AddIns/Analysis/CodeQuality/Src/Type.cs

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

@ -93,9 +93,14 @@ @@ -93,9 +93,14 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Src\Controls\DependencyEdge.cs" />
<Compile Include="Src\Controls\DependencyGraph.cs" />
<Compile Include="Src\Controls\DependencyGraphLayout.cs" />
<Compile Include="Src\Controls\DependencyVertex.cs" />
<Compile Include="Src\DependencyGraphCommand.cs" />
<Compile Include="Src\Event.cs" />
<Compile Include="Src\Field.cs" />
<Compile Include="Src\INode.cs" />
<Compile Include="Src\NodeIconService.cs" />
<Compile Include="Src\IDependency.cs" />
<Compile Include="Src\MetricsReader.cs" />

15
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyEdge.cs

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyEdge : Edge<DependencyVertex>
{
public DependencyEdge(DependencyVertex source, DependencyVertex target) : base(source, target)
{
}
}
}

12
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraph.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyGraph : BidirectionalGraph<DependencyVertex, DependencyEdge>
{
}
}

61
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraphLayout.cs

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using GraphSharp.Controls;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyGraphLayout : GraphLayout<DependencyVertex, DependencyEdge, DependencyGraph>
{
public event MouseButtonEventHandler VertexClick;
public void ChangeGraph(DependencyGraph graph)
{
try
{
if (graph != null && graph.VertexCount > 0)
{
this.Graph = graph;
}
}
catch
{
} // ignore it if it fails
foreach (UIElement element in this.Children)
{
var vertex = element as VertexControl;
if (vertex != null)
{
vertex.PreviewMouseLeftButtonDown += vertex_MouseLeftButtonDown;
vertex.MouseDoubleClick += vertex_MouseDoubleClick;
}
}
}
private void vertex_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var vertexControl = sender as VertexControl;
if (vertexControl != null)
{
var vertex = vertexControl.Vertex as DependencyVertex;
if (vertex != null && vertex.Node.Dependency != null)
{
this.ChangeGraph(vertex.Node.Dependency.BuildDependencyGraph());
}
}
}
private void vertex_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
VertexClick(sender, e);
// TODO: Implement SelectedVertex and change its color
}
}
}

39
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyVertex.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyVertex
{
public INode Node { get; private set; }
public DependencyVertex(INode node)
{
Node = node;
}
public override string ToString()
{
return Node.ToString();
}
public override bool Equals(object obj)
{
var dependencyVertex = obj as DependencyVertex;
if (obj == null)
return false;
else
{
return this.Node.Equals(dependencyVertex.Node);
}
}
public override int GetHashCode()
{
return this.Node.GetHashCode();
}
}
}

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

@ -6,7 +6,7 @@ using QuickGraph; @@ -6,7 +6,7 @@ using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public class Event : IDependency
public class Event : INode
{
/// <summary>
/// Name of event
@ -23,14 +23,21 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -23,14 +23,21 @@ namespace ICSharpCode.CodeQualityAnalysis
/// </summary>
public Type Owner { get; set; }
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
public Event()
{
return null;
Dependency = null;
}
public override string ToString()
{
return Name;
}
public IDependency Dependency { get; set; }
public string GetInfo()
{
return this.ToString();
}
}
}

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

@ -6,7 +6,7 @@ using QuickGraph; @@ -6,7 +6,7 @@ using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public class Field : IDependency
public class Field : INode
{
/// <summary>
/// Name of field
@ -73,16 +73,20 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -73,16 +73,20 @@ namespace ICSharpCode.CodeQualityAnalysis
FieldType = null;
IsEvent = false;
Owner = null;
}
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
{
return null;
Dependency = null;
}
public override string ToString()
{
return Name;
}
public IDependency Dependency { get; set; }
public string GetInfo()
{
return this.ToString();
}
}
}

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

@ -2,13 +2,13 @@ @@ -2,13 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.CodeQualityAnalysis.Controls;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public interface IDependency
{
string Name { set; get; }
BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph();
DependencyGraph BuildDependencyGraph();
}
}

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

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.CodeQualityAnalysis
{
public interface INode
{
string Name { set; get; }
IDependency Dependency { set; get; }
string GetInfo();
}
}

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

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls;assembly=ICSharpCode.WpfDesign.Designer"
xmlns:Graph="clr-namespace:ICSharpCode.CodeQualityAnalysis.Controls"
Title="Code Quality Analysis"
x:Name="root">
<Window.Resources>
@ -36,10 +37,11 @@ @@ -36,10 +37,11 @@
<TreeView Name="definitionTree" Grid.Row="1" Grid.Column="0" SelectedItemChanged="definitionTree_SelectedItemChanged" />
<Controls:ZoomControl Grid.Row="1" Grid.Column="1" Name="zoom" AlwaysShowZoomButtons="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<graphsharp:GraphLayout x:Name="graphLayout"
<Graph:DependencyGraphLayout x:Name="graphLayout"
LayoutAlgorithmType="LinLog"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple"
VertexClick="graphLayout_VertexClick"
/>
</Controls:ZoomControl>

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

@ -11,6 +11,8 @@ using System.Windows.Media; @@ -11,6 +11,8 @@ 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;
@ -27,6 +29,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -27,6 +29,7 @@ namespace ICSharpCode.CodeQualityAnalysis
public partial class MainWindow : Window
{
private MetricsReader _metricsReader;
private VertexControl _selectedVertexControl;
public MainWindow()
{
@ -103,7 +106,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -103,7 +106,7 @@ namespace ICSharpCode.CodeQualityAnalysis
var itemMethod = new MetricTreeViewItem
{
Text = method.Name,
Dependency = method,
Dependency = null,
Icon = NodeIconService.GetIcon(method)
};
@ -115,7 +118,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -115,7 +118,7 @@ namespace ICSharpCode.CodeQualityAnalysis
var itemField = new MetricTreeViewItem
{
Text = field.Name,
Dependency = field,
Dependency = null,
Icon = NodeIconService.GetIcon(field)
};
@ -129,31 +132,24 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -129,31 +132,24 @@ namespace ICSharpCode.CodeQualityAnalysis
{
var item = definitionTree.SelectedItem as MetricTreeViewItem;
if (item != null)
if (item != null && item.Dependency != null)
{
// would be better inherit from TreeViewItem and add reference into it
// will do it later or will use another tree maybe tree from SharpDevelop
string name = item.Header.ToString();
txbTypeInfo.Text = "Infobox: \n" + name;
/*var type = (from n in this._metricsReader.MainModule.Namespaces
from t in n.Types
where t.Name == name
select t).SingleOrDefault();*/
var graph = item.Dependency.BuildDependencyGraph();
graphLayout.ChangeGraph(graph);
}
}
try
private void graphLayout_VertexClick(object sender, MouseButtonEventArgs e)
{
var vertexControl = sender as VertexControl;
if (vertexControl != null)
{
var vertex = vertexControl.Vertex as DependencyVertex;
if (vertex != null)
{
if (graph != null && graph.VertexCount > 0)
{
graphLayout.Graph = graph;
}
txbTypeInfo.Text = "Summary: \n" + vertex.Node.GetInfo();
}
catch
{
} // ignore it if it fails
}
}
private class MetricTreeViewItem : TreeViewItem

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

@ -6,7 +6,7 @@ using QuickGraph; @@ -6,7 +6,7 @@ using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public class Method : IDependency
public class Method : INode
{
/// <summary>
/// Parameters which are used by method
@ -116,17 +116,21 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -116,17 +116,21 @@ namespace ICSharpCode.CodeQualityAnalysis
Owner = null;
IsReturnTypeGenericInstance = false;
}
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
{
return null;
Dependency = null;
}
public override string ToString()
{
return Name;
}
public IDependency Dependency { get; set; }
public string GetInfo()
{
return this.ToString();
}
}
public class MethodParameter

21
src/AddIns/Analysis/CodeQuality/Src/Module.cs

@ -2,11 +2,12 @@ @@ -2,11 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.CodeQualityAnalysis.Controls;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public class Module : IDependency
public class Module : IDependency, INode
{
/// <summary>
/// Namespaces within module
@ -21,15 +22,17 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -21,15 +22,17 @@ namespace ICSharpCode.CodeQualityAnalysis
public Module()
{
Namespaces = new HashSet<Namespace>();
Dependency = this;
}
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
public DependencyGraph BuildDependencyGraph()
{
var g = new BidirectionalGraph<object, IEdge<object>>();
var g = new DependencyGraph();
foreach (var ns in Namespaces)
{
g.AddVertex(ns.Name);
g.AddVertex(new DependencyVertex(ns));
}
foreach (var ns in Namespaces)
@ -41,7 +44,8 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -41,7 +44,8 @@ namespace ICSharpCode.CodeQualityAnalysis
foreach (var dependType in types)
{
if (dependType != type && dependType.Namespace.Module == type.Namespace.Module)
g.AddEdge(new Edge<object>(type.Namespace.Name, dependType.Namespace.Name));
g.AddEdge(new DependencyEdge(new DependencyVertex(type.Namespace),
new DependencyVertex(dependType.Namespace)));
}
}
}
@ -53,5 +57,12 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -53,5 +57,12 @@ namespace ICSharpCode.CodeQualityAnalysis
{
return Name;
}
public IDependency Dependency { get; set; }
public string GetInfo()
{
return this.ToString();
}
}
}

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

@ -2,11 +2,12 @@ @@ -2,11 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.CodeQualityAnalysis.Controls;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public class Namespace : IDependency
public class Namespace : IDependency, INode
{
/// <summary>
/// Types within namespace
@ -26,15 +27,17 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -26,15 +27,17 @@ namespace ICSharpCode.CodeQualityAnalysis
public Namespace()
{
Types = new HashSet<Type>();
Dependency = this;
}
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
public DependencyGraph BuildDependencyGraph()
{
var g = new BidirectionalGraph<object, IEdge<object>>();
var g = new DependencyGraph();
foreach (var type in Types)
{
g.AddVertex(type.Name);
g.AddVertex(new DependencyVertex(type));
}
foreach (var type in Types)
@ -44,7 +47,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -44,7 +47,7 @@ namespace ICSharpCode.CodeQualityAnalysis
foreach (var dependType in types)
{
if (dependType != type && dependType.Namespace == type.Namespace)
g.AddEdge(new Edge<object>(type.Name, dependType.Name));
g.AddEdge(new DependencyEdge(new DependencyVertex(type), new DependencyVertex(dependType)));
}
}
@ -55,5 +58,12 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -55,5 +58,12 @@ namespace ICSharpCode.CodeQualityAnalysis
{
return Name;
}
public IDependency Dependency { get; set; }
public string GetInfo()
{
return this.ToString();
}
}
}

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

@ -2,11 +2,12 @@ @@ -2,11 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.CodeQualityAnalysis.Controls;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public class Type : IDependency
public class Type : IDependency, INode
{
/// <summary>
/// Nested types like inner classes, interfaces and so on.
@ -153,6 +154,8 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -153,6 +154,8 @@ namespace ICSharpCode.CodeQualityAnalysis
BaseType = null;
IsBaseTypeGenericInstance = false;
Dependency = this;
}
/// <summary>
@ -204,30 +207,30 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -204,30 +207,30 @@ namespace ICSharpCode.CodeQualityAnalysis
return set;
}
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
public DependencyGraph BuildDependencyGraph()
{
var g = new BidirectionalGraph<object, IEdge<object>>();
var g = new DependencyGraph();
foreach (var method in Methods)
{
g.AddVertex(method.Name);
g.AddVertex(new DependencyVertex(method));
}
foreach (var field in Fields)
{
g.AddVertex(field.Name);
g.AddVertex(new DependencyVertex(field));
}
foreach (var method in Methods)
{
foreach (var methodUse in method.MethodUses)
{
g.AddEdge(new Edge<object>(method.Name, methodUse.Name));
g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse)));
}
foreach (var fieldUse in method.FieldUses)
{
g.AddEdge(new Edge<object>(method.Name, fieldUse.Name));
g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse)));
}
}
@ -236,7 +239,14 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -236,7 +239,14 @@ namespace ICSharpCode.CodeQualityAnalysis
public override string ToString()
{
return FullName;
return Name;
}
public IDependency Dependency { get; set; }
public string GetInfo()
{
return this.ToString();
}
}
}

Loading…
Cancel
Save