Browse Source

TreeMapViewModel.cs, create Linq Queries for Namespace and Method

pull/21/merge
PeterForstmeier 14 years ago
parent
commit
b2223bea74
  1. 1
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 12
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  3. 22
      src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs
  4. 2
      src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryAssembly.cs
  5. 36
      src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryMethod.cs
  6. 98
      src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryNameSpace.cs
  7. 2
      src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryType.cs
  8. 21
      src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/TreeMapViewModel.cs

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

@ -156,6 +156,7 @@
<Compile Include="Src\Utility\Queries\QueryMethod.cs" /> <Compile Include="Src\Utility\Queries\QueryMethod.cs" />
<Compile Include="Src\Utility\Queries\QueryNameSpace.cs" /> <Compile Include="Src\Utility\Queries\QueryNameSpace.cs" />
<Compile Include="Src\Utility\Queries\QueryType.cs" /> <Compile Include="Src\Utility\Queries\QueryType.cs" />
<Compile Include="Src\Utility\Queries\TreeMapViewModel.cs" />
<Compile Include="Src\Utility\VisibleMatrix.cs" /> <Compile Include="Src\Utility\VisibleMatrix.cs" />
<Page Include="Resources\GridSplitterTemplate.xaml" /> <Page Include="Resources\GridSplitterTemplate.xaml" />
<Page Include="Resources\GraphTemplate.xaml"> <Page Include="Resources\GraphTemplate.xaml">

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

@ -41,18 +41,6 @@
<RowDefinition <RowDefinition
Height="Auto" /> Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!--
<ToolBarTray
Background="White"
Grid.Row="0">
<ToolBar>
<Button
Name="btnOpenAssembly"
Content="{Binding btnOpenAssembly}"
Click="btnOpenAssembly_Click"
Margin="0 0 5 0"></Button>
</ToolBar>
</ToolBarTray>-->
<Menu> <Menu>
<MenuItem Header="File"> <MenuItem Header="File">
<MenuItem Header="{Binding btnOpenAssembly}" <MenuItem Header="{Binding btnOpenAssembly}"

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

@ -264,19 +264,12 @@ namespace ICSharpCode.CodeQualityAnalysis
void ExecuteSelectedItem() void ExecuteSelectedItem()
{ {
/*
var s = SelectedTreeNode;
var b = s as Namespace;
var c = s as Type;
var d = s as Method;
var a = s as Module;
*/
if (SelectedItemWithCommand != null) { if (SelectedItemWithCommand != null) {
TreeValueProperty = SelectedItemWithCommand.Metrics; // TreeValueProperty = SelectedItemWithCommand.Metrics;
TreeValueProperty ="Numval";
var list = SelectedItemWithCommand.Action.Invoke(); var list = SelectedItemWithCommand.Action.Invoke();
if (list != null ) { if (list != null ) {
Nodes = new ObservableCollection<INode>(list); Nodes = new ObservableCollection<TreeMapViewModel>(list);
} }
} }
} }
@ -285,13 +278,13 @@ namespace ICSharpCode.CodeQualityAnalysis
#region ShowTreeMap Treemap #region ShowTreeMap Treemap
private ObservableCollection<INode> nodes; private ObservableCollection<TreeMapViewModel> nodes;
public ObservableCollection<INode> Nodes { public ObservableCollection<TreeMapViewModel> Nodes {
get { get {
if (nodes == null) if (nodes == null)
{ {
nodes = new ObservableCollection<INode>(); nodes = new ObservableCollection<TreeMapViewModel>();
} }
return nodes; return nodes;
} }
@ -341,9 +334,8 @@ namespace ICSharpCode.CodeQualityAnalysis
public ItemWithAction() public ItemWithAction()
{ {
} }
public string Description {get; set;} public string Description {get; set;}
public Func<List<INode>> Action {get; set;} public Func<List<TreeMapViewModel>> Action {get; set;}
public string Metrics {get;set;} public string Metrics {get;set;}
} }
} }

2
src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryAssembly.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
return items; return items;
} }
private List<INode> ExecuteNotImplemented() private List<TreeMapViewModel> ExecuteNotImplemented()
{ {
MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis"); MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis");
return null; return null;

36
src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryMethod.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
{ {
} }
private List <Method> QueryForMethod() private List <Method> MethodQuery()
{ {
IEnumerable<Method> query = new List<Method>(); IEnumerable<Method> query = new List<Method>();
query = from ns in MainModule.Namespaces query = from ns in MainModule.Namespaces
@ -44,6 +44,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
Metrics = "Instructions.Count", Metrics = "Instructions.Count",
Action = ExecuteMethodILInstructions Action = ExecuteMethodILInstructions
}); });
/*
items.Add(new ItemWithAction() items.Add(new ItemWithAction()
{ {
Description = "IL Cyclomatic Complexity", Description = "IL Cyclomatic Complexity",
@ -56,40 +57,55 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
Metrics = Metrics.Variables.ToString(), Metrics = Metrics.Variables.ToString(),
Action = ExecuteMethodVariables Action = ExecuteMethodVariables
}); });
*/
return items; return items;
} }
private List<INode> ExecuteMethodILInstructions() private List<TreeMapViewModel> ExecuteMethodILInstructions()
{ {
var intermediate = QueryForMethod(); var intermediate = MethodQuery();
var filtered = from method in intermediate var filtered = from method in intermediate
where method.Instructions.Count > 0 where method.Instructions.Count > 0
select method; select method;
return filtered.Cast<INode>().ToList();
int i = 0;
var list = filtered.Select(m => new TreeMapViewModel()
{
Name = m.Name,
Numval = m.GetAllMethods().Aggregate(i, (current, x) => current + x.Instructions.Count)
});
// var list = intermediate.Select(m => new TreeMapViewModel()
// {
// Name = m.Name,
// Numval = m.GetAllMethods().Aggregate(i, (current, x) => current + x.Instructions.Count)
// });
return list.ToList();
//return filtered.Cast<TreeMapViewModel>().ToList();
} }
private List<INode> ExecuteMethodComplexity () private List<TreeMapViewModel> ExecuteMethodComplexity ()
{ {
var intermediate = QueryForMethod(); var intermediate = MethodQuery();
var filtered = from method in intermediate var filtered = from method in intermediate
where method.CyclomaticComplexity > 0 where method.CyclomaticComplexity > 0
select method; select method;
return filtered.Cast<INode>().ToList(); return filtered.Cast<TreeMapViewModel>().ToList();
} }
private List<INode> ExecuteMethodVariables () private List<TreeMapViewModel> ExecuteMethodVariables ()
{ {
var intermediate = QueryForMethod(); var intermediate = MethodQuery();
// eliminate 0-values reduce time for my test assembly from 6 to 1 sek // eliminate 0-values reduce time for my test assembly from 6 to 1 sek
var filtered = from method in intermediate var filtered = from method in intermediate
where method.Variables > 0 where method.Variables > 0
select method; select method;
return filtered.Cast<INode>().ToList(); return filtered.Cast<TreeMapViewModel>().ToList();
} }
} }
} }

98
src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryNameSpace.cs

@ -9,6 +9,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.Core; using ICSharpCode.Core;
using System.Linq;
namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
{ {
@ -21,6 +22,13 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
{ {
} }
private List <Namespace> NameSpaceQuery()
{
IEnumerable<Namespace> query = new List<Namespace>();
query = from ns in MainModule.Namespaces
select ns;
return query.ToList();
}
public override List<ItemWithAction> GetQueryList() public override List<ItemWithAction> GetQueryList()
{ {
@ -29,40 +37,108 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
{ {
Description = "# of IL Instructions", Description = "# of IL Instructions",
Metrics = "Instructions.Count", Metrics = "Instructions.Count",
Action = ExecuteNotImplemented Action = ExecuteILInstructions
}); });
items.Add(new ItemWithAction() items.Add(new ItemWithAction()
{ {
Description = "# of Methods", Description = "# of Methods",
Metrics = Metrics.CyclomaticComplexity.ToString(), Metrics = Metrics.CyclomaticComplexity.ToString(),
Action = ExecuteNotImplemented Action = MethodsCount
}); });
items.Add(new ItemWithAction() items.Add(new ItemWithAction()
{ {
Description = "# of Fields", Description = "# of Fields",
Metrics = Metrics.Variables.ToString(), Metrics = Metrics.Variables.ToString(),
Action = ExecuteNotImplemented Action = FieldsCount
}); });
items.Add(new ItemWithAction() items.Add(new ItemWithAction()
{ {
Description = "# of Types", Description = "# of Types",
Metrics = Metrics.Variables.ToString(), Metrics = Metrics.Variables.ToString(),
Action = ExecuteNotImplemented Action = TypesCount
}); });
items.Add(new ItemWithAction() // items.Add(new ItemWithAction()
{ // {
Description = "# of Namespaces", // Description = "# of Namespaces",
Metrics = Metrics.Variables.ToString(), // Metrics = Metrics.Variables.ToString(),
Action = ExecuteNotImplemented // Action = ExecuteNotImplemented
}); // });
return items; return items;
} }
private List<INode> ExecuteNotImplemented() private List<TreeMapViewModel> ExecuteNotImplemented()
{ {
MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis"); MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis");
return null; return null;
} }
private List<TreeMapViewModel> ExecuteILInstructions ()
{
//var list = new List<TreeMapNode>();
var intermediate = this.NameSpaceQuery();
var i = 0;
/*
foreach (var element in intermediate)
{
var node = new TreeMapNode();
node.Name = element.Name;
foreach (var m in element.GetAllMethods()) {
i = i + m.Instructions.Count;
}
node.Numval = i;
list.Add(node);
i = 0;
}
*/
var list = intermediate.Select(m => new TreeMapViewModel()
{
Name = m.Name,
Numval = m.GetAllMethods().Aggregate(i, (current, x) => current + x.Instructions.Count)
});
return list.ToList();
}
private List<TreeMapViewModel> MethodsCount()
{
var intermediate = this.NameSpaceQuery();
var list = intermediate.Select(m => new TreeMapViewModel()
{
Name = m.Name,
Numval = m.GetAllMethods().ToList().Count
});
return list.ToList();
}
private List<TreeMapViewModel> FieldsCount()
{
var intermediate = this.NameSpaceQuery();
var list = intermediate.Select(m => new TreeMapViewModel()
{
Name = m.Name,
Numval = m.GetAllFields().ToList().Count
});
return list.ToList();
}
private List<TreeMapViewModel> TypesCount()
{
var intermediate = this.NameSpaceQuery();
var list = intermediate.Select(m => new TreeMapViewModel()
{
Name = m.Name,
Numval = m.GetAllTypes().ToList().Count
});
return list.ToList();
}
} }
} }

2
src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/QueryType.cs

@ -53,7 +53,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
return items; return items;
} }
private List<INode> ExecuteNotImplemented() private List<TreeMapViewModel> ExecuteNotImplemented()
{ {
MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis"); MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis");
return null; return null;

21
src/AddIns/Analysis/CodeQuality/Src/Utility/Queries/TreeMapViewModel.cs

@ -0,0 +1,21 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 07.01.2012
* Time: 19:56
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace ICSharpCode.CodeQualityAnalysis.Utility.Queries
{
/// <summary>
/// Description of TreeMapViewModel.
/// </summary>
public class TreeMapViewModel
{
public string Name {get;set;}
public int Numval {get;set;}
}
}
Loading…
Cancel
Save