Browse Source

Implemented ITypeParameter.EffectiveInterfaceSet

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
211c6a1b05
  1. 2
      ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs
  2. 43
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs
  3. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/DummyTypeParameter.cs

2
ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs

@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Gets the effective interface set of this type parameter.
/// </summary>
IList<IType> EffectiveInterfaceSet { get; }
ICollection<IType> EffectiveInterfaceSet { get; }
/// <summary>
/// Gets if the type parameter has the 'new()' constraint.

43
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs

@ -94,19 +94,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -94,19 +94,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public IType EffectiveBaseClass {
get {
if (effectiveBaseClass == null)
if (effectiveBaseClass == null) {
// protect against cyclic type parameters
using (var busyLock = BusyManager.Enter(this)) {
if (!busyLock.Success)
return SpecialType.UnknownType; // don't cache this error
effectiveBaseClass = CalculateEffectiveBaseClass();
}
}
return effectiveBaseClass;
}
}
IType CalculateEffectiveBaseClass()
{
// protect against cyclic type parameters
using (var busyLock = BusyManager.Enter(this)) {
if (!busyLock.Success)
return SpecialType.UnknownType;
if (HasValueTypeConstraint)
return this.Compilation.FindType(KnownTypeCode.ValueType);
@ -130,13 +131,37 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -130,13 +131,37 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
return result;
}
}
public IList<IType> EffectiveInterfaceSet {
ICollection<IType> effectiveInterfaceSet;
public ICollection<IType> EffectiveInterfaceSet {
get {
throw new NotImplementedException();
var result = LazyInit.VolatileRead(ref effectiveInterfaceSet);
if (result != null) {
return result;
} else {
// protect against cyclic type parameters
using (var busyLock = BusyManager.Enter(this)) {
if (!busyLock.Success)
return EmptyList<IType>.Instance; // don't cache this error
return LazyInit.GetOrSet(ref effectiveInterfaceSet, CalculateEffectiveInterfaceSet());
}
}
}
}
ICollection<IType> CalculateEffectiveInterfaceSet()
{
HashSet<IType> result = new HashSet<IType>();
foreach (IType constraint in this.DirectBaseTypes) {
if (constraint.Kind == TypeKind.Interface) {
result.Add(constraint);
} else if (constraint.Kind == TypeKind.TypeParameter) {
result.UnionWith(((ITypeParameter)constraint).EffectiveInterfaceSet);
}
}
return result;
}
public abstract bool HasDefaultConstructorConstraint { get; }
public abstract bool HasReferenceTypeConstraint { get; }

2
ICSharpCode.NRefactory/TypeSystem/Implementation/DummyTypeParameter.cs

@ -189,7 +189,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -189,7 +189,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return SpecialType.UnknownType; }
}
IList<IType> ITypeParameter.EffectiveInterfaceSet {
ICollection<IType> ITypeParameter.EffectiveInterfaceSet {
get { return EmptyList<IType>.Instance; }
}

Loading…
Cancel
Save