Browse Source

Fixed IsExplicitInterfaceImplementation.

Implemented IMember.InterfaceImplementations for explicitly implemented members.
newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
3b95e5a2e3
  1. 4
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  2. 10
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
  3. 5
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs
  4. 6
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  5. 12
      ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs
  6. 20
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedMember.cs

4
ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

@ -420,6 +420,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ConvertParameters(m.Parameters, methodDeclaration.Parameters); ConvertParameters(m.Parameters, methodDeclaration.Parameters);
if (!methodDeclaration.PrivateImplementationType.IsNull) { if (!methodDeclaration.PrivateImplementationType.IsNull) {
m.Accessibility = Accessibility.None; m.Accessibility = Accessibility.None;
m.IsExplicitInterfaceImplementation = true;
m.ExplicitInterfaceImplementations.Add(new DefaultMemberReference( m.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
m.EntityType, ConvertType(methodDeclaration.PrivateImplementationType), m.Name, m.EntityType, ConvertType(methodDeclaration.PrivateImplementationType), m.Name,
m.TypeParameters.Count, GetParameterTypes(m.Parameters))); m.TypeParameters.Count, GetParameterTypes(m.Parameters)));
@ -597,6 +598,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ConvertAttributes(p.Attributes, propertyDeclaration.Attributes); ConvertAttributes(p.Attributes, propertyDeclaration.Attributes);
if (!propertyDeclaration.PrivateImplementationType.IsNull) { if (!propertyDeclaration.PrivateImplementationType.IsNull) {
p.Accessibility = Accessibility.None; p.Accessibility = Accessibility.None;
p.IsExplicitInterfaceImplementation = true;
p.ExplicitInterfaceImplementations.Add(new DefaultMemberReference( p.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
p.EntityType, ConvertType(propertyDeclaration.PrivateImplementationType), p.Name)); p.EntityType, ConvertType(propertyDeclaration.PrivateImplementationType), p.Name));
} }
@ -625,6 +627,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
if (!indexerDeclaration.PrivateImplementationType.IsNull) { if (!indexerDeclaration.PrivateImplementationType.IsNull) {
p.Accessibility = Accessibility.None; p.Accessibility = Accessibility.None;
p.IsExplicitInterfaceImplementation = true;
p.ExplicitInterfaceImplementations.Add(new DefaultMemberReference( p.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
p.EntityType, ConvertType(indexerDeclaration.PrivateImplementationType), p.Name, 0, GetParameterTypes(p.Parameters))); p.EntityType, ConvertType(indexerDeclaration.PrivateImplementationType), p.Name, 0, GetParameterTypes(p.Parameters)));
} }
@ -726,6 +729,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
if (!eventDeclaration.PrivateImplementationType.IsNull) { if (!eventDeclaration.PrivateImplementationType.IsNull) {
e.Accessibility = Accessibility.None; e.Accessibility = Accessibility.None;
e.IsExplicitInterfaceImplementation = true;
e.ExplicitInterfaceImplementations.Add(new DefaultMemberReference( e.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
e.EntityType, ConvertType(eventDeclaration.PrivateImplementationType), e.Name)); e.EntityType, ConvertType(eventDeclaration.PrivateImplementationType), e.Name));
} }

10
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

@ -18,6 +18,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.Utils; using ICSharpCode.NRefactory.Utils;
@ -50,6 +51,15 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib }) .AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib })
.SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name); .SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name);
} }
[Test]
public void ExplicitDisposableImplementation()
{
ITypeDefinition disposable = GetTypeDefinition(typeof(NRefactory.TypeSystem.TestCase.ExplicitDisposableImplementation));
IMethod method = disposable.Methods.Single(m => m.Name == "Dispose");
Assert.IsTrue(method.IsExplicitInterfaceImplementation);
Assert.AreEqual("System.IDisposable.Dispose", method.InterfaceImplementations.Single().FullName);
}
} }
[TestFixture] [TestFixture]

5
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs

@ -161,4 +161,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase
public Inner Field2; public Inner Field2;
public OuterGeneric<OuterGeneric<X>.Inner>.Inner Field3; public OuterGeneric<OuterGeneric<X>.Inner>.Inner Field3;
} }
public class ExplicitDisposableImplementation : IDisposable
{
void IDisposable.Dispose() {}
}
} }

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

@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
protected ICompilation compilation; protected ICompilation compilation;
ITypeDefinition GetTypeDefinition(Type type) protected ITypeDefinition GetTypeDefinition(Type type)
{ {
return compilation.FindType(type).GetDefinition(); return compilation.FindType(type).GetDefinition();
} }
@ -556,7 +556,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
ResolveResult GetParamsAttributeArgument(int index) ResolveResult GetParamsAttributeArgument(int index)
{ {
ITypeDefinition type = GetTypeDefinition(typeof(ParamsAttribute)).GetDefinition(); ITypeDefinition type = GetTypeDefinition(typeof(ParamsAttribute));
var arr = (ArrayCreateResolveResult)type.Attributes.Single().PositionalArguments.Single(); var arr = (ArrayCreateResolveResult)type.Attributes.Single().PositionalArguments.Single();
Assert.AreEqual(5, arr.InitializerElements.Length); Assert.AreEqual(5, arr.InitializerElements.Length);
return arr.InitializerElements[index]; return arr.InitializerElements[index];
@ -616,7 +616,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test] [Test]
public void DoubleAttribute_ImplicitNumericConversion() public void DoubleAttribute_ImplicitNumericConversion()
{ {
ITypeDefinition type = GetTypeDefinition(typeof(DoubleAttribute)).GetDefinition(); ITypeDefinition type = GetTypeDefinition(typeof(DoubleAttribute));
var arg = type.Attributes.Single().PositionalArguments.ElementAt(0); var arg = type.Attributes.Single().PositionalArguments.ElementAt(0);
Assert.AreEqual("System.Double", arg.Type.ReflectionName); Assert.AreEqual("System.Double", arg.Type.ReflectionName);
Assert.AreEqual(1.0, arg.ConstantValue); Assert.AreEqual(1.0, arg.ConstantValue);

12
ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs

@ -328,8 +328,20 @@ namespace ICSharpCode.NRefactory.TypeSystem
return new ProjectedList<ITypeResolveContext, ITypeReference, IType>(context, typeReferences, (c, t) => t.Resolve(c)); return new ProjectedList<ITypeResolveContext, ITypeReference, IType>(context, typeReferences, (c, t) => t.Resolve(c));
} }
public static IList<IMember> Resolve(this IList<IMemberReference> memberReferences, ITypeResolveContext context)
{
if (memberReferences == null)
throw new ArgumentNullException("memberReferences");
if (memberReferences.Count == 0)
return EmptyList<IMember>.Instance;
else
return new ProjectedList<ITypeResolveContext, IMemberReference, IMember>(context, memberReferences, (c, t) => t.Resolve(c));
}
public static IList<ResolveResult> Resolve(this IList<IConstantValue> constantValues, ITypeResolveContext context) public static IList<ResolveResult> Resolve(this IList<IConstantValue> constantValues, ITypeResolveContext context)
{ {
if (constantValues == null)
throw new ArgumentNullException("constantValues");
if (constantValues.Count == 0) if (constantValues.Count == 0)
return EmptyList<ResolveResult>.Instance; return EmptyList<ResolveResult>.Instance;
else else

20
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedMember.cs

@ -30,7 +30,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
protected new readonly IUnresolvedMember unresolved; protected new readonly IUnresolvedMember unresolved;
protected readonly ITypeResolveContext context; protected readonly ITypeResolveContext context;
volatile IType returnType; volatile IType returnType;
IList<IMember> interfaceImplementations;
protected AbstractResolvedMember(IUnresolvedMember unresolved, ITypeResolveContext parentContext) protected AbstractResolvedMember(IUnresolvedMember unresolved, ITypeResolveContext parentContext)
: base(unresolved, parentContext) : base(unresolved, parentContext)
{ {
@ -52,8 +53,23 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return unresolved; } get { return unresolved; }
} }
IList<IMember> IMember.InterfaceImplementations { public IList<IMember> InterfaceImplementations {
get { get {
IList<IMember> result = this.interfaceImplementations;
if (result != null) {
LazyInit.ReadBarrier();
return result;
} else {
return LazyInit.GetOrSet(ref interfaceImplementations, FindInterfaceImplementations());
}
}
}
IList<IMember> FindInterfaceImplementations()
{
if (unresolved.IsExplicitInterfaceImplementation) {
return unresolved.ExplicitInterfaceImplementations.Resolve(context);
} else {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }

Loading…
Cancel
Save