Browse Source

Rename ITypeResolveContext extension methods to be consistent with the new names of the ITypeResolveContext methods.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
c9d4a5d0c9
  1. 2
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  2. 6
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/TypeInferenceTests.cs
  3. 36
      ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs
  4. 10
      ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs
  5. 6
      ICSharpCode.NRefactory.Tests/TypeSystem/ReflectionHelperTests.cs
  6. 48
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  7. 150
      ICSharpCode.NRefactory.VB/Ast/AstNode.cs
  8. 2
      ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs
  9. 14
      ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs
  10. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  11. 14
      ICSharpCode.NRefactory/TypeSystem/ReflectionHelper.cs

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

@ -134,7 +134,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -134,7 +134,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public void FindTypeParameters()
{
resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
resolver.CurrentTypeDefinition = context.GetClass(typeof(List<>));
resolver.CurrentTypeDefinition = context.GetTypeDefinition(typeof(List<>));
resolver.CurrentMember = resolver.CurrentTypeDefinition.Methods.Single(m => m.Name == "ConvertAll");
TypeResolveResult trr;

6
ICSharpCode.NRefactory.Tests/CSharp/Resolver/TypeInferenceTests.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
ITypeParameter tp = new DefaultTypeParameter(EntityType.Method, 0, "T");
IType stringType = KnownTypeReference.String.Resolve(ctx);
ITypeDefinition enumerableType = ctx.GetClass(typeof(IEnumerable<>));
ITypeDefinition enumerableType = ctx.GetTypeDefinition(typeof(IEnumerable<>));
bool success;
Assert.AreEqual(
@ -58,8 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -58,8 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
ITypeParameter tp = new DefaultTypeParameter(EntityType.Method, 0, "T");
IType stringType = KnownTypeReference.String.Resolve(ctx);
ITypeDefinition enumerableType = ctx.GetClass(typeof(IEnumerable<>));
ITypeDefinition comparerType = ctx.GetClass(typeof(IComparer<>));
ITypeDefinition enumerableType = ctx.GetTypeDefinition(typeof(IEnumerable<>));
ITypeDefinition comparerType = ctx.GetTypeDefinition(typeof(IComparer<>));
var comparerOfIEnumerableOfString = new ParameterizedType(comparerType, new [] { new ParameterizedType(enumerableType, new [] { stringType} ) });
var comparerOfTpArray = new ParameterizedType(comparerType, new [] { new ArrayType(tp) });

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

@ -27,8 +27,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -27,8 +27,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void InheritanceTest()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(SystemException));
ITypeDefinition c2 = Mscorlib.GetClass(typeof(Exception));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(SystemException));
ITypeDefinition c2 = Mscorlib.GetTypeDefinition(typeof(Exception));
Assert.IsNotNull(c, "c is null");
Assert.IsNotNull(c2, "c2 is null");
//Assert.AreEqual(3, c.BaseTypes.Count); // Inherited interfaces are not reported by Cecil
@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void GenericPropertyTest()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(Comparer<>));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(Comparer<>));
IProperty def = c.Properties.Single(p => p.Name == "Default");
ParameterizedType pt = (ParameterizedType)def.ReturnType.Resolve(ctx);
Assert.AreEqual("System.Collections.Generic.Comparer", pt.FullName);
@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void PointerTypeTest()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(IntPtr));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(IntPtr));
IMethod toPointer = c.Methods.Single(p => p.Name == "ToPointer");
Assert.AreEqual("System.Void*", toPointer.ReturnType.Resolve(ctx).ReflectionName);
Assert.IsTrue (toPointer.ReturnType.Resolve(ctx) is PointerType);
@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void DateTimeDefaultConstructor()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(DateTime));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(DateTime));
Assert.IsFalse(c.Methods.Any(m => m.IsConstructor && m.Parameters.Count == 0)); // struct ctor isn't declared
// but it is implicit:
Assert.IsTrue(c.GetConstructors(ctx).Any(m => m.Parameters.Count == 0));
@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void NoEncodingInfoDefaultConstructor()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(EncodingInfo));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(EncodingInfo));
// EncodingInfo only has an internal constructor
Assert.IsFalse(c.Methods.Any(m => m.IsConstructor));
// and no implicit ctor should be added:
@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void StaticModifierTest()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(Environment));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(Environment));
Assert.IsNotNull(c, "System.Environment not found");
Assert.IsTrue(c.IsAbstract, "class should be abstract");
Assert.IsTrue(c.IsSealed, "class should be sealed");
@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void InnerClassReferenceTest()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(Environment));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(Environment));
Assert.IsNotNull(c, "System.Environment not found");
ITypeReference rt = c.Methods.First(m => m.Name == "GetFolderPath").Parameters[0].Type;
Assert.AreSame(c.NestedTypes.Single(ic => ic.Name == "SpecialFolder"), rt.Resolve(ctx));
@ -104,7 +104,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -104,7 +104,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void NestedTypesTest()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(Environment.SpecialFolder));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(Environment.SpecialFolder));
Assert.IsNotNull(c, "c is null");
Assert.AreEqual("System.Environment.SpecialFolder", c.FullName);
Assert.AreEqual("System.Environment+SpecialFolder", c.ReflectionName);
@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void VoidTest()
{
ITypeDefinition c = Mscorlib.GetClass(typeof(void));
ITypeDefinition c = Mscorlib.GetTypeDefinition(typeof(void));
Assert.IsNotNull(c, "System.Void not found");
Assert.AreEqual(0, c.GetMethods(ctx).Count());
Assert.AreEqual(0, c.GetProperties(ctx).Count());
@ -131,11 +131,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -131,11 +131,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void NestedClassInGenericClassTest()
{
ITypeDefinition dictionary = Mscorlib.GetClass(typeof(Dictionary<,>));
ITypeDefinition dictionary = Mscorlib.GetTypeDefinition(typeof(Dictionary<,>));
Assert.IsNotNull(dictionary);
ITypeDefinition valueCollection = Mscorlib.GetClass(typeof(Dictionary<,>.ValueCollection));
ITypeDefinition valueCollection = Mscorlib.GetTypeDefinition(typeof(Dictionary<,>.ValueCollection));
Assert.IsNotNull(valueCollection);
var dictionaryRT = new ParameterizedType(dictionary, new[] { Mscorlib.GetClass(typeof(string)), Mscorlib.GetClass(typeof(int)) });
var dictionaryRT = new ParameterizedType(dictionary, new[] { Mscorlib.GetTypeDefinition(typeof(string)), Mscorlib.GetTypeDefinition(typeof(int)) });
IProperty valueProperty = dictionaryRT.GetProperties(ctx).Single(p => p.Name == "Values");
IType parameterizedValueCollection = valueProperty.ReturnType.Resolve(ctx);
Assert.AreEqual("System.Collections.Generic.Dictionary`2+ValueCollection[[System.String],[System.Int32]]", parameterizedValueCollection.ReflectionName);
@ -145,7 +145,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -145,7 +145,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void ValueCollectionCountModifiers()
{
ITypeDefinition valueCollection = Mscorlib.GetClass(typeof(Dictionary<,>.ValueCollection));
ITypeDefinition valueCollection = Mscorlib.GetTypeDefinition(typeof(Dictionary<,>.ValueCollection));
Assert.AreEqual(Accessibility.Public, valueCollection.Accessibility);
Assert.IsTrue(valueCollection.IsSealed);
Assert.IsFalse(valueCollection.IsAbstract);
@ -162,7 +162,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -162,7 +162,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void MathAcosModifiers()
{
ITypeDefinition math = Mscorlib.GetClass(typeof(Math));
ITypeDefinition math = Mscorlib.GetTypeDefinition(typeof(Math));
Assert.AreEqual(Accessibility.Public, math.Accessibility);
Assert.IsTrue(math.IsSealed);
Assert.IsTrue(math.IsAbstract);
@ -180,7 +180,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -180,7 +180,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void EncodingModifiers()
{
ITypeDefinition encoding = Mscorlib.GetClass(typeof(Encoding));
ITypeDefinition encoding = Mscorlib.GetTypeDefinition(typeof(Encoding));
Assert.AreEqual(Accessibility.Public, encoding.Accessibility);
Assert.IsFalse(encoding.IsSealed);
Assert.IsTrue(encoding.IsAbstract);
@ -213,7 +213,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -213,7 +213,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void UnicodeEncodingModifiers()
{
ITypeDefinition encoding = Mscorlib.GetClass(typeof(UnicodeEncoding));
ITypeDefinition encoding = Mscorlib.GetTypeDefinition(typeof(UnicodeEncoding));
Assert.AreEqual(Accessibility.Public, encoding.Accessibility);
Assert.IsFalse(encoding.IsSealed);
Assert.IsFalse(encoding.IsAbstract);
@ -230,7 +230,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -230,7 +230,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void UTF32EncodingModifiers()
{
ITypeDefinition encoding = Mscorlib.GetClass(typeof(UTF32Encoding));
ITypeDefinition encoding = Mscorlib.GetTypeDefinition(typeof(UTF32Encoding));
Assert.AreEqual(Accessibility.Public, encoding.Accessibility);
Assert.IsTrue(encoding.IsSealed);
Assert.IsFalse(encoding.IsAbstract);

10
ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs

@ -100,8 +100,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -100,8 +100,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
c,
c.BaseTypes[0].Resolve(context),
c.BaseTypes[1].Resolve(context),
mscorlib.GetClass(typeof(IEnumerable)),
mscorlib.GetClass(typeof(object))
mscorlib.GetTypeDefinition(typeof(IEnumerable)),
mscorlib.GetTypeDefinition(typeof(object))
};
Assert.AreEqual(expected,
c.GetAllBaseTypes(context).OrderBy(t => t.ReflectionName).ToArray());
@ -114,12 +114,12 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -114,12 +114,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
// don't use a Cecil-loaded struct for this test; we're testing the implicit addition of System.ValueType
DefaultTypeDefinition s = new DefaultTypeDefinition(mscorlib, string.Empty, "S");
s.ClassType = ClassType.Struct;
s.BaseTypes.Add(new ParameterizedType(mscorlib.GetClass(typeof(IEquatable<>)), new[] { s }));
s.BaseTypes.Add(new ParameterizedType(mscorlib.GetTypeDefinition(typeof(IEquatable<>)), new[] { s }));
IType[] expected = {
s,
s.BaseTypes[0].Resolve(context),
mscorlib.GetClass(typeof(object)),
mscorlib.GetClass(typeof(ValueType))
mscorlib.GetTypeDefinition(typeof(object)),
mscorlib.GetTypeDefinition(typeof(ValueType))
};
Assert.AreEqual(expected,
s.GetAllBaseTypes(context).OrderBy(t => t.ReflectionName).ToArray());

6
ICSharpCode.NRefactory.Tests/TypeSystem/ReflectionHelperTests.cs

@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
void TestGetClass(Type type)
{
ITypeDefinition t = CecilLoaderTests.Mscorlib.GetClass(type);
ITypeDefinition t = CecilLoaderTests.Mscorlib.GetTypeDefinition(type);
Assert.IsNotNull(t, type.FullName);
Assert.AreEqual(type.FullName, t.ReflectionName);
}
@ -142,7 +142,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -142,7 +142,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.AreEqual("System.Converter`2[[?],[?]]",
parameterType.ToTypeReference().Resolve(context).ReflectionName);
// now try with parent entity:
IMethod convertAll = context.GetClass(typeof(List<>)).Methods.Single(m => m.Name == "ConvertAll");
IMethod convertAll = context.GetTypeDefinition(typeof(List<>)).Methods.Single(m => m.Name == "ConvertAll");
Assert.AreEqual("System.Converter`2[[`0],[``0]]",
parameterType.ToTypeReference(entity: convertAll).Resolve(context).ReflectionName);
}
@ -163,7 +163,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -163,7 +163,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void ParseOpenGenericReflectionName()
{
IMethod convertAll = context.GetClass(typeof(List<>)).Methods.Single(m => m.Name == "ConvertAll");
IMethod convertAll = context.GetTypeDefinition(typeof(List<>)).Methods.Single(m => m.Name == "ConvertAll");
Assert.AreEqual("System.Converter`2[[?],[?]]", ReflectionHelper.ParseReflectionName("System.Converter`2[[`0],[``0]]").Resolve(context).ReflectionName);
Assert.AreEqual("System.Converter`2[[`0],[``0]]", ReflectionHelper.ParseReflectionName("System.Converter`2[[`0],[``0]]", convertAll).Resolve(context).ReflectionName);
}

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

@ -28,13 +28,13 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -28,13 +28,13 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition GetClass(Type type)
{
return testCasePC.GetClass(type);
return testCasePC.GetTypeDefinition(type);
}
[Test]
public void SimplePublicClassTest()
{
ITypeDefinition c = testCasePC.GetClass(typeof(SimplePublicClass));
ITypeDefinition c = testCasePC.GetTypeDefinition(typeof(SimplePublicClass));
Assert.AreEqual(typeof(SimplePublicClass).Name, c.Name);
Assert.AreEqual(typeof(SimplePublicClass).FullName, c.FullName);
Assert.AreEqual(typeof(SimplePublicClass).Namespace, c.Namespace);
@ -50,7 +50,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -50,7 +50,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void SimplePublicClassMethodTest()
{
ITypeDefinition c = testCasePC.GetClass(typeof(SimplePublicClass));
ITypeDefinition c = testCasePC.GetTypeDefinition(typeof(SimplePublicClass));
IMethod method = c.Methods.Single(m => m.Name == "Method");
Assert.AreEqual(typeof(SimplePublicClass).FullName + ".Method", method.FullName);
@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void DynamicType()
{
ITypeDefinition testClass = testCasePC.GetClass(typeof(DynamicTest));
ITypeDefinition testClass = testCasePC.GetTypeDefinition(typeof(DynamicTest));
Assert.AreSame(SharedTypes.Dynamic, testClass.Properties.Single().ReturnType.Resolve(ctx));
Assert.AreEqual(0, testClass.Properties.Single().Attributes.Count);
}
@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void DynamicTypeInGenerics()
{
ITypeDefinition testClass = testCasePC.GetClass(typeof(DynamicTest));
ITypeDefinition testClass = testCasePC.GetTypeDefinition(typeof(DynamicTest));
IMethod m1 = testClass.Methods.Single(me => me.Name == "DynamicGenerics1");
Assert.AreEqual("System.Collections.Generic.List`1[[dynamic]]", m1.ReturnType.Resolve(ctx).ReflectionName);
@ -103,7 +103,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -103,7 +103,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void DynamicParameterHasNoAttributes()
{
ITypeDefinition testClass = testCasePC.GetClass(typeof(DynamicTest));
ITypeDefinition testClass = testCasePC.GetTypeDefinition(typeof(DynamicTest));
IMethod m1 = testClass.Methods.Single(me => me.Name == "DynamicGenerics1");
Assert.AreEqual(0, m1.Parameters[0].Attributes.Count);
}
@ -133,7 +133,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -133,7 +133,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void TestClassTypeParameters()
{
var testClass = testCasePC.GetClass(typeof(GenericClass<,>));
var testClass = testCasePC.GetTypeDefinition(typeof(GenericClass<,>));
Assert.AreEqual(EntityType.TypeDefinition, testClass.TypeParameters[0].OwnerType);
Assert.AreEqual(EntityType.TypeDefinition, testClass.TypeParameters[1].OwnerType);
Assert.AreSame(testClass.TypeParameters[1], testClass.TypeParameters[0].Constraints[0].Resolve(ctx));
@ -142,7 +142,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -142,7 +142,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void TestMethod()
{
var testClass = testCasePC.GetClass(typeof(GenericClass<,>));
var testClass = testCasePC.GetTypeDefinition(typeof(GenericClass<,>));
IMethod m = testClass.Methods.Single(me => me.Name == "TestMethod");
Assert.AreEqual("K", m.TypeParameters[0].Name);
@ -157,7 +157,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -157,7 +157,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void GetIndex()
{
var testClass = testCasePC.GetClass(typeof(GenericClass<,>));
var testClass = testCasePC.GetTypeDefinition(typeof(GenericClass<,>));
IMethod m = testClass.Methods.Single(me => me.Name == "GetIndex");
Assert.AreEqual("T", m.TypeParameters[0].Name);
@ -173,7 +173,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -173,7 +173,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void PropertyWithProtectedSetter()
{
var testClass = testCasePC.GetClass(typeof(PropertyTest));
var testClass = testCasePC.GetTypeDefinition(typeof(PropertyTest));
IProperty p = testClass.Properties.Single(pr => pr.Name == "PropertyWithProtectedSetter");
Assert.IsTrue(p.CanGet);
Assert.IsTrue(p.CanSet);
@ -185,7 +185,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -185,7 +185,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void PropertyWithPrivateSetter()
{
var testClass = testCasePC.GetClass(typeof(PropertyTest));
var testClass = testCasePC.GetTypeDefinition(typeof(PropertyTest));
IProperty p = testClass.Properties.Single(pr => pr.Name == "PropertyWithPrivateSetter");
Assert.IsTrue(p.CanGet);
Assert.IsTrue(p.CanSet);
@ -197,7 +197,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -197,7 +197,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void Indexer()
{
var testClass = testCasePC.GetClass(typeof(PropertyTest));
var testClass = testCasePC.GetTypeDefinition(typeof(PropertyTest));
IProperty p = testClass.Properties.Single(pr => pr.IsIndexer);
Assert.IsTrue(p.CanGet);
Assert.AreEqual(Accessibility.Public, p.Accessibility);
@ -209,7 +209,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -209,7 +209,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void EnumTest()
{
var e = testCasePC.GetClass(typeof(MyEnum));
var e = testCasePC.GetTypeDefinition(typeof(MyEnum));
Assert.AreEqual(ClassType.Enum, e.ClassType);
Assert.AreEqual(false, e.IsReferenceType);
Assert.AreEqual("System.Int16", e.BaseTypes[0].Resolve(ctx).ReflectionName);
@ -219,7 +219,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -219,7 +219,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void EnumFieldsTest()
{
var e = testCasePC.GetClass(typeof(MyEnum));
var e = testCasePC.GetTypeDefinition(typeof(MyEnum));
Assert.AreEqual(5, e.Fields.Count);
foreach (IField f in e.Fields) {
@ -266,21 +266,21 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -266,21 +266,21 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void SerializableAttribute()
{
IAttribute attr = ctx.GetClass(typeof(NonCustomAttributes)).Attributes.Single();
IAttribute attr = ctx.GetTypeDefinition(typeof(NonCustomAttributes)).Attributes.Single();
Assert.AreEqual("System.SerializableAttribute", attr.AttributeType.Resolve(ctx).FullName);
}
[Test]
public void NonSerializedAttribute()
{
IField field = ctx.GetClass(typeof(NonCustomAttributes)).Fields.Single(f => f.Name == "NonSerializedField");
IField field = ctx.GetTypeDefinition(typeof(NonCustomAttributes)).Fields.Single(f => f.Name == "NonSerializedField");
Assert.AreEqual("System.NonSerializedAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName);
}
[Test]
public void ExplicitStructLayoutAttribute()
{
IAttribute attr = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Attributes.Single();
IAttribute attr = ctx.GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Attributes.Single();
Assert.AreEqual("System.Runtime.InteropServices.StructLayoutAttribute", attr.AttributeType.Resolve(ctx).FullName);
IConstantValue arg1 = attr.GetPositionalArguments(ctx).Single();
Assert.AreEqual("System.Runtime.InteropServices.LayoutKind", arg1.GetValueType(ctx).FullName);
@ -301,13 +301,13 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -301,13 +301,13 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void FieldOffsetAttribute()
{
IField field = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field0");
IField field = ctx.GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field0");
Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName);
IConstantValue arg = field.Attributes.Single().GetPositionalArguments(ctx).Single();
Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName);
Assert.AreEqual(0, arg.GetValue(ctx));
field = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field100");
field = ctx.GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field100");
Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName);
arg = field.Attributes.Single().GetPositionalArguments(ctx).Single();
Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName);
@ -317,7 +317,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -317,7 +317,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void DllImportAttribute()
{
IMethod method = ctx.GetClass(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod");
IMethod method = ctx.GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod");
IAttribute dllImport = method.Attributes.Single();
Assert.AreEqual("System.Runtime.InteropServices.DllImportAttribute", dllImport.AttributeType.Resolve(ctx).FullName);
Assert.AreEqual("unmanaged.dll", dllImport.GetPositionalArguments(ctx)[0].GetValue(ctx));
@ -327,7 +327,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -327,7 +327,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void InOutParametersOnRefMethod()
{
IParameter p = ctx.GetClass(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod").Parameters.Single();
IParameter p = ctx.GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod").Parameters.Single();
Assert.IsTrue(p.IsRef);
Assert.IsFalse(p.IsOut);
Assert.AreEqual(2, p.Attributes.Count);
@ -338,7 +338,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -338,7 +338,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void MarshalAsAttributeOnMethod()
{
IMethod method = ctx.GetClass(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod");
IMethod method = ctx.GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod");
IAttribute marshalAs = method.ReturnTypeAttributes.Single();
Assert.AreEqual((int)UnmanagedType.Bool, marshalAs.GetPositionalArguments(ctx).Single().GetValue(ctx));
}
@ -346,7 +346,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -346,7 +346,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void MethodWithOutParameter()
{
IParameter p = ctx.GetClass(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOutParameter").Parameters.Single();
IParameter p = ctx.GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOutParameter").Parameters.Single();
Assert.IsFalse(p.IsRef);
Assert.IsTrue(p.IsOut);
Assert.AreEqual(0, p.Attributes.Count);
@ -356,7 +356,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -356,7 +356,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void MethodWithParamsArray()
{
IParameter p = ctx.GetClass(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithParamsArray").Parameters.Single();
IParameter p = ctx.GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithParamsArray").Parameters.Single();
Assert.IsFalse(p.IsRef);
Assert.IsFalse(p.IsOut);
Assert.IsTrue(p.IsParams);

150
ICSharpCode.NRefactory.VB/Ast/AstNode.cs

@ -35,7 +35,7 @@ using ICSharpCode.NRefactory.VB.Ast; @@ -35,7 +35,7 @@ using ICSharpCode.NRefactory.VB.Ast;
namespace ICSharpCode.NRefactory.VB
{
public abstract class AstNode : PatternMatching.INode
public abstract class AstNode : AbstractAnnotatable, PatternMatching.INode
{
#region Null
public static readonly AstNode Null = new NullAstNode ();
@ -443,157 +443,13 @@ namespace ICSharpCode.NRefactory.VB @@ -443,157 +443,13 @@ namespace ICSharpCode.NRefactory.VB
return copy;
}
#region Annotation support
// Annotations: points either null (no annotations), to the single annotation,
// or to an AnnotationList.
// Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list)
object annotations;
sealed class AnnotationList : List<object>, ICloneable
{
// There are two uses for this custom list type:
// 1) it's private, and thus (unlike List<object>) cannot be confused with real annotations
// 2) It allows us to simplify the cloning logic by making the list behave the same as a clonable annotation.
public AnnotationList(int initialCapacity) : base(initialCapacity)
{
}
public object Clone()
{
lock (this) {
AnnotationList copy = new AnnotationList(this.Count);
for (int i = 0; i < this.Count; i++) {
object obj = this[i];
ICloneable c = obj as ICloneable;
copy.Add(c != null ? c.Clone() : obj);
}
return copy;
}
}
}
public void AddAnnotation(object annotation)
public override void AddAnnotation (object annotation)
{
if (annotation == null)
throw new ArgumentNullException("annotation");
if (this.IsNull)
throw new InvalidOperationException("Cannot add annotations to the null node");
retry: // Retry until successful
object oldAnnotation = Interlocked.CompareExchange(ref this.annotations, annotation, null);
if (oldAnnotation == null) {
return; // we successfully added a single annotation
}
AnnotationList list = oldAnnotation as AnnotationList;
if (list == null) {
// we need to transform the old annotation into a list
list = new AnnotationList(4);
list.Add(oldAnnotation);
list.Add(annotation);
if (Interlocked.CompareExchange(ref this.annotations, list, oldAnnotation) != oldAnnotation) {
// the transformation failed (some other thread wrote to this.annotations first)
goto retry;
}
} else {
// once there's a list, use simple locking
lock (list) {
list.Add(annotation);
}
}
}
public void RemoveAnnotations<T>() where T : class
{
retry: // Retry until successful
object oldAnnotations = this.annotations;
AnnotationList list = oldAnnotations as AnnotationList;
if (list != null) {
lock (list)
list.RemoveAll(obj => obj is T);
} else if (oldAnnotations is T) {
if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) {
// Operation failed (some other thread wrote to this.annotations first)
goto retry;
}
}
base.AddAnnotation (annotation);
}
public void RemoveAnnotations(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
retry: // Retry until successful
object oldAnnotations = this.annotations;
AnnotationList list = oldAnnotations as AnnotationList;
if (list != null) {
lock (list)
list.RemoveAll(obj => type.IsInstanceOfType(obj));
} else if (type.IsInstanceOfType(oldAnnotations)) {
if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) {
// Operation failed (some other thread wrote to this.annotations first)
goto retry;
}
}
}
public T Annotation<T>() where T: class
{
object annotations = this.annotations;
AnnotationList list = annotations as AnnotationList;
if (list != null) {
lock (list) {
foreach (object obj in list) {
T t = obj as T;
if (t != null)
return t;
}
return null;
}
} else {
return annotations as T;
}
}
public object Annotation(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
object annotations = this.annotations;
AnnotationList list = annotations as AnnotationList;
if (list != null) {
lock (list) {
foreach (object obj in list) {
if (type.IsInstanceOfType(obj))
return obj;
}
}
} else {
if (type.IsInstanceOfType(annotations))
return annotations;
}
return null;
}
/// <summary>
/// Gets all annotations stored on this AstNode.
/// </summary>
public IEnumerable<object> Annotations {
get {
object annotations = this.annotations;
AnnotationList list = annotations as AnnotationList;
if (list != null) {
lock (list) {
return list.ToArray();
}
} else {
if (annotations != null)
return new object[] { annotations };
else
return Enumerable.Empty<object>();
}
}
}
#endregion
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data);
#region Pattern Matching

2
ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs

@ -833,7 +833,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -833,7 +833,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
candidateTypeDefinitions = hashSet.ToList();
} else {
// Find candidates by looking at all classes in the project:
candidateTypeDefinitions = context.GetAllClasses().ToList();
candidateTypeDefinitions = context.GetAllTypes().ToList();
}
// Now filter out candidates that violate the upper bounds:

14
ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs

@ -210,11 +210,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -210,11 +210,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
#endregion
#region GetAllClasses
#region GetAllTypes
/// <summary>
/// Gets all classes, including nested classes.
/// Gets all type definitions, including nested types.
/// </summary>
public static IEnumerable<ITypeDefinition> GetAllClasses(this ITypeResolveContext context)
public static IEnumerable<ITypeDefinition> GetAllTypes(this ITypeResolveContext context)
{
return TreeTraversal.PreOrder(context.GetTypes(), t => t.NestedTypes);
}
@ -248,9 +248,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -248,9 +248,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
public static IEnumerable<IMember> GetMembers (this IType type, ITypeResolveContext context, Predicate<IMember> filter = null)
{
return type.GetFields (context, filter).SafeCast<IField, IMember> ()
.Concat (type.GetProperties (context, filter).SafeCast<IProperty, IMember> ())
.Concat (type.GetMethods (context, filter).SafeCast<IMethod, IMember> ())
.Concat (type.GetEvents (context, filter).SafeCast<IEvent, IMember> ());
.Concat (type.GetProperties (context, filter).SafeCast<IProperty, IMember> ())
.Concat (type.GetMethods (context, filter).SafeCast<IMethod, IMember> ())
.Concat (type.GetEvents (context, filter).SafeCast<IEvent, IMember> ());
}
#endregion
@ -260,7 +260,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -260,7 +260,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
public static IEnumerable<ITypeDefinition> GetSubTypeDefinitions (this ITypeDefinition baseType, ITypeResolveContext context)
{
foreach (var contextType in context.GetAllClasses ()) {
foreach (var contextType in context.GetAllTypes ()) {
if (contextType.IsDerivedFrom (baseType, context))
yield return contextType;
}

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

@ -377,7 +377,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -377,7 +377,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
primitiveBaseType = typeof(object);
break;
}
IType t = context.GetClass(primitiveBaseType);
IType t = context.GetTypeDefinition(primitiveBaseType);
if (t != null)
yield return t;
}

14
ICSharpCode.NRefactory/TypeSystem/ReflectionHelper.cs

@ -23,12 +23,16 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -23,12 +23,16 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
public sealed class Dynamic {}
#region ITypeResolveContext.GetClass(Type)
#region ITypeResolveContext.GetTypeDefinition(Type)
/// <summary>
/// Retrieves a class.
/// Retrieves a type definition.
/// </summary>
/// <returns>Returns the class; or null if it is not found.</returns>
public static ITypeDefinition GetClass(this ITypeResolveContext context, Type type)
/// <returns>Returns the type definition; or null if it is not found.</returns>
/// <remarks>
/// This method retrieves the type definition; consider using <code>type.ToTypeReference().Resolve(context)</code> instead
/// if you need an <see cref="IType"/>.
/// </remarks>
public static ITypeDefinition GetTypeDefinition(this ITypeResolveContext context, Type type)
{
if (type == null)
return null;
@ -39,7 +43,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -39,7 +43,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
if (type.IsGenericParameter)
return null;
if (type.DeclaringType != null) {
ITypeDefinition declaringType = GetClass(context, type.DeclaringType);
ITypeDefinition declaringType = GetTypeDefinition(context, type.DeclaringType);
if (declaringType != null) {
int typeParameterCount;
string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);

Loading…
Cancel
Save