Browse Source

Adjust unit tests and fix bugs introduced by caching.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
a93fd14efb
  1. 2
      ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
  2. 12
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  3. 14
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
  4. 18
      ICSharpCode.NRefactory/Documentation/IDStringProvider.cs
  5. 2
      ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs
  6. 33
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs
  7. 32
      ICSharpCode.NRefactory/TypeSystem/KnownTypeReference.cs
  8. 2
      ICSharpCode.NRefactory/TypeSystem/PointerType.cs

2
ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs

@ -77,7 +77,7 @@ namespace OtherNS { @@ -77,7 +77,7 @@ namespace OtherNS {
{
return new TypeSystemAstBuilder(
new CSharpResolver(ctx) {
UsingScope = currentTypeDef != null ? parsedFile.GetUsingScope(currentTypeDef.Region.Begin) : parsedFile.RootUsingScope,
CurrentUsingScope = currentTypeDef != null ? parsedFile.GetUsingScope(currentTypeDef.Region.Begin) : parsedFile.RootUsingScope,
CurrentTypeDefinition = currentTypeDef
});
}

12
ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -32,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public void SimpleNameLookupWithoutContext()
{
// nothing should be found without specifying any UsingScope - however, the resolver also must not crash
resolver.UsingScope = null;
resolver.CurrentUsingScope = null;
Assert.IsTrue(resolver.ResolveSimpleName("System", new IType[0]).IsError);
}
@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void NamespaceInParentNamespaceLookup()
{
resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
resolver.CurrentUsingScope = MakeUsingScope("System.Collections.Generic");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("Text", new IType[0]);
Assert.AreEqual("System.Text", nrr.NamespaceName);
}
@ -102,7 +102,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -102,7 +102,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public void AliasToImportedType2()
{
AddUsing("System");
resolver.UsingScope = new UsingScope(resolver.UsingScope, "SomeNamespace");
resolver.CurrentUsingScope = new UsingScope(resolver.CurrentUsingScope, "SomeNamespace");
AddUsingAlias("x", "String");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("x", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void FindClassInCurrentNamespace()
{
resolver.UsingScope = MakeUsingScope("System.Collections");
resolver.CurrentUsingScope = MakeUsingScope("System.Collections");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("String", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
}
@ -140,7 +140,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -140,7 +140,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void FindNeighborNamespace()
{
resolver.UsingScope = MakeUsingScope("System.Collections");
resolver.CurrentUsingScope = MakeUsingScope("System.Collections");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("Text", new IType[0]);
Assert.AreEqual("System.Text", nrr.NamespaceName);
}
@ -148,7 +148,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -148,7 +148,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void FindTypeParameters()
{
resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
resolver.CurrentUsingScope = MakeUsingScope("System.Collections.Generic");
resolver.CurrentTypeDefinition = context.GetTypeDefinition(typeof(List<>));
resolver.CurrentMember = resolver.CurrentTypeDefinition.Methods.Single(m => m.Name == "ConvertAll");

14
ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
project = new SimpleProjectContent();
context = new CompositeTypeResolveContext(new [] { project, mscorlib, CecilLoaderTests.SystemCore });
resolver = new CSharpResolver(context);
resolver.UsingScope = MakeUsingScope("");
resolver.CurrentUsingScope = MakeUsingScope("");
}
protected UsingScope MakeUsingScope(string namespaceName)
@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// </summary>
protected void AddUsing(string namespaceName)
{
resolver.UsingScope.Usings.Add(MakeReference(namespaceName));
resolver.CurrentUsingScope.Usings.Add(MakeReference(namespaceName));
}
/// <summary>
@ -71,15 +71,15 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -71,15 +71,15 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// </summary>
protected void AddUsingAlias(string alias, string target)
{
resolver.UsingScope.UsingAliases.Add(new KeyValuePair<string, ITypeOrNamespaceReference>(alias, MakeReference(target)));
resolver.CurrentUsingScope.UsingAliases.Add(new KeyValuePair<string, ITypeOrNamespaceReference>(alias, MakeReference(target)));
}
protected ITypeOrNamespaceReference MakeReference(string namespaceName)
{
string[] nameParts = namespaceName.Split('.');
ITypeOrNamespaceReference r = new SimpleTypeOrNamespaceReference(nameParts[0], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.UsingScope, SimpleNameLookupMode.TypeInUsingDeclaration);
ITypeOrNamespaceReference r = new SimpleTypeOrNamespaceReference(nameParts[0], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.CurrentUsingScope, SimpleNameLookupMode.TypeInUsingDeclaration);
for (int i = 1; i < nameParts.Length; i++) {
r = new MemberTypeOrNamespaceReference(r, nameParts[i], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.UsingScope);
r = new MemberTypeOrNamespaceReference(r, nameParts[i], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.CurrentUsingScope);
}
return r;
}
@ -194,8 +194,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -194,8 +194,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
SetUp();
ParsedFile parsedFile = new ParsedFile("test.cs", resolver.UsingScope);
TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.UsingScope, null);
ParsedFile parsedFile = new ParsedFile("test.cs", resolver.CurrentUsingScope);
TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.CurrentUsingScope, null);
cu.AcceptVisitor(convertVisitor, null);
project.UpdateProjectContent(null, convertVisitor.ParsedFile);

18
ICSharpCode.NRefactory/Documentation/IDStringProvider.cs

@ -170,6 +170,15 @@ namespace ICSharpCode.NRefactory.Documentation @@ -170,6 +170,15 @@ namespace ICSharpCode.NRefactory.Documentation
AppendTypeName(b, resolvedType);
return;
}
KnownTypeReference knownType = type as KnownTypeReference;
if (knownType != null) {
if (!string.IsNullOrEmpty(knownType.Namespace)) {
b.Append(knownType.Namespace);
b.Append('.');
}
b.Append(knownType.Name);
return;
}
GetClassTypeReference gctr = type as GetClassTypeReference;
if (gctr != null) {
if (!string.IsNullOrEmpty(gctr.Namespace)) {
@ -240,15 +249,6 @@ namespace ICSharpCode.NRefactory.Documentation @@ -240,15 +249,6 @@ namespace ICSharpCode.NRefactory.Documentation
static int AppendParameterizedTypeName(StringBuilder b, ITypeReference type, IList<ITypeReference> typeArguments, ITypeResolveContext context)
{
KnownTypeReference knownType = type as KnownTypeReference;
if (knownType != null) {
if (!string.IsNullOrEmpty(knownType.Namespace)) {
b.Append(knownType.Namespace);
b.Append('.');
}
b.Append(knownType.Name);
return 0;
}
GetClassTypeReference gctr = type as GetClassTypeReference;
if (gctr != null) {
if (!string.IsNullOrEmpty(gctr.Namespace)) {

2
ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs

@ -86,7 +86,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -86,7 +86,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
[Serializable]
public class ByReferenceTypeReference : ITypeReference, ISupportsInterning
public sealed class ByReferenceTypeReference : ITypeReference, ISupportsInterning
{
ITypeReference elementType;

33
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs

@ -138,24 +138,27 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -138,24 +138,27 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
return this;
}
public override int GetHashCode()
{
unchecked {
return (int)ownerType * 178256151 + index;
}
}
public override bool Equals(object obj)
{
return Equals(obj as IType);
}
// public override int GetHashCode()
// {
// unchecked {
// return (int)ownerType * 178256151 + index;
// }
// }
//
// public override bool Equals(object obj)
// {
// return Equals(obj as IType);
// }
public bool Equals(IType other)
{
DefaultTypeParameter p = other as DefaultTypeParameter;
if (p == null)
return false;
return ownerType == p.ownerType && index == p.index;
// Use reference equality for type parameters. While we could consider any types with same
// ownerType + index as equal for the type system, doing so makes it difficult to cache calculation
// results based on types - e.g. the cache in the Conversions class.
return this == other;
// We can still consider type parameters of different methods/classes to be equal to each other,
// if they have been interned. But then also all constraints are equal, so caching conversions
// is valid in that case.
}
public EntityType OwnerType {

32
ICSharpCode.NRefactory/TypeSystem/KnownTypeReference.cs

@ -31,82 +31,82 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -31,82 +31,82 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Gets a type reference pointing to the <c>void</c> type.
/// </summary>
public static readonly KnownTypeReference Void = new KnownTypeReference(TypeCode.Empty);
public static readonly ITypeReference Void = new KnownTypeReference(TypeCode.Empty);
/// <summary>
/// Gets a type reference pointing to the <c>object</c> type.
/// </summary>
public static readonly KnownTypeReference Object = new KnownTypeReference(TypeCode.Object);
public static readonly ITypeReference Object = new KnownTypeReference(TypeCode.Object);
/// <summary>
/// Gets a type reference pointing to the <c>bool</c> type.
/// </summary>
public static readonly KnownTypeReference Boolean = new KnownTypeReference(TypeCode.Boolean);
public static readonly ITypeReference Boolean = new KnownTypeReference(TypeCode.Boolean);
/// <summary>
/// Gets a type reference pointing to the <c>char</c> type.
/// </summary>
public static readonly KnownTypeReference Char = new KnownTypeReference(TypeCode.Char);
public static readonly ITypeReference Char = new KnownTypeReference(TypeCode.Char);
/// <summary>
/// Gets a type reference pointing to the <c>sbyte</c> type.
/// </summary>
public static readonly KnownTypeReference SByte = new KnownTypeReference(TypeCode.SByte);
public static readonly ITypeReference SByte = new KnownTypeReference(TypeCode.SByte);
/// <summary>
/// Gets a type reference pointing to the <c>byte</c> type.
/// </summary>
public static readonly KnownTypeReference Byte = new KnownTypeReference(TypeCode.Byte);
public static readonly ITypeReference Byte = new KnownTypeReference(TypeCode.Byte);
/// <summary>
/// Gets a type reference pointing to the <c>short</c> type.
/// </summary>
public static readonly KnownTypeReference Int16 = new KnownTypeReference(TypeCode.Int16);
public static readonly ITypeReference Int16 = new KnownTypeReference(TypeCode.Int16);
/// <summary>
/// Gets a type reference pointing to the <c>ushort</c> type.
/// </summary>
public static readonly KnownTypeReference UInt16 = new KnownTypeReference(TypeCode.UInt16);
public static readonly ITypeReference UInt16 = new KnownTypeReference(TypeCode.UInt16);
/// <summary>
/// Gets a type reference pointing to the <c>int</c> type.
/// </summary>
public static readonly KnownTypeReference Int32 = new KnownTypeReference(TypeCode.Int32);
public static readonly ITypeReference Int32 = new KnownTypeReference(TypeCode.Int32);
/// <summary>
/// Gets a type reference pointing to the <c>uint</c> type.
/// </summary>
public static readonly KnownTypeReference UInt32 = new KnownTypeReference(TypeCode.UInt32);
public static readonly ITypeReference UInt32 = new KnownTypeReference(TypeCode.UInt32);
/// <summary>
/// Gets a type reference pointing to the <c>long</c> type.
/// </summary>
public static readonly KnownTypeReference Int64 = new KnownTypeReference(TypeCode.Int64);
public static readonly ITypeReference Int64 = new KnownTypeReference(TypeCode.Int64);
/// <summary>
/// Gets a type reference pointing to the <c>ulong</c> type.
/// </summary>
public static readonly KnownTypeReference UInt64 = new KnownTypeReference(TypeCode.UInt64);
public static readonly ITypeReference UInt64 = new KnownTypeReference(TypeCode.UInt64);
/// <summary>
/// Gets a type reference pointing to the <c>float</c> type.
/// </summary>
public static readonly KnownTypeReference Single = new KnownTypeReference(TypeCode.Single);
public static readonly ITypeReference Single = new KnownTypeReference(TypeCode.Single);
/// <summary>
/// Gets a type reference pointing to the <c>double</c> type.
/// </summary>
public static readonly KnownTypeReference Double = new KnownTypeReference(TypeCode.Double);
public static readonly ITypeReference Double = new KnownTypeReference(TypeCode.Double);
/// <summary>
/// Gets a type reference pointing to the <c>decimal</c> type.
/// </summary>
public static readonly KnownTypeReference Decimal = new KnownTypeReference(TypeCode.Decimal);
public static readonly ITypeReference Decimal = new KnownTypeReference(TypeCode.Decimal);
/// <summary>
/// Gets a type reference pointing to the <c>string</c> type.
/// </summary>
public static readonly KnownTypeReference String = new KnownTypeReference(TypeCode.String);
public static readonly ITypeReference String = new KnownTypeReference(TypeCode.String);
/// <summary>
/// Gets a type reference pointing to the <c>System.Type</c> type.

2
ICSharpCode.NRefactory/TypeSystem/PointerType.cs

@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
[Serializable]
public class PointerTypeReference : ITypeReference, ISupportsInterning
public sealed class PointerTypeReference : ITypeReference, ISupportsInterning
{
ITypeReference elementType;

Loading…
Cancel
Save