Fix #2571
Add swift_name attribute to properties in framework header too.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
9955b2cbf1
commit
550163cc7b
+3
-2
@@ -435,7 +435,8 @@ abstract class ObjCExportHeaderGenerator(
|
||||
|
||||
descriptor.enumEntries.forEach {
|
||||
val entryName = namer.getEnumEntrySelector(it)
|
||||
+ObjCProperty(entryName, null, type, listOf("class", "readonly"))
|
||||
+ObjCProperty(entryName, null, type, listOf("class", "readonly"),
|
||||
declarationAttributes = listOf(swiftNameAttribute(entryName)))
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -657,7 +658,7 @@ abstract class ObjCExportHeaderGenerator(
|
||||
val getterSelector = getSelector(baseProperty.getter!!)
|
||||
val getterName: String? = if (getterSelector != name) getterSelector else null
|
||||
|
||||
return ObjCProperty(name, property, type, attributes, setterName, getterName)
|
||||
return ObjCProperty(name, property, type, attributes, setterName, getterName, listOf(swiftNameAttribute(name)))
|
||||
}
|
||||
|
||||
private fun buildMethod(method: FunctionDescriptor, baseMethod: FunctionDescriptor): ObjCMethod {
|
||||
|
||||
+9
-4
@@ -46,9 +46,9 @@ object StubRenderer {
|
||||
}
|
||||
|
||||
fun ObjCProperty.getAllAttributes(): List<String> {
|
||||
if (getterName == null && setterName == null) return attributes
|
||||
if (getterName == null && setterName == null) return propertyAttributes
|
||||
|
||||
val allAttributes = attributes.toMutableList()
|
||||
val allAttributes = propertyAttributes.toMutableList()
|
||||
getterName?.let { allAttributes += "getter=$it" }
|
||||
setterName?.let { allAttributes += "setter=$it" }
|
||||
return allAttributes
|
||||
@@ -65,6 +65,7 @@ object StubRenderer {
|
||||
append("@property")
|
||||
appendAttributes()
|
||||
appendTypeAndName()
|
||||
appendPostfixDeclarationAttributes(property.declarationAttributes)
|
||||
append(';')
|
||||
}
|
||||
|
||||
@@ -105,8 +106,7 @@ object StubRenderer {
|
||||
}
|
||||
|
||||
fun appendAttributes() {
|
||||
if (method.attributes.isNotEmpty()) append(' ')
|
||||
method.attributes.joinTo(this, separator = " ", transform = ::renderAttribute)
|
||||
appendPostfixDeclarationAttributes(method.attributes)
|
||||
}
|
||||
|
||||
appendStaticness()
|
||||
@@ -116,6 +116,11 @@ object StubRenderer {
|
||||
append(';')
|
||||
}
|
||||
|
||||
private fun Appendable.appendPostfixDeclarationAttributes(attributes: List<kotlin.String>) {
|
||||
if (attributes.isNotEmpty()) this.append(' ')
|
||||
attributes.joinTo(this, separator = " ", transform = this@StubRenderer::renderAttribute)
|
||||
}
|
||||
|
||||
private fun ObjCProtocol.renderProtocolHeader() = buildString {
|
||||
append("@protocol ")
|
||||
append(name)
|
||||
|
||||
+7
-2
@@ -47,9 +47,14 @@ class ObjCParameter(name: String,
|
||||
class ObjCProperty(name: String,
|
||||
descriptor: PropertyDescriptor?,
|
||||
val type: ObjCType,
|
||||
val attributes: List<String>,
|
||||
val propertyAttributes: List<String>,
|
||||
val setterName: String? = null,
|
||||
val getterName: String? = null) : Stub<PropertyDescriptor>(name, descriptor)
|
||||
val getterName: String? = null,
|
||||
val declarationAttributes: List<String> = emptyList()) : Stub<PropertyDescriptor>(name, descriptor) {
|
||||
|
||||
@Deprecated("", ReplaceWith("this.propertyAttributes"), DeprecationLevel.WARNING)
|
||||
val attributes: List<String> get() = propertyAttributes
|
||||
}
|
||||
|
||||
private fun buildMethodName(selectors: List<String>, parameters: List<ObjCParameter>): String =
|
||||
if (selectors.size == 1 && parameters.size == 0) {
|
||||
|
||||
@@ -266,3 +266,6 @@ class Bridge : BridgeBase() {
|
||||
}
|
||||
|
||||
fun Any.same() = this
|
||||
|
||||
// https://github.com/JetBrains/kotlin-native/issues/2571
|
||||
val PROPERTY_NAME_MUST_NOT_BE_ALTERED_BY_SWIFT = 111
|
||||
|
||||
@@ -490,6 +490,10 @@ func testPureSwiftClasses() throws {
|
||||
try assertEquals(actual: "pure", expected: ValuesKt.iFunExt(PureSwiftKotlinInterfaceImpl()))
|
||||
}
|
||||
|
||||
func testNames() throws {
|
||||
try assertEquals(actual: ValuesKt.PROPERTY_NAME_MUST_NOT_BE_ALTERED_BY_SWIFT, expected: 111)
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class ValuesTests : TestProvider {
|
||||
@@ -526,6 +530,7 @@ class ValuesTests : TestProvider {
|
||||
TestCase(name: "TestInlineClasses", method: withAutorelease(testInlineClasses)),
|
||||
TestCase(name: "TestShared", method: withAutorelease(testShared)),
|
||||
TestCase(name: "TestPureSwiftClasses", method: withAutorelease(testPureSwiftClasses)),
|
||||
TestCase(name: "TestNames", method: withAutorelease(testNames)),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user