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 @@ -158,9 +158,16 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
bool needsExplicitly = explicitly;
alreadyImplemented = false;
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;
foreach (IProperty cprop in t.Properties) {
}
foreach (var cprop in t.Properties) {
if (cprop.Name == prop.Name) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;

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

@ -811,10 +811,11 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -811,10 +811,11 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
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) {
m.Accessibility = Accessibility.Public;
m.IsAbstract = true;
m.IsShadowing = (modifiers & Modifiers.New) != 0;
return;
}
m.Accessibility = GetAccessibility(modifiers) ?? Accessibility.Private;

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

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