Browse Source

Restore mapping of overloaded getters to methods

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1261/head
Dimitar Dobrev 6 years ago
parent
commit
d2ebabbebe
  1. 47
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  2. 2
      tests/CSharp/CSharp.Tests.cs
  3. 4
      tests/Common/Common.Tests.cs

47
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -169,25 +169,16 @@ namespace CppSharp.Passes @@ -169,25 +169,16 @@ namespace CppSharp.Passes
@class.Properties.Remove(property);
continue;
}
foreach (var method in @class.Methods.Where(
m => m.IsGenerated && m.Name == property.Name))
{
var oldName = method.Name;
method.Name = $@"get{char.ToUpperInvariant(method.Name[0])}{
method.Name.Substring(1)}";
Diagnostics.Debug("Method {0}::{1} renamed to {2}",
method.Namespace.Name, oldName, method.Name);
}
foreach (var @event in @class.Events.Where(
e => e.Name == property.Name))
if (property.SetMethod == null &&
@class.GetOverloads(property.GetMethod).Any(
m => m != property.GetMethod && !m.Ignore))
{
var oldName = @event.Name;
@event.Name = $@"on{char.ToUpperInvariant(@event.Name[0])}{
@event.Name.Substring(1)}";
Diagnostics.Debug("Event {0}::{1} renamed to {2}",
@event.Namespace.Name, oldName, @event.Name);
property.GetMethod.GenerationKind = GenerationKind.Generate;
@class.Properties.Remove(property);
continue;
}
RenameConflictingMethods(@class, property);
CombineComments(property);
}
}
@ -211,6 +202,28 @@ namespace CppSharp.Passes @@ -211,6 +202,28 @@ namespace CppSharp.Passes
return null;
}
private static void RenameConflictingMethods(Class @class, Property property)
{
foreach (var method in @class.Methods.Where(
m => m.IsGenerated && m.Name == property.Name))
{
var oldName = method.Name;
method.Name = $@"get{char.ToUpperInvariant(method.Name[0])}{
method.Name.Substring(1)}";
Diagnostics.Debug("Method {0}::{1} renamed to {2}",
method.Namespace.Name, oldName, method.Name);
}
foreach (var @event in @class.Events.Where(
e => e.Name == property.Name))
{
var oldName = @event.Name;
@event.Name = $@"on{char.ToUpperInvariant(@event.Name[0])}{
@event.Name.Substring(1)}";
Diagnostics.Debug("Event {0}::{1} renamed to {2}",
@event.Namespace.Name, oldName, @event.Name);
}
}
private static string GetReadWritePropertyName(INamedDecl getter, string afterSet)
{
string name = GetPropertyName(getter.Name);

2
tests/CSharp/CSharp.Tests.cs

@ -1330,7 +1330,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -1330,7 +1330,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
private class OverrideVirtualTemplate : VirtualTemplate<int>
{
public override int Function => 10;
public override int Function() => 10;
}
[Test]

4
tests/Common/Common.Tests.cs

@ -517,8 +517,8 @@ public class CommonTests : GeneratorTestFixture @@ -517,8 +517,8 @@ public class CommonTests : GeneratorTestFixture
prop.VirtualSetterReturnsBoolean = 45;
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
Assert.That(prop.nestedEnum, Is.EqualTo(5));
Assert.That(prop.GetNestedEnum(55), Is.EqualTo(55));
Assert.That(prop.nestedEnum(), Is.EqualTo(5));
Assert.That(prop.nestedEnum(55), Is.EqualTo(55));
Assert.That(prop.Get32Bit, Is.EqualTo(10));
}

Loading…
Cancel
Save