diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index 54c56f6857..c9fbb687c2 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -136,15 +136,16 @@ private static Property GetProperty(Method method, string name, { Type underlyingType = GetUnderlyingType(type); Class @class = (Class) method.Namespace; + Property property = @class.Properties.Find( p => p.Field == null && - ((!isSetter && p.HasSetter && p.Name == name) || - (isSetter && p.HasGetter && - GetReadWritePropertyName(p.GetMethod, name) == name)) && - ((p.HasGetter && - GetUnderlyingType(p.GetMethod.OriginalReturnType).Equals(underlyingType)) || - (p.HasSetter && - GetUnderlyingType(p.SetMethod.Parameters[0].QualifiedType).Equals(underlyingType)))) ?? + ((!isSetter && p.SetMethod?.IsStatic == method.IsStatic) || + (isSetter && p.GetMethod?.IsStatic == method.IsStatic)) && + ((p.HasGetter && GetUnderlyingType( + p.GetMethod.OriginalReturnType).Equals(underlyingType)) || + (p.HasSetter && GetUnderlyingType( + p.SetMethod.Parameters[0].QualifiedType).Equals(underlyingType))) && + Match(p, name)) ?? new Property { Name = name, QualifiedType = type }; if (property.Namespace == null) @@ -160,13 +161,43 @@ private static Property GetProperty(Method method, string name, (int) method.Access); } - property.Name = property.OriginalName = name; method.GenerationKind = GenerationKind.Internal; if (method.ExplicitInterfaceImpl != null) property.ExplicitInterfaceImpl = method.ExplicitInterfaceImpl; return property; } + private static bool Match(Property property, string name) + { + if (string.IsNullOrEmpty(name)) + return false; + + if (property.Name == name) + return true; + + if (property.Name == RemovePrefix(name)) + return true; + + if (RemovePrefix(property.Name) == name) + { + property.Name = property.OriginalName = name; + return true; + } + + return property.SetMethod != null && + GetPropertyNameFromSetter(property.SetMethod.Name) == name; + } + + private static string RemovePrefix(string identifier) + { + if (string.IsNullOrEmpty(identifier)) + return identifier; + + string name = GetPropertyName(identifier); + return name.StartsWith("is", StringComparison.Ordinal) && name != "is" ? + char.ToLowerInvariant(name[2]) + name.Substring(3) : name; + } + private static void ProcessProperties(Class @class, IEnumerable newProperties) { foreach (Property property in newProperties) @@ -275,17 +306,6 @@ private static void RenameConflictingMethods(Class @class, Property property) } } - private static string GetReadWritePropertyName(INamedDecl getter, string afterSet) - { - string name = GetPropertyName(getter.Name); - if (name != afterSet && name.StartsWith("is", StringComparison.Ordinal) && - name != "is") - { - name = char.ToLowerInvariant(name[2]) + name.Substring(3); - } - return name; - } - private static Type GetUnderlyingType(QualifiedType type) { TagType tagType = type.Type as TagType; diff --git a/src/Generator/Passes/MultipleInheritancePass.cs b/src/Generator/Passes/MultipleInheritancePass.cs index b28467071d..b6ff91b2e1 100644 --- a/src/Generator/Passes/MultipleInheritancePass.cs +++ b/src/Generator/Passes/MultipleInheritancePass.cs @@ -118,16 +118,19 @@ where property.IsDeclared if (@interface.Bases.Count == 0) { + QualifiedType intPtr = new QualifiedType( + new BuiltinType(PrimitiveType.IntPtr)); var instance = new Property - { + { Namespace = @interface, Name = Helpers.InstanceIdentifier, - QualifiedType = new QualifiedType(new BuiltinType(PrimitiveType.IntPtr)), + QualifiedType = intPtr, GetMethod = new Method { Name = Helpers.InstanceIdentifier, SynthKind = FunctionSynthKind.InterfaceInstance, - Namespace = @interface + Namespace = @interface, + OriginalReturnType = intPtr } }; diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index f31ba108b3..a37ae76031 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -642,6 +642,15 @@ void TestProperties::setStartWithVerb(int value) { } +void TestProperties::setSetterBeforeGetter(bool value) +{ +} + +bool TestProperties::isSetterBeforeGetter() +{ + return true; +} + bool TestProperties::contains(char c) { return true; diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 9f04020b01..c0d9e0f5c9 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -620,6 +620,9 @@ struct DLL_API TestProperties int startWithVerb(); void setStartWithVerb(int value); + void setSetterBeforeGetter(bool value); + bool isSetterBeforeGetter(); + bool contains(char c); bool contains(const char* str); private: