Browse Source

eliminate '0' values in 'Nodes'

pull/21/merge
PeterForstmeier 14 years ago
parent
commit
aa7e1bba54
  1. 2
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 4
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  3. 245
      src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs
  4. 137
      src/AddIns/Analysis/CodeQuality/Src/Utility/QueryMainModule.cs
  5. 87
      src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs

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

@ -151,7 +151,7 @@
<Compile Include="Src\Utility\Localizeable\EnumToFriendlyNameConverter.cs" /> <Compile Include="Src\Utility\Localizeable\EnumToFriendlyNameConverter.cs" />
<Compile Include="Src\Utility\Localizeable\LocalizableDescriptionAttribute.cs" /> <Compile Include="Src\Utility\Localizeable\LocalizableDescriptionAttribute.cs" />
<Compile Include="Src\Utility\Matrix.cs" /> <Compile Include="Src\Utility\Matrix.cs" />
<Compile Include="Src\Utility\testclass.cs" /> <Compile Include="Src\Utility\QueryMainModule.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">

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

@ -252,7 +252,7 @@
</ObjectDataProvider.MethodParameters> </ObjectDataProvider.MethodParameters>
</ObjectDataProvider> </ObjectDataProvider>
<!--
<ObjectDataProvider MethodName="GetValues" <ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}" ObjectType="{x:Type sys:Enum}"
x:Key="Metrics"> x:Key="Metrics">
@ -260,7 +260,7 @@
<x:Type TypeName="src:Metrics" /> <x:Type TypeName="src:Metrics" />
</ObjectDataProvider.MethodParameters> </ObjectDataProvider.MethodParameters>
</ObjectDataProvider> </ObjectDataProvider>
-->
<loc:EnumToFriendlyNameConverter x:Key="enumItemsConverter"/> <loc:EnumToFriendlyNameConverter x:Key="enumItemsConverter"/>
<DataTemplate <DataTemplate

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

@ -35,8 +35,6 @@ namespace ICSharpCode.CodeQualityAnalysis
public enum Metrics public enum Metrics
{ {
[LocalizableDescription("Select a Value")]
dummy,
[LocalizableDescription("IL Instructions")] [LocalizableDescription("IL Instructions")]
ILInstructions, ILInstructions,
@ -50,11 +48,11 @@ namespace ICSharpCode.CodeQualityAnalysis
public class MainWindowViewModel :ViewModelBase public class MainWindowViewModel :ViewModelBase
{ {
QueryMainModule queryModule;
public MainWindowViewModel():base() public MainWindowViewModel():base()
{ {
this.FrmTitle = "Code Quality Analysis"; this.FrmTitle = "Code Quality Analysis";
//ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.Server");
this.btnOpenAssembly = "Open Assembly"; this.btnOpenAssembly = "Open Assembly";
#region MainTab #region MainTab
@ -64,9 +62,8 @@ namespace ICSharpCode.CodeQualityAnalysis
#endregion #endregion
ActivateMetrics = new RelayCommand(ActivateMetricsExecute); ActivateMetrics = new RelayCommand(ActivateMetricsExecute);
ShowTreeMap = new RelayCommand(ShowTreemapExecute,CanActivateTreemap);
ExecuteSelectedItemWithCommand = new RelayCommand (ExecuteSelectedItem); ExecuteSelectedItemWithCommand = new RelayCommand (ExecuteSelectedItem);
} }
@ -155,6 +152,7 @@ namespace ICSharpCode.CodeQualityAnalysis
mainModule.TypesCount, mainModule.TypesCount,
mainModule.MethodsCount, mainModule.MethodsCount,
mainModule.FieldsCount); mainModule.FieldsCount);
queryModule = new QueryMainModule(MainModule);
} }
} }
@ -193,28 +191,7 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
private ObservableCollection<INode> nodes;
public ObservableCollection<INode> Nodes {
get {
if (nodes == null)
{
nodes = new ObservableCollection<INode>();
}
return nodes;
}
set { nodes = value;
base.RaisePropertyChanged(() =>this.Nodes);}
}
private string treeValueProperty ;
public string TreeValueProperty {
get { return treeValueProperty; }
set { treeValueProperty = value;
base.RaisePropertyChanged(() =>this.TreeValueProperty);}
}
#region MetricsLevel Combo Left ComboBox #region MetricsLevel Combo Left ComboBox
@ -233,70 +210,33 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
} }
#endregion
#region Metrics Combo > Right Combobox
public Metrics Metrics
{
get {return Metrics;}
}
Metrics selectedMetrics;
public Metrics SelectedMetrics {
get { return selectedMetrics; }
set { selectedMetrics = value;
base.RaisePropertyChanged(() =>this.SelectedMetrics);
}
}
/*
int selectedMetricsIndex;
public int SelectedMetricsIndex {
get { return selectedMetricsIndex; }
set {
selectedMetricsIndex = value;
base.RaisePropertyChanged(() =>this.SelectedMetricsIndex);}
}
*/
#endregion
#region ActivateMetrics
public ICommand ActivateMetrics {get;private set;} public ICommand ActivateMetrics {get;private set;}
bool metricsIsActive;
/*
void ActivateMetricsExecute () void ActivateMetricsExecute ()
{ {
itemsWithCommand.Clear();
switch (SelectedMetricsLevel) { switch (SelectedMetricsLevel) {
case MetricsLevel.Assembly: case MetricsLevel.Assembly:
metricsIsActive = false;
break; break;
case MetricsLevel.Namespace: case MetricsLevel.Namespace:
metricsIsActive = true; ItemsWithCommand = queryModule.NameSpaceList();
break; break;
case MetricsLevel.Type: case MetricsLevel.Type:
metricsIsActive = true;
break; break;
case MetricsLevel.Method: case MetricsLevel.Method:
metricsIsActive = true; ItemsWithCommand = queryModule.MethodList();
break; break;
default: default:
throw new Exception("Invalid value for MetricsLevel"); throw new Exception("Invalid value for MetricsLevel");
} }
} }
*/
#endregion #endregion
#region testregion #region Metrics Combo > Right Combobox
List<ItemWithAction> itemsWithCommand; List<ItemWithAction> itemsWithCommand;
public List<ItemWithAction> ItemsWithCommand { public List<ItemWithAction> ItemsWithCommand {
@ -306,49 +246,11 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
return itemsWithCommand; return itemsWithCommand;
} }
set { itemsWithCommand = value; set {
itemsWithCommand = value;
base.RaisePropertyChanged(() => ItemsWithCommand);} base.RaisePropertyChanged(() => ItemsWithCommand);}
} }
void ActivateMetricsExecute ()
{
itemsWithCommand.Clear();
switch (SelectedMetricsLevel) {
case MetricsLevel.Assembly:
break;
case MetricsLevel.Namespace:
break;
case MetricsLevel.Type:
break;
case MetricsLevel.Method:
ItemsWithCommand.Add(new ItemWithAction()
{
Description = "IL Instructions",
Action = ExecuteMerhodIlInstructions
});
ItemsWithCommand.Add(new ItemWithAction()
{
Description = "Cyclomatic Complexity",
Action = ExecuteMethodComplexity
});
ItemsWithCommand.Add(new ItemWithAction()
{
Description = "Variables",
Action = ExecuteMethodVariables
});
// var t = new testclass(MainModule);
// ItemsWithCommand = t.MethodList();
break;
default:
throw new Exception("Invalid value for MetricsLevel");
}
}
ItemWithAction selectedItemWithCommand; ItemWithAction selectedItemWithCommand;
public ItemWithAction SelectedItemWithCommand { public ItemWithAction SelectedItemWithCommand {
@ -357,126 +259,54 @@ namespace ICSharpCode.CodeQualityAnalysis
base.RaisePropertyChanged(() => SelectedItemWithCommand);} base.RaisePropertyChanged(() => SelectedItemWithCommand);}
} }
private void ExecuteMerhodIlInstructions()
{
var t = new testclass(MainModule);
TreeValueProperty = "Instructions.Count";
Nodes = t.QueryMethod();
}
private void ExecuteMethodComplexity ()
{
var t = new testclass(MainModule);
TreeValueProperty = Metrics.CyclomaticComplexity.ToString();
var tt = t.QueryMethod();
foreach (var element in tt) {
var m = element as Method;
Console.WriteLine("{0} - {1}",m.Name,m.CyclomaticComplexity);
}
Nodes = t.QueryMethod();
}
private void ExecuteMethodVariables ()
{
var t = new testclass(MainModule);
TreeValueProperty = Metrics.Variables.ToString();
Nodes = t.QueryMethod();
}
public ICommand ExecuteSelectedItemWithCommand {get; private set;} public ICommand ExecuteSelectedItemWithCommand {get; private set;}
void ExecuteSelectedItem() void ExecuteSelectedItem()
{ {
//SelectedItemWithCommand.Command.Execute(null); TreeValueProperty = SelectedItemWithCommand.Metrics;
SelectedItemWithCommand.Action.Invoke(); var list = SelectedItemWithCommand.Action.Invoke();
if (list != null ) {
Nodes = new ObservableCollection<INode>(list);
}
} }
#endregion #endregion
#region ShowTreeMap Treemap #region ShowTreeMap Treemap
void ResetTreeMap() private ObservableCollection<INode> nodes;
{
Nodes.Clear();
ItemsWithCommand.Clear();
base.RaisePropertyChanged(() => Nodes);
base.RaisePropertyChanged(() => ItemsWithCommand);
metricsIsActive = false;
}
public ICommand ShowTreeMap {get;private set;}
bool CanActivateTreemap() public ObservableCollection<INode> Nodes {
get {
if (nodes == null)
{ {
return metricsIsActive; nodes = new ObservableCollection<INode>();
}
return nodes;
}
set { nodes = value;
base.RaisePropertyChanged(() =>this.Nodes);}
} }
void ShowTreemapExecute () private string treeValueProperty ;
{
switch (selectedMetrics)
{
case Metrics.ILInstructions:
TreeValueProperty = "Instructions.Count";
break;
case Metrics.CyclomaticComplexity: public string TreeValueProperty {
TreeValueProperty = Metrics.CyclomaticComplexity.ToString(); get { return treeValueProperty; }
break; set { treeValueProperty = value;
case Metrics.Variables: base.RaisePropertyChanged(() =>this.TreeValueProperty);}
TreeValueProperty = Metrics.Variables.ToString();
break;
default:
throw new Exception("Invalid value for Metrics");
}
Nodes = PrepareNodes();
} }
ObservableCollection<INode> PrepareNodes() void ResetTreeMap()
{
IEnumerable<INode> list = new List<INode>();
switch (selectedMetricsLevel)
{ {
case MetricsLevel.Assembly: Nodes.Clear();
list = from ns in MainModule.Namespaces ItemsWithCommand.Clear();
select ns;
break;
case MetricsLevel.Namespace: base.RaisePropertyChanged(() => Nodes);
var n1 = SelectedNode as Namespace; base.RaisePropertyChanged(() => ItemsWithCommand);
list = from x in n1.GetAllMethods() select x;
break;
//type has no Cyclomatics
case MetricsLevel.Type:
var n2 = SelectedNode as Namespace;
list = n2.GetAllTypes();
var i1 = list.Count();
break;
case MetricsLevel.Method:
list = from ns in MainModule.Namespaces
from type in ns.Types
from method in type.Methods
select method;
break;
default:
throw new Exception("Invalid value for MetricsLevel");
} }
var nodes = new ObservableCollection<INode>(list);
foreach (INode element in nodes)
{
var t = element as Namespace;
//Console.WriteLine(t.CyclomaticComplexity);
}
return nodes;
}
#endregion #endregion
@ -502,6 +332,7 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
public string Description {get; set;} public string Description {get; set;}
public Action Action {get; set;} public Func<List<INode>> Action {get; set;}
public string Metrics {get;set;}
} }
} }

137
src/AddIns/Analysis/CodeQuality/Src/Utility/QueryMainModule.cs

@ -0,0 +1,137 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 25.12.2011
* Time: 19:07
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using ICSharpCode.Core;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
/// <summary>
/// Description of testclass.
/// </summary>
public class QueryMainModule
{
public QueryMainModule(Module mainModule)
{
MainModule = mainModule;
}
public Module MainModule {get; private set;}
private List <INode> QueryForMethod()
{
IEnumerable<INode> query = new List<INode>();
query = from ns in MainModule.Namespaces
from type in ns.Types
from method in type.Methods
select method;
return query.ToList();
}
public List<ItemWithAction> NameSpaceList()
{
List<ItemWithAction> items = new List<ItemWithAction>();
items.Add(new ItemWithAction()
{
Description = "# of Methods",
Metrics = Metrics.CyclomaticComplexity.ToString(),
Action = ExecuteNotImplemented
});
items.Add(new ItemWithAction()
{
Description = "# of Fields",
Metrics = Metrics.Variables.ToString(),
Action = ExecuteNotImplemented
});
items.Add(new ItemWithAction()
{
Description = "# of Types",
Metrics = Metrics.Variables.ToString(),
Action = ExecuteNotImplemented
});
items.Add(new ItemWithAction()
{
Description = "# of Namespaces",
Metrics = Metrics.Variables.ToString(),
Action = ExecuteNotImplemented
});
return items;
}
public List<ItemWithAction> MethodList()
{
List<ItemWithAction> items = new List<ItemWithAction>();
items.Add(new ItemWithAction()
{
Description = "# of IL Instructions",
Metrics = "Instructions.Count",
Action = ExecuteMethodILInstructions
});
items.Add(new ItemWithAction()
{
Description = "Cyclomatic Complexity",
Metrics = Metrics.CyclomaticComplexity.ToString(),
Action = ExecuteMethodComplexity
});
items.Add(new ItemWithAction()
{
Description = "Variables",
Metrics = Metrics.Variables.ToString(),
Action = ExecuteMethodVariables
});
return items;
}
private List<INode> ExecuteNotImplemented()
{
MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis");
return null;
}
private List<INode> ExecuteMethodILInstructions()
{
var intermediate = QueryForMethod().Cast<Method>().ToList();
var filtered = from method in intermediate
where method.Instructions.Count > 0
select method;
return filtered.Cast<INode>().ToList();
}
private List<INode> ExecuteMethodComplexity ()
{
var intermediate = QueryForMethod().Cast<Method>().ToList();
var filtered = from method in intermediate
where method.CyclomaticComplexity > 0
select method;
return filtered.Cast<INode>().ToList();
}
private List<INode> ExecuteMethodVariables ()
{
var intermediate = QueryForMethod().Cast<Method>().ToList();
// eliminate 0-values
var filtered = from method in intermediate
where method.Variables > 0
select method;
return filtered.Cast<INode>().ToList();
}
}
}

87
src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs

@ -1,87 +0,0 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 25.12.2011
* Time: 19:07
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
/// <summary>
/// Description of testclass.
/// </summary>
public class testclass
{
public testclass(Module mainModule)
{
MainModule = mainModule;
}
public Module MainModule {get; private set;}
public ObservableCollection <INode> QueryMethod()
{
IEnumerable<INode> list = new List<INode>();
list = from ns in MainModule.Namespaces
from type in ns.Types
from method in type.Methods
select method;
return new ObservableCollection <INode>(list);
}
public List<ItemWithAction> MethodList()
{
List<ItemWithAction> itemsWithCommand = new List<ItemWithAction>();
itemsWithCommand.Add(new ItemWithAction()
{
Description = "IL Instructions",
Action = ExecuteMerhodIlInstructions
});
itemsWithCommand.Add(new ItemWithAction()
{
Description = "Cyclomatic Complexity",
Action = ExecuteMethodComplexity
});
itemsWithCommand.Add(new ItemWithAction()
{
Description = "Variables",
Action = ExecuteMethodVariables
});
return itemsWithCommand;
}
private void ExecuteMerhodIlInstructions()
{
// var t = new testclass(MainModule);
// TreeValueProperty = "Instructions.Count";
// Nodes = t.QueryMethod();
}
private void ExecuteMethodComplexity ()
{
// var t = new testclass(MainModule);
// TreeValueProperty = Metrics.CyclomaticComplexity.ToString();
// var tt = t.QueryMethod();
// foreach (var element in tt) {
// var m = element as Method;
// Console.WriteLine("{0} - {1}",m.Name,m.CyclomaticComplexity);
// }
// Nodes = t.QueryMethod();
}
private void ExecuteMethodVariables ()
{
// var t = new testclass(MainModule);
// TreeValueProperty = Metrics.Variables.ToString();
// Nodes = t.QueryMethod();
}
}
}
Loading…
Cancel
Save