Browse Source

Matrix control now shows real data.

pull/19/head
Tomas Linhart 14 years ago
parent
commit
0ae68ca01a
  1. 37
      src/AddIns/Analysis/CodeQuality/Src/Field.cs
  2. 62
      src/AddIns/Analysis/CodeQuality/Src/Method.cs
  3. 141
      src/AddIns/Analysis/CodeQuality/Src/Namespace.cs
  4. 113
      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 @@ -83,6 +83,15 @@ namespace ICSharpCode.CodeQualityAnalysis
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)
{
Relationship relationship = new Relationship();
@ -92,6 +101,34 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -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;
}

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

@ -145,6 +145,28 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -145,6 +145,28 @@ namespace ICSharpCode.CodeQualityAnalysis
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)
{
Relationship relationship = new Relationship();
@ -154,6 +176,46 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -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;
}

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

@ -65,6 +65,34 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -65,6 +65,34 @@ namespace ICSharpCode.CodeQualityAnalysis
return g;
}
public IEnumerable<Type> GetAllTypes()
{
foreach (var type in Types) {
yield return type;
foreach (var usedType in type.GetAllTypes()) {
yield return usedType;
}
}
}
public IEnumerable<Method> GetAllMethods()
{
foreach (var type in Types) {
foreach (var method in type.GetAllMethods()) {
yield return method;
}
}
}
public IEnumerable<Field> 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 @@ -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;

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

@ -253,67 +253,98 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -253,67 +253,98 @@ namespace ICSharpCode.CodeQualityAnalysis
return g;
}
public IEnumerable<Type> 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<Method> GetAllMethods()
{
foreach (var method in this.Methods) {
yield return method;
foreach (var usedMethod in method.GetAllMethods())
yield return usedMethod;
}
}
public IEnumerable<Field> 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);
}
}

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

@ -27,13 +27,13 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility @@ -27,13 +27,13 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility
}
}
private DoubleKeyDictionary<int, int, TValue> cache;
private DoubleKeyDictionary<TItem, TItem, TValue> cache;
protected Matrix()
{
headerRows = 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)
@ -46,12 +46,12 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility @@ -46,12 +46,12 @@ namespace ICSharpCode.CodeQualityAnalysis.Utility
headerColumns.Add(new Cell<TItem>(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 @@ -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;
}
}

Loading…
Cancel
Save