Browse Source

Fixed bug in type system conversion (interface members can shadow

other members) & implement interface action bug.
pull/32/merge
Mike Krüger 13 years ago
parent
commit
ecc15dde9a
  1. 11
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementInterfaceAction.cs
  2. 3
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  3. 73
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ImplementInterfaceTests.cs

11
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementInterfaceAction.cs

@ -158,9 +158,16 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
bool needsExplicitly = explicitly; bool needsExplicitly = explicitly;
alreadyImplemented = false; alreadyImplemented = false;
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) { foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
if (t.Kind == TypeKind.Interface) if (t.Kind == TypeKind.Interface) {
foreach (var cprop in t.Properties) {
if (cprop.Name == prop.Name && cprop.IsShadowing) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;
}
}
continue; continue;
foreach (IProperty cprop in t.Properties) { }
foreach (var cprop in t.Properties) {
if (cprop.Name == prop.Name) { if (cprop.Name == prop.Name) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType)) if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true; needsExplicitly = true;

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

@ -811,10 +811,11 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
static void ApplyModifiers(AbstractUnresolvedMember m, Modifiers modifiers) static void ApplyModifiers(AbstractUnresolvedMember m, Modifiers modifiers)
{ {
// members from interfaces are always Public+Abstract. // members from interfaces are always Public+Abstract. (NOTE: 'new' modifier is valid in interfaces as well.)
if (m.DeclaringTypeDefinition.Kind == TypeKind.Interface) { if (m.DeclaringTypeDefinition.Kind == TypeKind.Interface) {
m.Accessibility = Accessibility.Public; m.Accessibility = Accessibility.Public;
m.IsAbstract = true; m.IsAbstract = true;
m.IsShadowing = (modifiers & Modifiers.New) != 0;
return; return;
} }
m.Accessibility = GetAccessibility(modifiers) ?? Accessibility.Private; m.Accessibility = GetAccessibility(modifiers) ?? Accessibility.Private;

73
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ImplementInterfaceTests.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
[TestFixture] [TestFixture]
public class ImplementInterfaceTests : ContextActionTestBase public class ImplementInterfaceTests : ContextActionTestBase
{ {
[Test()] [Test]
public void TestSimpleInterface() public void TestSimpleInterface()
{ {
Test<ImplementInterfaceAction>(@"using System; Test<ImplementInterfaceAction>(@"using System;
@ -56,7 +56,7 @@ class Foo : IDisposable
/// <summary> /// <summary>
/// Bug 663842 - Interface implementation does not include constraints /// Bug 663842 - Interface implementation does not include constraints
/// </summary> /// </summary>
[Test()] [Test]
public void TestBug663842() public void TestBug663842()
{ {
Test<ImplementInterfaceAction>(@"using System; Test<ImplementInterfaceAction>(@"using System;
@ -105,7 +105,7 @@ class Foo : ITest
/// <summary> /// <summary>
/// Bug 683007 - "Refactor/Implement implicit" creates explicit implementations of methods with same names /// Bug 683007 - "Refactor/Implement implicit" creates explicit implementations of methods with same names
/// </summary> /// </summary>
[Test()] [Test]
public void TestBug683007() public void TestBug683007()
{ {
Test<ImplementInterfaceAction>(@"interface ITest { Test<ImplementInterfaceAction>(@"interface ITest {
@ -138,7 +138,7 @@ class Foo : ITest
/// <summary> /// <summary>
/// Bug 243 - Implement implicit interface doesn't handle overloads correctly. /// Bug 243 - Implement implicit interface doesn't handle overloads correctly.
/// </summary> /// </summary>
[Test()] [Test]
public void TestBug243() public void TestBug243()
{ {
Test<ImplementInterfaceAction>(@"interface ITest { Test<ImplementInterfaceAction>(@"interface ITest {
@ -174,7 +174,7 @@ class Foo : ITest
/// <summary> /// <summary>
/// Bug 2074 - [Regression] Implement Interface implicitly does not check the methods already exist /// Bug 2074 - [Regression] Implement Interface implicitly does not check the methods already exist
/// </summary> /// </summary>
[Test()] [Test]
public void TestBug2074() public void TestBug2074()
{ {
Test<ImplementInterfaceAction>(@"interface ITest { Test<ImplementInterfaceAction>(@"interface ITest {
@ -205,7 +205,7 @@ class Foo : ITest
/// <summary> /// <summary>
/// Bug 3365 - MD cannot implement IEnumerable interface correctly - MD cannot implement IEnumerable interface correctly /// Bug 3365 - MD cannot implement IEnumerable interface correctly - MD cannot implement IEnumerable interface correctly
/// </summary> /// </summary>
[Test()] [Test]
public void TestBug3365() public void TestBug3365()
{ {
Test<ImplementInterfaceAction>(@"using System; Test<ImplementInterfaceAction>(@"using System;
@ -255,7 +255,7 @@ class Foo : ITest
/// <summary> /// <summary>
/// Bug 4818 - Implement implicit does not handle 'params' types /// Bug 4818 - Implement implicit does not handle 'params' types
/// </summary> /// </summary>
[Test()] [Test]
public void TestBug4818() public void TestBug4818()
{ {
Test<ImplementInterfaceAction>(@"using System; Test<ImplementInterfaceAction>(@"using System;
@ -302,7 +302,7 @@ class Foo : $ITest
/// <summary> /// <summary>
/// Bug 9117 - [3.0.5] C#: Implementing interfaces inheriting from other interfaces /// Bug 9117 - [3.0.5] C#: Implementing interfaces inheriting from other interfaces
/// </summary> /// </summary>
[Test()] [Test]
public void TestBug9117() public void TestBug9117()
{ {
Test<ImplementInterfaceAction>(@"using System; Test<ImplementInterfaceAction>(@"using System;
@ -387,6 +387,63 @@ class Foo : $ITest
} }
"); ");
} }
/// <summary>
/// Bug 9603 - Implement interface cannot deal with member hidding
/// </summary>
[Test]
public void TestBug9603()
{
Test<ImplementInterfaceAction>(@"using System;
public interface IA
{
string this[int index] { get; set; }
}
public interface IB : IA
{
new int this[int index] { get; set; }
}
class M : $IB
{
}", @"using System;
public interface IA
{
string this[int index] { get; set; }
}
public interface IB : IA
{
new int this[int index] { get; set; }
}
class M : IB
{
#region IB implementation
public int this [int index] {
get {
throw new NotImplementedException ();
}
set {
throw new NotImplementedException ();
}
}
#endregion
#region IA implementation
string IA.this [int index] {
get {
throw new NotImplementedException ();
}
set {
throw new NotImplementedException ();
}
}
#endregion
}");
}
} }
} }

Loading…
Cancel
Save