Browse Source

Move ArrayType/ConstructedType/PointerType from TypeSystem/Implementation to TypeSystem.

Added unit tests for assembly attributes.
newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
02674949a0
  1. 2
      ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs
  2. 27
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  3. 9
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  4. 3
      ICSharpCode.NRefactory/TypeSystem/ArrayType.cs
  5. 4
      ICSharpCode.NRefactory/TypeSystem/ConstructedType.cs
  6. 31
      ICSharpCode.NRefactory/TypeSystem/Implementation/DynamicType.cs
  7. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/GetClassTypeReference.cs
  8. 31
      ICSharpCode.NRefactory/TypeSystem/Implementation/NullType.cs
  9. 31
      ICSharpCode.NRefactory/TypeSystem/Implementation/UnknownType.cs
  10. 3
      ICSharpCode.NRefactory/TypeSystem/PointerType.cs
  11. 76
      ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs
  12. 2
      NRefactory.sln

2
ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs

@ -10,6 +10,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,6 +10,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
[TestFixture]
public class CecilLoaderTests : TypeSystemTests
{
public static readonly IProjectContent Mscorlib = new CecilLoader().LoadAssemblyFile(typeof(object).Assembly.Location);
[TestFixtureSetUp]
public void SetUp()
{

27
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.TypeSystem.TestCase;
using NUnit.Framework;
@ -16,6 +17,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -16,6 +17,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
protected IProjectContent testCasePC;
ITypeDefinition GetClass(Type type)
{
return testCasePC.GetClass(type.FullName, type.GetGenericArguments().Length, StringComparer.Ordinal);
}
[Test]
public void SimplePublicClassTest()
{
@ -63,5 +69,26 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -63,5 +69,26 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.AreEqual("void DynamicGenerics4(Action<int[], dynamic, object>)", a.Convert(testClass.Methods.Single(me => me.Name == "DynamicGenerics4")));
Assert.AreEqual("void DynamicGenerics5(Action<Int32*[], dynamic, object>)", a.Convert(testClass.Methods.Single(me => me.Name == "DynamicGenerics5")));*/
}
[Test]
public void AssemblyAttribute()
{
ITypeResolveContext ctx = MultiTypeResolveContext.Combine(testCasePC, CecilLoaderTests.Mscorlib);
var attributes = testCasePC.AssemblyAttributes;
var typeTest = attributes.First(a => a.AttributeType.Resolve(testCasePC).FullName == typeof(TypeTestAttribute).FullName);
Assert.AreEqual(3, typeTest.PositionalArguments.Count);
// first argument is (int)42
Assert.AreEqual(42, (int)typeTest.PositionalArguments[0].GetValue(testCasePC));
// second argument is typeof(System.Action<>)
IType rt = (IType)typeTest.PositionalArguments[1].GetValue(testCasePC);
Assert.IsFalse(rt is ConstructedType); // rt must not be constructed - it's just an unbound type
Assert.AreEqual("System.Action", rt.FullName);
Assert.AreEqual(1, rt.TypeParameterCount);
// third argument is typeof(IDictionary<string, IList<TestAttribute>>)
ConstructedType crt = (ConstructedType)typeTest.PositionalArguments[2];
Assert.AreEqual("System.Collections.Generic.IDictionary", crt.FullName);
Assert.AreEqual("System.String", crt.TypeArguments[0].FullName);
Assert.AreEqual("System.Collections.Generic.IList{NUnit.Framework.TestAttribute}", crt.TypeArguments[1].DotNetName);
}
}
}

9
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -141,8 +141,10 @@ @@ -141,8 +141,10 @@
<Compile Include="CSharp\Parser\mcs\roottypes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TypeSystem\Accessibility.cs" />
<Compile Include="TypeSystem\ArrayType.cs" />
<Compile Include="TypeSystem\CecilLoader.cs" />
<Compile Include="TypeSystem\ClassType.cs" />
<Compile Include="TypeSystem\ConstructedType.cs" />
<Compile Include="TypeSystem\DomRegion.cs" />
<Compile Include="TypeSystem\EntityType.cs" />
<Compile Include="TypeSystem\IAttribute.cs" />
@ -159,25 +161,19 @@ @@ -159,25 +161,19 @@
<Compile Include="TypeSystem\Implementation\AbstractMember.cs" />
<Compile Include="TypeSystem\Implementation\AbstractType.cs" />
<Compile Include="TypeSystem\Implementation\AbstractTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\ArrayType.cs" />
<Compile Include="TypeSystem\Implementation\BitVector16.cs" />
<Compile Include="TypeSystem\Implementation\ConstructedType.cs" />
<Compile Include="TypeSystem\Implementation\DefaultExplicitInterfaceImplementation.cs" />
<Compile Include="TypeSystem\Implementation\DefaultMethod.cs" />
<Compile Include="TypeSystem\Implementation\DefaultParameter.cs" />
<Compile Include="TypeSystem\Implementation\DynamicType.cs" />
<Compile Include="TypeSystem\Implementation\GetClassTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\MultiTypeResolveContext.cs" />
<Compile Include="TypeSystem\Implementation\NestedTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\PointerType.cs" />
<Compile Include="TypeSystem\Implementation\ProxyTypeResolveContext.cs" />
<Compile Include="TypeSystem\Implementation\DefaultTypeDefinition.cs" />
<Compile Include="TypeSystem\Implementation\NullType.cs" />
<Compile Include="TypeSystem\Implementation\SimpleConstantValue.cs" />
<Compile Include="TypeSystem\Implementation\SimpleProjectContent.cs" />
<Compile Include="TypeSystem\Implementation\TypeStorage.cs" />
<Compile Include="TypeSystem\Implementation\TypeWithElementType.cs" />
<Compile Include="TypeSystem\Implementation\UnknownType.cs" />
<Compile Include="TypeSystem\INamedElement.cs" />
<Compile Include="TypeSystem\IParameter.cs" />
<Compile Include="TypeSystem\IParameterizedMember.cs" />
@ -191,6 +187,7 @@ @@ -191,6 +187,7 @@
<Compile Include="TypeSystem\ITypeReference.cs" />
<Compile Include="TypeSystem\ITypeResolveContext.cs" />
<Compile Include="TypeSystem\IVariable.cs" />
<Compile Include="TypeSystem\PointerType.cs" />
<Compile Include="TypeSystem\SharedTypes.cs" />
<Compile Include="CSharp\Parser\mcs\cs-parser.cs" />
<Compile Include="CSharp\Parser\mcs\expression.cs" />

3
ICSharpCode.NRefactory/TypeSystem/Implementation/ArrayType.cs → ICSharpCode.NRefactory/TypeSystem/ArrayType.cs

@ -2,8 +2,9 @@ @@ -2,8 +2,9 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Represents an array type.

4
ICSharpCode.NRefactory/TypeSystem/Implementation/ConstructedType.cs → ICSharpCode.NRefactory/TypeSystem/ConstructedType.cs

@ -8,7 +8,9 @@ using System.Diagnostics; @@ -8,7 +8,9 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// ConstructedType represents an instance of a generic type.

31
ICSharpCode.NRefactory/TypeSystem/Implementation/DynamicType.cs

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Type representing the C# 'dynamic' type.
/// </summary>
sealed class DynamicType : AbstractType
{
public override string Name {
get { return "dynamic"; }
}
public override bool? IsReferenceType {
get { return true; }
}
public override bool Equals(IType other)
{
return other is DynamicType;
}
public override int GetHashCode()
{
return 31986112;
}
}
}

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

@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
if (context == null)
throw new ArgumentNullException("context");
return context.GetClass(fullTypeName, typeParameterCount, StringComparer.Ordinal);
return context.GetClass(fullTypeName, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
}
public override string ToString()

31
ICSharpCode.NRefactory/TypeSystem/Implementation/NullType.cs

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Type of the 'null' literal.
/// </summary>
sealed class NullType : AbstractType
{
public override string Name {
get { return "null"; }
}
public override bool? IsReferenceType {
get { return true; }
}
public override bool Equals(IType other)
{
return other is NullType;
}
public override int GetHashCode()
{
return 362709548;
}
}
}

31
ICSharpCode.NRefactory/TypeSystem/Implementation/UnknownType.cs

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Type representing resolve errors.
/// </summary>
sealed class UnknownType : AbstractType
{
public override string Name {
get { return "?"; }
}
public override bool? IsReferenceType {
get { return null; }
}
public override bool Equals(IType other)
{
return other is UnknownType;
}
public override int GetHashCode()
{
return 950772036;
}
}
}

3
ICSharpCode.NRefactory/TypeSystem/Implementation/PointerType.cs → ICSharpCode.NRefactory/TypeSystem/PointerType.cs

@ -2,8 +2,9 @@ @@ -2,8 +2,9 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
namespace ICSharpCode.NRefactory.TypeSystem
{
public class PointerType : TypeWithElementType
{

76
ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs

@ -15,7 +15,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -15,7 +15,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Gets the type representing resolve errors.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "It's immutable")]
public readonly static IType UnknownType = new UnknownType();
public readonly static IType UnknownType = new UnknownTypeImpl();
/// <summary>
/// The null type is used as type of the null literal. It is a reference type without any members; and it is a subtype of all reference types.
@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
*
* SharedTypes.Void.GetDefinition().ProjectContent should return mscorlib, but
* we can't do that without providing a context.
*
* Assuming we add a context parameter to GetDefinition():
*
* SharedType.Void.Equals(SharedType.Void.GetDefinition(x))
@ -46,5 +47,78 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -46,5 +47,78 @@ namespace ICSharpCode.NRefactory.TypeSystem
* SharedType.Void.GetDefinition(x).Equals(SharedType.Void.GetDefinition(y))
* would have to return true even though these are two distinct definitions.
*/
/// <summary>
/// Type representing resolve errors.
/// </summary>
sealed class UnknownTypeImpl : AbstractType
{
public override string Name {
get { return "?"; }
}
public override bool? IsReferenceType {
get { return null; }
}
public override bool Equals(IType other)
{
return other is UnknownTypeImpl;
}
public override int GetHashCode()
{
return 950772036;
}
}
/// <summary>
/// Type of the 'null' literal.
/// </summary>
sealed class NullType : AbstractType
{
public override string Name {
get { return "null"; }
}
public override bool? IsReferenceType {
get { return true; }
}
public override bool Equals(IType other)
{
return other is NullType;
}
public override int GetHashCode()
{
return 362709548;
}
}
/// <summary>
/// Type representing the C# 'dynamic' type.
/// </summary>
sealed class DynamicType : AbstractType
{
public override string Name {
get { return "dynamic"; }
}
public override bool? IsReferenceType {
get { return true; }
}
public override bool Equals(IType other)
{
return other is DynamicType;
}
public override int GetHashCode()
{
return 31986112;
}
}
}
}

2
NRefactory.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.6362
# SharpDevelop 4.0.0.6721
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DC98210E-1646-483B-819A-2BB8272461E4}"
ProjectSection(SolutionItems) = postProject
README = README

Loading…
Cancel
Save