From a056659d093e3f51d7cc664d90157a3756560fed Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 20 Aug 2017 16:46:23 +0300 Subject: [PATCH] Generated properties from get()/void get() pairs. Signed-off-by: Dimitar Dobrev --- .../Passes/GetterSetterToPropertyPass.cs | 12 ++++++++---- tests/Common/Common.Tests.cs | 3 +++ tests/Common/Common.cpp | 16 +++++++++++++++- tests/Common/Common.h | 6 ++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index cf6779b7..f5b4183a 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -49,7 +49,13 @@ namespace CppSharp.Passes { var type = (Class) setter.Namespace; var firstWord = GetFirstWord(setter.Name); - var nameBuilder = new StringBuilder(setter.Name.Substring(firstWord.Length)); + string property; + if ((firstWord == "set" || firstWord == "set_") && + firstWord.Length < setter.Name.Length) + property = setter.Name.Substring(firstWord.Length); + else + property = setter.Name; + var nameBuilder = new StringBuilder(property); if (char.IsLower(setter.Name[0])) nameBuilder[0] = char.ToLowerInvariant(nameBuilder[0]); string afterSet = nameBuilder.ToString(); @@ -241,9 +247,7 @@ namespace CppSharp.Passes private void DistributeMethod(Method method) { - var firstWord = GetFirstWord(method.Name); - if (Match(firstWord, new[] { "set" }) && method.Name.Length > firstWord.Length && - method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void)) + if (method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void)) { if (method.Parameters.Count == 1) setters.Add(method); diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index 145615b2..34eb8c87 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -470,6 +470,9 @@ public class CommonTests : GeneratorTestFixture Assert.That(prop.FieldValue, Is.EqualTo(20)); prop.FieldValue = 10; Assert.That(prop.FieldValue, Is.EqualTo(10)); + + prop.GetterAndSetterWithTheSameName = 25; + Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25)); } [Test] diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 2b92d096..69e09b2f 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -489,7 +489,7 @@ std::string& HasStdString::getStdString() return s; } -TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0) +TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0), _getterAndSetterWithTheSameName(0) { } @@ -522,6 +522,20 @@ void TestProperties::setRefToPrimitiveInSetter(const double& value) _refToPrimitiveInSetter = value; } +int TestProperties::getterAndSetterWithTheSameName() +{ + return _getterAndSetterWithTheSameName; +} + +void TestProperties::getterAndSetterWithTheSameName(int value) +{ + _getterAndSetterWithTheSameName = value; +} + +void TestProperties::set(int value) +{ +} + HasOverridenSetter::HasOverridenSetter() { } diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 8090e850..a322ef4c 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -585,9 +585,15 @@ public: double refToPrimitiveInSetter() const; void setRefToPrimitiveInSetter(const double& value); + + int getterAndSetterWithTheSameName(); + void getterAndSetterWithTheSameName(int value); + + void set(int value); private: int FieldValue; double _refToPrimitiveInSetter; + int _getterAndSetterWithTheSameName; }; class DLL_API HasOverridenSetter : public TestProperties