30 changed files with 303 additions and 614 deletions
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.CodeQuality.Engine.Dom |
||||
{ |
||||
/// <summary>
|
||||
/// Description of INode.
|
||||
/// </summary>
|
||||
public interface INode |
||||
{ |
||||
string Name { get; } |
||||
IList<INode> Children { get; } |
||||
IEnumerable<INode> Uses { get; } |
||||
IEnumerable<INode> UsedBy { get; } |
||||
|
||||
Relationship GetRelationship(INode value); |
||||
} |
||||
} |
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.CodeQuality.Engine.Dom |
||||
{ |
||||
public interface IValue |
||||
{ |
||||
string Text { get; } |
||||
} |
||||
} |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.CodeQuality.Engine.Dom |
||||
{ |
||||
public abstract class NodeBase |
||||
{ |
||||
public abstract string Name { get; } |
||||
public abstract IList<NodeBase> Children { get; } |
||||
public NodeBase Parent { get; private set; } |
||||
|
||||
internal IEnumerable<NodeBase> AncestorsAndSelf { |
||||
get { |
||||
var node = this; |
||||
while (node != null) { |
||||
yield return node; |
||||
node = node.Parent; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void AddRelationship(NodeBase reference) |
||||
{ |
||||
foreach (NodeBase pa in AncestorsAndSelf) { |
||||
if (reference.AncestorsAndSelf.Contains(pa)) break; |
||||
foreach (NodeBase pb in reference.AncestorsAndSelf) { |
||||
if (AncestorsAndSelf.Contains(pb)) break; |
||||
pa.AddRelationshipInternal(pb); |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected Dictionary<NodeBase, int> relationships = new Dictionary<NodeBase, int>(); |
||||
|
||||
void AddRelationshipInternal(NodeBase reference) |
||||
{ |
||||
if (!relationships.ContainsKey(reference)) |
||||
relationships[reference] = 0; |
||||
relationships[reference]++; |
||||
} |
||||
|
||||
public void AddChild(NodeBase child) |
||||
{ |
||||
child.Parent = this; |
||||
Children.Add(child); |
||||
} |
||||
|
||||
public int GetUses(NodeBase value) |
||||
{ |
||||
if (this == value) |
||||
return -1; |
||||
int uses; |
||||
if (relationships.TryGetValue(value, out uses)) |
||||
return uses; |
||||
return 0; |
||||
} |
||||
} |
||||
} |
@ -1,91 +0,0 @@
@@ -1,91 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.CodeQuality.Engine.Dom |
||||
{ |
||||
/// <summary>
|
||||
/// Description of Relationship.
|
||||
/// </summary>
|
||||
public class Relationship : IValue |
||||
{ |
||||
public ISet<RelationshipType> Relationships { get; private set; } |
||||
|
||||
public int OccurrenceCount { get; private set; } |
||||
|
||||
public string Text { get { return OccurrenceCount.ToString(); } } |
||||
|
||||
public INode To { get; set; } |
||||
public INode From { get; set; } |
||||
|
||||
public Relationship() |
||||
{ |
||||
Relationships = new HashSet<RelationshipType>(); |
||||
} |
||||
|
||||
public void AddRelationship(RelationshipType type) |
||||
{ |
||||
if (type == RelationshipType.Uses || type == RelationshipType.UsedBy) |
||||
OccurrenceCount++; |
||||
|
||||
Relationships.Add(type); |
||||
} |
||||
|
||||
public string InfoText { |
||||
get { |
||||
string text = "is not related to"; |
||||
if (Relationships.Any(r => r == RelationshipType.Uses)) |
||||
text = "uses"; |
||||
else if (Relationships.Any(r => r == RelationshipType.UsedBy)) |
||||
text = "is used by"; |
||||
else if (Relationships.Any(r => r == RelationshipType.Same)) |
||||
text = "is the same as"; |
||||
return string.Format("{0} {1} {2}", From.Name, text, To.Name); |
||||
} |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
var builder = new StringBuilder(); |
||||
|
||||
foreach (var relationship in Relationships) |
||||
builder.Append(relationship + " "); |
||||
|
||||
builder.Append(OccurrenceCount); |
||||
return builder.ToString(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Type of relationship between two INodes.
|
||||
/// </summary>
|
||||
public enum RelationshipType |
||||
{ |
||||
/// <summary>
|
||||
/// a and b are not related to each other.
|
||||
/// </summary>
|
||||
None, |
||||
/// <summary>
|
||||
/// a contains b.
|
||||
/// </summary>
|
||||
Contains, |
||||
/// <summary>
|
||||
/// a uses b.
|
||||
/// </summary>
|
||||
Uses, |
||||
/// <summary>
|
||||
/// a is used by b.
|
||||
/// </summary>
|
||||
UsedBy, |
||||
/// <summary>
|
||||
/// a and b are the same INode
|
||||
/// </summary>
|
||||
Same |
||||
} |
||||
} |
@ -1,140 +0,0 @@
@@ -1,140 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.CodeQuality |
||||
{ |
||||
public class DoubleKeyDictionary<K, T, V> : |
||||
IEnumerable<DoubleKeyPairValue<K, T, V>>, |
||||
IEquatable<DoubleKeyDictionary<K, T, V>> |
||||
{ |
||||
private Dictionary<T, V> innerDictionary; |
||||
|
||||
public DoubleKeyDictionary() |
||||
{ |
||||
OuterDictionary = new Dictionary<K, Dictionary<T, V>>(); |
||||
} |
||||
|
||||
private Dictionary<K, Dictionary<T, V>> OuterDictionary { get; set; } |
||||
|
||||
public void Add(K key1, T key2, V value) |
||||
{ |
||||
if (OuterDictionary.ContainsKey(key1)) { |
||||
if (innerDictionary.ContainsKey(key2)) { |
||||
OuterDictionary[key1][key2] = value; |
||||
} |
||||
else { |
||||
innerDictionary = OuterDictionary[key1]; |
||||
innerDictionary.Add(key2, value); |
||||
OuterDictionary[key1] = innerDictionary; |
||||
} |
||||
} |
||||
else { |
||||
innerDictionary = new Dictionary<T, V>(); |
||||
innerDictionary[key2] = value; |
||||
OuterDictionary.Add(key1, innerDictionary); |
||||
} |
||||
} |
||||
|
||||
public V this[K index1, T index2] |
||||
{ |
||||
get |
||||
{ |
||||
Dictionary<T, V> value1; |
||||
OuterDictionary.TryGetValue(index1, out value1); |
||||
if (value1 == null) |
||||
return default(V); |
||||
|
||||
V value2; |
||||
value1.TryGetValue(index2, out value2); |
||||
if (value2 == null) |
||||
return default(V); |
||||
|
||||
return value2; |
||||
} |
||||
|
||||
set |
||||
{ |
||||
Add(index1, index2, value); |
||||
} |
||||
} |
||||
|
||||
#region IEnumerable<DoubleKeyPairValue<K,T,V>> Members
|
||||
|
||||
public IEnumerator<DoubleKeyPairValue<K, T, V>> GetEnumerator() |
||||
{ |
||||
foreach (KeyValuePair<K, Dictionary<T, V>> outer in OuterDictionary) |
||||
foreach (KeyValuePair<T, V> inner in outer.Value) |
||||
yield return new DoubleKeyPairValue<K, T, V>(outer.Key, inner.Key, inner.Value); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
||||
{ |
||||
return GetEnumerator(); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<DoubleKeyDictionary<K,T,V>> Members
|
||||
|
||||
public bool Equals(DoubleKeyDictionary<K, T, V> other) |
||||
{ |
||||
if (OuterDictionary.Keys.Count != other.OuterDictionary.Keys.Count) |
||||
return false; |
||||
|
||||
bool isEqual = true; |
||||
|
||||
foreach (KeyValuePair<K, Dictionary<T, V>> innerItems in OuterDictionary) { |
||||
if (!other.OuterDictionary.ContainsKey(innerItems.Key)) |
||||
isEqual = false; |
||||
|
||||
if (!isEqual) |
||||
break; |
||||
|
||||
// here we can be sure that the key is in both lists,
|
||||
// but we need to check the contents of the inner dictionary
|
||||
Dictionary<T, V> otherInnerDictionary = other.OuterDictionary[innerItems.Key]; |
||||
foreach (KeyValuePair<T, V> innerValue in innerItems.Value) { |
||||
if (!otherInnerDictionary.ContainsValue(innerValue.Value)) |
||||
isEqual = false; |
||||
if (!otherInnerDictionary.ContainsKey(innerValue.Key)) |
||||
isEqual = false; |
||||
} |
||||
|
||||
if (!isEqual) |
||||
break; |
||||
} |
||||
|
||||
return isEqual; |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
|
||||
public class DoubleKeyPairValue<K, T, V> |
||||
{ |
||||
public K Key1 { get; set; } |
||||
public T Key2 { get; set; } |
||||
public V Value { get; set; } |
||||
|
||||
public DoubleKeyPairValue(K key1, T key2, V value) { |
||||
Key1 = key1; |
||||
Key2 = key2; |
||||
Value = value; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return Key1.ToString() + " - " + Key2.ToString() + " - " + Value.ToString(); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue