Browse Source

Matrix control now shows real data.

pull/19/head
Tomas Linhart 15 years ago
parent
commit
0ae68ca01a
  1. 37
      src/AddIns/Analysis/CodeQuality/Src/Field.cs
  2. 62
      src/AddIns/Analysis/CodeQuality/Src/Method.cs
  3. 119
      src/AddIns/Analysis/CodeQuality/Src/Namespace.cs
  4. 97
      src/AddIns/Analysis/CodeQuality/Src/Type.cs
  5. 19
      src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs

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

@ -83,6 +83,15 @@ namespace ICSharpCode.CodeQualityAnalysis
Dependency = null; Dependency = null;
} }
public IEnumerable<Type> GetAllTypes()
{
yield return FieldType;
yield return DeclaringType;
foreach (var genericType in GenericTypes) {
yield return genericType;
}
}
public Relationship GetRelationship(INode node) public Relationship GetRelationship(INode node)
{ {
Relationship relationship = new Relationship(); Relationship relationship = new Relationship();
@ -92,6 +101,34 @@ namespace ICSharpCode.CodeQualityAnalysis
return relationship; 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; return relationship;
} }

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

@ -145,6 +145,28 @@ namespace ICSharpCode.CodeQualityAnalysis
Variables = 0; Variables = 0;
} }
public IEnumerable<Type> 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<Method> GetAllMethods()
{
foreach (var method in this.MethodUses)
yield return method;
}
public IEnumerable<Field> GetAllFields()
{
foreach (var field in this.FieldUses)
yield return field;
}
public Relationship GetRelationship(INode node) public Relationship GetRelationship(INode node)
{ {
Relationship relationship = new Relationship(); Relationship relationship = new Relationship();
@ -154,6 +176,46 @@ namespace ICSharpCode.CodeQualityAnalysis
return relationship; 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; return relationship;
} }

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

@ -65,130 +65,81 @@ namespace ICSharpCode.CodeQualityAnalysis
return g; return g;
} }
public Relationship GetRelationship(INode node) public IEnumerable<Type> GetAllTypes()
{
Relationship relationship = new Relationship();
if (node == this) {
relationship.Relationships.Add(RelationshipType.Same);
return relationship;
}
if (node is Namespace) {
Namespace ns = (Namespace)node;
foreach (var type in ns.Types)
{ {
if (Types.Contains(type)) { foreach (var type in Types) {
relationship.AddRelationship(RelationshipType.UseThis); yield return type;
foreach (var usedType in type.GetAllTypes()) {
yield return usedType;
} }
} }
} }
public IEnumerable<Method> GetAllMethods()
if (node is Type) { {
Type type = (Type)node; foreach (var type in Types) {
foreach (var method in type.GetAllMethods()) {
if (this.Types.Contains(type.BaseType)) { yield return method;
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) { public IEnumerable<Field> GetAllFields()
if (this.Types.Contains(thisType)) { {
relationship.AddRelationship(RelationshipType.UseThis); foreach (var type in Types) {
} foreach (var field in type.GetAllFields()) {
yield return field;
} }
if (this.Types.Contains(type)) {
relationship.AddRelationship(RelationshipType.Contains);
} }
} }
if (node is Method) { public Relationship GetRelationship(INode node)
Method method = (Method)node; {
Relationship relationship = new Relationship();
if (this.Types.Contains(method.ReturnType)) {
relationship.AddRelationship(RelationshipType.UseThis);
}
foreach (var type in method.GenericReturnTypes) { if (node == this) {
if (this.Types.Contains(type)) { relationship.Relationships.Add(RelationshipType.Same);
relationship.AddRelationship(RelationshipType.UseThis); return relationship;
}
} }
foreach (var parameter in method.Parameters) { if (node is Namespace) {
Namespace ns = (Namespace)node;
if (this.Types.Contains(parameter.ParameterType)) {
relationship.AddRelationship(RelationshipType.UseThis);
}
foreach (var type in parameter.GenericTypes) { foreach (var type in this.GetAllTypes()) {
if (this.Types.Contains(type)) { if (type != null && type.Namespace == ns) {
relationship.AddRelationship(RelationshipType.UseThis); relationship.AddRelationship(RelationshipType.UseThis);
} }
} }
} }
foreach (var type in method.TypeUses) { if (node is Type) {
if (this.Types.Contains(type)) { Type type = (Type)node;
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 usedType in this.GetAllTypes()) {
foreach (var type in this.Types) { if (type == usedType) {
if (type.Fields.Contains(field)) {
relationship.AddRelationship(RelationshipType.UseThis); relationship.AddRelationship(RelationshipType.UseThis);
} }
} }
} }
foreach (var meth in method.MethodUses) { if (node is Method) {
foreach (var type in this.Types) { Method method = (Method)node;
if (type.Methods.Contains(meth)) {
relationship.AddRelationship(RelationshipType.UseThis);
}
}
}
foreach (var type in method.TypeUses) { foreach (var usedMethod in this.GetAllMethods()) {
if (this.Types.Contains(type)) { if (method == usedMethod) {
relationship.AddRelationship(RelationshipType.UseThis); relationship.AddRelationship(RelationshipType.UseThis);
} }
} }
if (this.Types.Contains(method.DeclaringType))
relationship.AddRelationship(RelationshipType.Contains);
} }
if (node is Field) { if (node is Field) {
Field field = (Field)node; Field field = (Field)node;
if (this.Types.Contains(field.FieldType)) {
relationship.AddRelationship(RelationshipType.UseThis);
}
foreach (var type in field.GenericTypes) { foreach (var usedField in this.GetAllFields()) {
if (this.Types.Contains(type)) { if (field == usedField) {
relationship.AddRelationship(RelationshipType.UseThis); relationship.AddRelationship(RelationshipType.UseThis);
} }
} }
if (this.Types.Contains(field.DeclaringType))
relationship.AddRelationship(RelationshipType.Contains);
} }
return relationship; return relationship;

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

@ -253,67 +253,98 @@ namespace ICSharpCode.CodeQualityAnalysis
return g; return g;
} }
public Relationship GetRelationship(INode node) public IEnumerable<Type> GetAllTypes()
{ {
Relationship relationship = new Relationship(); foreach (var field in Fields) {
foreach (var type in field.GetAllTypes()) {
yield return type;
}
}
if (node == this) { foreach (var method in Methods) {
relationship.Relationships.Add(RelationshipType.Same); foreach (var type in method.GetAllTypes()) {
return relationship; yield return type;
}
} }
if (node is Namespace) { yield return this.BaseType;
Namespace ns = (Namespace)node; yield return this.DeclaringType;
if (this.Namespace.Name == ns.Name) { foreach (var type in this.GenericBaseTypes) {
relationship.AddRelationship(RelationshipType.UseThis); yield return type;
} }
if (this.BaseType != null && this.BaseType.Namespace.Name == ns.Name) { foreach (var type in this.NestedTypes) {
relationship.AddRelationship(RelationshipType.UseThis); yield return type;
}
} }
foreach (var type in this.GenericBaseTypes) { public IEnumerable<Method> GetAllMethods()
if (type.Namespace.Name == ns.Name) { {
relationship.AddRelationship(RelationshipType.UseThis); foreach (var method in this.Methods) {
yield return method;
foreach (var usedMethod in method.GetAllMethods())
yield return usedMethod;
} }
} }
foreach (var type in this.GenericImplementedInterfacesTypes) { public IEnumerable<Field> GetAllFields()
if (type.Namespace.Name == ns.Name) { {
relationship.AddRelationship(RelationshipType.UseThis); foreach (var field in this.Fields) {
} yield return field;
} }
foreach (var type in this.ImplementedInterfaces) { foreach (var method in this.Methods) {
if (type.Namespace.Name == ns.Name) { foreach (var field in method.GetAllFields()) {
relationship.AddRelationship(RelationshipType.UseThis); yield return field;
}
} }
} }
foreach (var field in this.Fields) { public Relationship GetRelationship(INode node)
if (field.DeclaringType.Namespace.Name == ns.Name) { {
relationship.AddRelationship(RelationshipType.UseThis); Relationship relationship = new Relationship();
if (node == this) {
relationship.Relationships.Add(RelationshipType.Same);
return relationship;
} }
if (field.FieldType != null && field.FieldType.Namespace.Name == ns.Name) {
if (node is Namespace) {
Namespace ns = (Namespace)node;
foreach (var type in this.GetAllTypes()) {
if (type != null && type.Namespace == ns) {
relationship.AddRelationship(RelationshipType.UseThis); relationship.AddRelationship(RelationshipType.UseThis);
} }
if (field.GenericTypes.Any(type => type.Namespace.Name == ns.Name)) {
relationship.AddRelationship(RelationshipType.UseThis);
} }
} }
foreach (var method in this.Methods) { if (node is Type) {
if (method.TypeUses.Any(type => type.Namespace.Name == ns.Name)) { Type type = (Type)node;
foreach (var usedType in this.GetAllTypes()) {
if (type == usedType) {
relationship.AddRelationship(RelationshipType.UseThis); 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) { }
if (node is Method) {
Method method = (Method)node;
foreach (var usedMethod in this.GetAllMethods()) {
if (method == usedMethod) {
relationship.AddRelationship(RelationshipType.UseThis); relationship.AddRelationship(RelationshipType.UseThis);
} }
if (method.ReturnType != null && method.ReturnType.Namespace.Name == ns.Name) { }
}
if (node is Field) {
Field field = (Field)node;
foreach (var usedField in this.GetAllFields()) {
if (field == usedField) {
relationship.AddRelationship(RelationshipType.UseThis); relationship.AddRelationship(RelationshipType.UseThis);
} }
} }

19
src/AddIns/Analysis/CodeQuality/Src/Utility/Matrix.cs

@ -27,13 +27,13 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility
} }
} }
private DoubleKeyDictionary<int, int, TValue> cache; private DoubleKeyDictionary<TItem, TItem, TValue> cache;
protected Matrix() protected Matrix()
{ {
headerRows = new List<Cell<TItem>>(); headerRows = new List<Cell<TItem>>();
headerColumns = new List<Cell<TItem>>(); headerColumns = new List<Cell<TItem>>();
cache = new DoubleKeyDictionary<int, int, TValue>(); cache = new DoubleKeyDictionary<TItem, TItem, TValue>();
} }
public void AddRow(TItem value) public void AddRow(TItem value)
@ -46,12 +46,12 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility
headerColumns.Add(new Cell<TItem>(value)); headerColumns.Add(new Cell<TItem>(value));
} }
private TValue GetFromCache(int rowIndex, int columnIndex) private TValue GetFromCache(TItem rowIndex, TItem columnIndex)
{ {
return cache[rowIndex, 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); cache.Add(rowIndex, columnIndex, result);
} }
@ -64,12 +64,15 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility
columnIndex > HeaderColumns.Count || columnIndex < 0) columnIndex > HeaderColumns.Count || columnIndex < 0)
return default(TValue); return default(TValue);
// var cacheResult = GetFromCache(rowIndex, columnIndex); var from = HeaderRows[rowIndex].Value;
// if (cacheResult != null) var to = HeaderColumns[columnIndex].Value;
// return cacheResult;
var cacheResult = GetFromCache(from, to);
if (cacheResult != null)
return cacheResult;
var result = GetCellValue(rowIndex, columnIndex); var result = GetCellValue(rowIndex, columnIndex);
// SaveToCache(rowIndex, columnIndex, result); SaveToCache(from, to, result);
return result; return result;
} }
} }

Loading…
Cancel
Save