From aa7e1bba548aea2a79548a193845546645e355a3 Mon Sep 17 00:00:00 2001 From: PeterForstmeier Date: Sun, 1 Jan 2012 20:13:48 +0100 Subject: [PATCH] eliminate '0' values in 'Nodes' --- .../CodeQuality/CodeQualityAnalysis.csproj | 2 +- .../Analysis/CodeQuality/Src/MainWindow.xaml | 4 +- .../CodeQuality/Src/MainWindowModel.cs | 277 ++++-------------- .../Src/Utility/QueryMainModule.cs | 137 +++++++++ .../CodeQuality/Src/Utility/testclass.cs | 87 ------ 5 files changed, 194 insertions(+), 313 deletions(-) create mode 100644 src/AddIns/Analysis/CodeQuality/Src/Utility/QueryMainModule.cs delete mode 100644 src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs diff --git a/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj b/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj index 7d0ebf7d3b..d40b820b65 100644 --- a/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj +++ b/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj @@ -151,7 +151,7 @@ - + diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml index 8a8577a663..d91f48e250 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml @@ -252,7 +252,7 @@ - + nodes; - - public ObservableCollection Nodes { - get { - if (nodes == null) - { - nodes = new ObservableCollection(); - } - 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 @@ -233,121 +210,46 @@ 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;} - - bool metricsIsActive; - /* + void ActivateMetricsExecute () { - + itemsWithCommand.Clear(); switch (SelectedMetricsLevel) { case MetricsLevel.Assembly: - metricsIsActive = false; + break; case MetricsLevel.Namespace: - metricsIsActive = true; + ItemsWithCommand = queryModule.NameSpaceList(); break; case MetricsLevel.Type: - metricsIsActive = true; + break; case MetricsLevel.Method: - metricsIsActive = true; + ItemsWithCommand = queryModule.MethodList(); break; default: throw new Exception("Invalid value for MetricsLevel"); } } - */ - #endregion - #region testregion - - List itemsWithCommand; - - public List ItemsWithCommand { - get { - if (itemsWithCommand == null) { - itemsWithCommand = new List(); - } - return itemsWithCommand; - } - set { itemsWithCommand = value; - base.RaisePropertyChanged(() => ItemsWithCommand);} - } + #region Metrics Combo > Right Combobox + List 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"); + public List ItemsWithCommand { + get { + if (itemsWithCommand == null) { + itemsWithCommand = new List(); + } + return itemsWithCommand; + } + set { + itemsWithCommand = value; + base.RaisePropertyChanged(() => ItemsWithCommand);} } - } ItemWithAction selectedItemWithCommand; @@ -357,127 +259,55 @@ namespace ICSharpCode.CodeQualityAnalysis base.RaisePropertyChanged(() => SelectedItemWithCommand);} } - private void ExecuteMerhodIlInstructions() - { - var t = new testclass(MainModule); - TreeValueProperty = "Instructions.Count"; - Nodes = t.QueryMethod(); - } + public ICommand ExecuteSelectedItemWithCommand {get; private set;} - private void ExecuteMethodComplexity () + void ExecuteSelectedItem() { - 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); + TreeValueProperty = SelectedItemWithCommand.Metrics; + var list = SelectedItemWithCommand.Action.Invoke(); + if (list != null ) { + Nodes = new ObservableCollection(list); } - Nodes = t.QueryMethod(); } - - private void ExecuteMethodVariables () - { - var t = new testclass(MainModule); - TreeValueProperty = Metrics.Variables.ToString(); - Nodes = t.QueryMethod(); - } - - public ICommand ExecuteSelectedItemWithCommand {get; private set;} + #endregion - void ExecuteSelectedItem() - { - //SelectedItemWithCommand.Command.Execute(null); - SelectedItemWithCommand.Action.Invoke(); - } - - - #endregion - #region ShowTreeMap Treemap - void ResetTreeMap() - { - - Nodes.Clear(); - ItemsWithCommand.Clear(); - - base.RaisePropertyChanged(() => Nodes); - base.RaisePropertyChanged(() => ItemsWithCommand); - metricsIsActive = false; + private ObservableCollection nodes; + + public ObservableCollection Nodes { + get { + if (nodes == null) + { + nodes = new ObservableCollection(); + } + return nodes; + } + set { nodes = value; + base.RaisePropertyChanged(() =>this.Nodes);} } - public ICommand ShowTreeMap {get;private set;} + private string treeValueProperty ; - bool CanActivateTreemap() - { - return metricsIsActive; + public string TreeValueProperty { + get { return treeValueProperty; } + set { treeValueProperty = value; + base.RaisePropertyChanged(() =>this.TreeValueProperty);} } - void ShowTreemapExecute () + void ResetTreeMap() { - switch (selectedMetrics) - { - case Metrics.ILInstructions: - TreeValueProperty = "Instructions.Count"; - break; - - case Metrics.CyclomaticComplexity: - TreeValueProperty = Metrics.CyclomaticComplexity.ToString(); - break; - case Metrics.Variables: - TreeValueProperty = Metrics.Variables.ToString(); - break; - default: - throw new Exception("Invalid value for Metrics"); - } - Nodes = PrepareNodes(); + Nodes.Clear(); + ItemsWithCommand.Clear(); + + base.RaisePropertyChanged(() => Nodes); + base.RaisePropertyChanged(() => ItemsWithCommand); } - ObservableCollection PrepareNodes() - { - IEnumerable list = new List(); - - switch (selectedMetricsLevel) - { - case MetricsLevel.Assembly: - list = from ns in MainModule.Namespaces - select ns; - break; - - case MetricsLevel.Namespace: - var n1 = SelectedNode as Namespace; - 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(list); - foreach (INode element in nodes) - { - - var t = element as Namespace; - //Console.WriteLine(t.CyclomaticComplexity); - } - return nodes; - } - #endregion #region ToolStrip and ToolTip @@ -502,6 +332,7 @@ namespace ICSharpCode.CodeQualityAnalysis } public string Description {get; set;} - public Action Action {get; set;} + public Func> Action {get; set;} + public string Metrics {get;set;} } } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Utility/QueryMainModule.cs b/src/AddIns/Analysis/CodeQuality/Src/Utility/QueryMainModule.cs new file mode 100644 index 0000000000..680eb867bf --- /dev/null +++ b/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 +{ + /// + /// Description of testclass. + /// + public class QueryMainModule + { + public QueryMainModule(Module mainModule) + { + MainModule = mainModule; + } + + public Module MainModule {get; private set;} + + private List QueryForMethod() + { + IEnumerable query = new List(); + query = from ns in MainModule.Namespaces + from type in ns.Types + from method in type.Methods + select method; + return query.ToList(); + } + + + public List NameSpaceList() + { + List items = new List(); + 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 MethodList() + { + List items = new List(); + 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 ExecuteNotImplemented() + { + MessageService.ShowMessage("Not Implemented yet","CodeQualityAnalysis"); + return null; + } + + + private List ExecuteMethodILInstructions() + { + var intermediate = QueryForMethod().Cast().ToList(); + var filtered = from method in intermediate + where method.Instructions.Count > 0 + select method; + return filtered.Cast().ToList(); + } + + + private List ExecuteMethodComplexity () + { + var intermediate = QueryForMethod().Cast().ToList(); + var filtered = from method in intermediate + where method.CyclomaticComplexity > 0 + select method; + return filtered.Cast().ToList(); + } + + + private List ExecuteMethodVariables () + { + var intermediate = QueryForMethod().Cast().ToList(); +// eliminate 0-values + var filtered = from method in intermediate + where method.Variables > 0 + select method; + + return filtered.Cast().ToList(); + } + } +} diff --git a/src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs b/src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs deleted file mode 100644 index 6b000aa226..0000000000 --- a/src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs +++ /dev/null @@ -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 -{ - /// - /// Description of testclass. - /// - public class testclass - { - public testclass(Module mainModule) - { - MainModule = mainModule; - } - - public Module MainModule {get; private set;} - - public ObservableCollection QueryMethod() - { - IEnumerable list = new List(); - list = from ns in MainModule.Namespaces - from type in ns.Types - from method in type.Methods - select method; - return new ObservableCollection (list); - } - - public List MethodList() - { - List itemsWithCommand = new List(); - 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(); - } - } -}