From 0ae68ca01a66938a677893a57d9094541688d476 Mon Sep 17 00:00:00 2001 From: Tomas Linhart Date: Mon, 5 Sep 2011 09:15:18 +0200 Subject: [PATCH] Matrix control now shows real data. --- src/AddIns/Analysis/CodeQuality/Src/Field.cs | 37 +++++ src/AddIns/Analysis/CodeQuality/Src/Method.cs | 62 ++++++++ .../Analysis/CodeQuality/Src/Namespace.cs | 141 ++++++------------ src/AddIns/Analysis/CodeQuality/Src/Type.cs | 113 +++++++++----- .../CodeQuality/Src/Utility/Matrix.cs | 19 ++- 5 files changed, 228 insertions(+), 144 deletions(-) diff --git a/src/AddIns/Analysis/CodeQuality/Src/Field.cs b/src/AddIns/Analysis/CodeQuality/Src/Field.cs index e6dc66de4d..250c68a70f 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Field.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Field.cs @@ -83,6 +83,15 @@ namespace ICSharpCode.CodeQualityAnalysis Dependency = null; } + public IEnumerable GetAllTypes() + { + yield return FieldType; + yield return DeclaringType; + foreach (var genericType in GenericTypes) { + yield return genericType; + } + } + public Relationship GetRelationship(INode node) { Relationship relationship = new Relationship(); @@ -92,6 +101,34 @@ namespace ICSharpCode.CodeQualityAnalysis return relationship; } + if (node is Namespace) { + Namespace ns = (Namespace)node; + + foreach (var type in this.GetAllTypes()) { + if (type != null && type.Namespace == ns) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } + } + + if (node is Type) { + Type type = (Type)node; + + foreach (var usedType in this.GetAllTypes()) { + if (type == usedType) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } + } + + if (node is Field) { + Field field = (Field)node; + + if (this == field) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } + return relationship; } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Method.cs b/src/AddIns/Analysis/CodeQuality/Src/Method.cs index d988320720..c5e3fcad82 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Method.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Method.cs @@ -145,6 +145,28 @@ namespace ICSharpCode.CodeQualityAnalysis Variables = 0; } + public IEnumerable GetAllTypes() + { + yield return this.DeclaringType; + yield return this.ReturnType; + foreach (var type in this.TypeUses) + yield return type; + foreach (var type in this.GenericReturnTypes) + yield return type; + } + + public IEnumerable GetAllMethods() + { + foreach (var method in this.MethodUses) + yield return method; + } + + public IEnumerable GetAllFields() + { + foreach (var field in this.FieldUses) + yield return field; + } + public Relationship GetRelationship(INode node) { Relationship relationship = new Relationship(); @@ -154,6 +176,46 @@ namespace ICSharpCode.CodeQualityAnalysis return relationship; } + if (node is Namespace) { + Namespace ns = (Namespace)node; + + foreach (var type in this.GetAllTypes()) { + if (type != null && type.Namespace == ns) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } + } + + if (node is Type) { + Type type = (Type)node; + + foreach (var usedType in this.GetAllTypes()) { + if (type == usedType) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } + } + + if (node is Method) { + Method method = (Method)node; + + foreach (var usedMethod in this.GetAllMethods()) { + if (method == usedMethod) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } + } + + if (node is Field) { + Field field = (Field)node; + + foreach (var usedField in this.GetAllFields()) { + if (field == usedField) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } + } + return relationship; } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs b/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs index 2a9904dc59..86e16620b0 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Namespace.cs @@ -65,6 +65,34 @@ namespace ICSharpCode.CodeQualityAnalysis return g; } + public IEnumerable GetAllTypes() + { + foreach (var type in Types) { + yield return type; + foreach (var usedType in type.GetAllTypes()) { + yield return usedType; + } + } + } + + public IEnumerable GetAllMethods() + { + foreach (var type in Types) { + foreach (var method in type.GetAllMethods()) { + yield return method; + } + } + } + + public IEnumerable GetAllFields() + { + foreach (var type in Types) { + foreach (var field in type.GetAllFields()) { + yield return field; + } + } + } + public Relationship GetRelationship(INode node) { Relationship relationship = new Relationship(); @@ -77,118 +105,41 @@ namespace ICSharpCode.CodeQualityAnalysis if (node is Namespace) { Namespace ns = (Namespace)node; - foreach (var type in ns.Types) - { - if (Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.UseThis); - } + foreach (var type in this.GetAllTypes()) { + if (type != null && type.Namespace == ns) { + relationship.AddRelationship(RelationshipType.UseThis); + } } } - if (node is Type) { Type type = (Type)node; - if (this.Types.Contains(type.BaseType)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - - foreach (var thisType in type.GenericImplementedInterfacesTypes) { - if (this.Types.Contains(thisType)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - - foreach (var thisType in type.ImplementedInterfaces) { - if (this.Types.Contains(thisType)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - - if (this.Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.Contains); - } + foreach (var usedType in this.GetAllTypes()) { + if (type == usedType) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } } if (node is Method) { Method method = (Method)node; - if (this.Types.Contains(method.ReturnType)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - - foreach (var type in method.GenericReturnTypes) { - if (this.Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - - foreach (var parameter in method.Parameters) { - - if (this.Types.Contains(parameter.ParameterType)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - - foreach (var type in parameter.GenericTypes) { - if (this.Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.UseThis); - } + foreach (var usedMethod in this.GetAllMethods()) { + if (method == usedMethod) { + relationship.AddRelationship(RelationshipType.UseThis); } } - - foreach (var type in method.TypeUses) { - if (this.Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - - foreach (var type in method.TypeUses) { - if (this.Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - - foreach (var field in method.FieldUses) { - foreach (var type in this.Types) { - if (type.Fields.Contains(field)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - } - - foreach (var meth in method.MethodUses) { - foreach (var type in this.Types) { - if (type.Methods.Contains(meth)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - } - - foreach (var type in method.TypeUses) { - if (this.Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - - } - - if (this.Types.Contains(method.DeclaringType)) - relationship.AddRelationship(RelationshipType.Contains); } if (node is Field) { Field field = (Field)node; - if (this.Types.Contains(field.FieldType)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - - foreach (var type in field.GenericTypes) { - if (this.Types.Contains(type)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - - if (this.Types.Contains(field.DeclaringType)) - relationship.AddRelationship(RelationshipType.Contains); + + foreach (var usedField in this.GetAllFields()) { + if (field == usedField) { + relationship.AddRelationship(RelationshipType.UseThis); + } + } } return relationship; diff --git a/src/AddIns/Analysis/CodeQuality/Src/Type.cs b/src/AddIns/Analysis/CodeQuality/Src/Type.cs index d18bd2df86..addc96c2a8 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Type.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Type.cs @@ -253,67 +253,98 @@ namespace ICSharpCode.CodeQualityAnalysis return g; } + public IEnumerable GetAllTypes() + { + foreach (var field in Fields) { + foreach (var type in field.GetAllTypes()) { + yield return type; + } + } + + foreach (var method in Methods) { + foreach (var type in method.GetAllTypes()) { + yield return type; + } + } + + yield return this.BaseType; + yield return this.DeclaringType; + + foreach (var type in this.GenericBaseTypes) { + yield return type; + } + + foreach (var type in this.NestedTypes) { + yield return type; + } + } + + public IEnumerable GetAllMethods() + { + foreach (var method in this.Methods) { + yield return method; + foreach (var usedMethod in method.GetAllMethods()) + yield return usedMethod; + } + } + + public IEnumerable GetAllFields() + { + foreach (var field in this.Fields) { + yield return field; + } + + foreach (var method in this.Methods) { + foreach (var field in method.GetAllFields()) { + yield return field; + } + } + } + public Relationship GetRelationship(INode node) { Relationship relationship = new Relationship(); - - if (node == this) { + + if (node == this) { relationship.Relationships.Add(RelationshipType.Same); return relationship; } - - if (node is Namespace) { + + if (node is Namespace) { Namespace ns = (Namespace)node; - if (this.Namespace.Name == ns.Name) { - relationship.AddRelationship(RelationshipType.UseThis); - } - - if (this.BaseType != null && this.BaseType.Namespace.Name == ns.Name) { - relationship.AddRelationship(RelationshipType.UseThis); - } - - foreach (var type in this.GenericBaseTypes) { - if (type.Namespace.Name == ns.Name) { - relationship.AddRelationship(RelationshipType.UseThis); - } - } - - foreach (var type in this.GenericImplementedInterfacesTypes) { - if (type.Namespace.Name == ns.Name) { + foreach (var type in this.GetAllTypes()) { + if (type != null && type.Namespace == ns) { relationship.AddRelationship(RelationshipType.UseThis); } } + } + + if (node is Type) { + Type type = (Type)node; - foreach (var type in this.ImplementedInterfaces) { - if (type.Namespace.Name == ns.Name) { + foreach (var usedType in this.GetAllTypes()) { + if (type == usedType) { relationship.AddRelationship(RelationshipType.UseThis); } } + } + + if (node is Method) { + Method method = (Method)node; - foreach (var field in this.Fields) { - if (field.DeclaringType.Namespace.Name == ns.Name) { - relationship.AddRelationship(RelationshipType.UseThis); - } - if (field.FieldType != null && field.FieldType.Namespace.Name == ns.Name) { - relationship.AddRelationship(RelationshipType.UseThis); - } - if (field.GenericTypes.Any(type => type.Namespace.Name == ns.Name)) { + foreach (var usedMethod in this.GetAllMethods()) { + if (method == usedMethod) { relationship.AddRelationship(RelationshipType.UseThis); } } + } + + if (node is Field) { + Field field = (Field)node; - foreach (var method in this.Methods) { - if (method.TypeUses.Any(type => type.Namespace.Name == ns.Name)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - if (method.GenericReturnTypes.Any(type => type.Namespace.Name == ns.Name)) { - relationship.AddRelationship(RelationshipType.UseThis); - } - if (method.DeclaringType != null && method.DeclaringType.Namespace.Name == ns.Name) { - relationship.AddRelationship(RelationshipType.UseThis); - } - if (method.ReturnType != null && method.ReturnType.Namespace.Name == ns.Name) { + foreach (var usedField in this.GetAllFields()) { + if (field == usedField) { relationship.AddRelationship(RelationshipType.UseThis); } } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs b/src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs index 007b409c1a..ee8c99844a 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs @@ -27,13 +27,13 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility } } - private DoubleKeyDictionary cache; + private DoubleKeyDictionary cache; protected Matrix() { headerRows = new List>(); headerColumns = new List>(); - cache = new DoubleKeyDictionary(); + cache = new DoubleKeyDictionary(); } public void AddRow(TItem value) @@ -46,12 +46,12 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility headerColumns.Add(new Cell(value)); } - private TValue GetFromCache(int rowIndex, int columnIndex) + private TValue GetFromCache(TItem rowIndex, TItem columnIndex) { return cache[rowIndex, columnIndex]; } - private void SaveToCache(int rowIndex, int columnIndex, TValue result) + private void SaveToCache(TItem rowIndex, TItem columnIndex, TValue result) { cache.Add(rowIndex, columnIndex, result); } @@ -64,12 +64,15 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility columnIndex > HeaderColumns.Count || columnIndex < 0) return default(TValue); -// var cacheResult = GetFromCache(rowIndex, columnIndex); -// if (cacheResult != null) -// return cacheResult; + var from = HeaderRows[rowIndex].Value; + var to = HeaderColumns[columnIndex].Value; + + var cacheResult = GetFromCache(from, to); + if (cacheResult != null) + return cacheResult; var result = GetCellValue(rowIndex, columnIndex); -// SaveToCache(rowIndex, columnIndex, result); + SaveToCache(from, to, result); return result; } }