Add swift_name attribute to properties in framework header too.
This commit is contained in:
Svyatoslav Scherbina
2019-01-28 18:29:37 +03:00
committed by SvyatoslavScherbina
parent 9955b2cbf1
commit 550163cc7b
5 changed files with 27 additions and 8 deletions
@@ -435,7 +435,8 @@ abstract class ObjCExportHeaderGenerator(
descriptor.enumEntries.forEach { descriptor.enumEntries.forEach {
val entryName = namer.getEnumEntrySelector(it) val entryName = namer.getEnumEntrySelector(it)
+ObjCProperty(entryName, null, type, listOf("class", "readonly")) +ObjCProperty(entryName, null, type, listOf("class", "readonly"),
declarationAttributes = listOf(swiftNameAttribute(entryName)))
} }
} }
else -> { else -> {
@@ -657,7 +658,7 @@ abstract class ObjCExportHeaderGenerator(
val getterSelector = getSelector(baseProperty.getter!!) val getterSelector = getSelector(baseProperty.getter!!)
val getterName: String? = if (getterSelector != name) getterSelector else null 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 { private fun buildMethod(method: FunctionDescriptor, baseMethod: FunctionDescriptor): ObjCMethod {
@@ -46,9 +46,9 @@ object StubRenderer {
} }
fun ObjCProperty.getAllAttributes(): List<String> { 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" } getterName?.let { allAttributes += "getter=$it" }
setterName?.let { allAttributes += "setter=$it" } setterName?.let { allAttributes += "setter=$it" }
return allAttributes return allAttributes
@@ -65,6 +65,7 @@ object StubRenderer {
append("@property") append("@property")
appendAttributes() appendAttributes()
appendTypeAndName() appendTypeAndName()
appendPostfixDeclarationAttributes(property.declarationAttributes)
append(';') append(';')
} }
@@ -105,8 +106,7 @@ object StubRenderer {
} }
fun appendAttributes() { fun appendAttributes() {
if (method.attributes.isNotEmpty()) append(' ') appendPostfixDeclarationAttributes(method.attributes)
method.attributes.joinTo(this, separator = " ", transform = ::renderAttribute)
} }
appendStaticness() appendStaticness()
@@ -116,6 +116,11 @@ object StubRenderer {
append(';') 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 { private fun ObjCProtocol.renderProtocolHeader() = buildString {
append("@protocol ") append("@protocol ")
append(name) append(name)
@@ -47,9 +47,14 @@ class ObjCParameter(name: String,
class ObjCProperty(name: String, class ObjCProperty(name: String,
descriptor: PropertyDescriptor?, descriptor: PropertyDescriptor?,
val type: ObjCType, val type: ObjCType,
val attributes: List<String>, val propertyAttributes: List<String>,
val setterName: String? = null, 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 = private fun buildMethodName(selectors: List<String>, parameters: List<ObjCParameter>): String =
if (selectors.size == 1 && parameters.size == 0) { if (selectors.size == 1 && parameters.size == 0) {
@@ -266,3 +266,6 @@ class Bridge : BridgeBase() {
} }
fun Any.same() = this 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())) 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 -------- // -------- Execution of the test --------
class ValuesTests : TestProvider { class ValuesTests : TestProvider {
@@ -526,6 +530,7 @@ class ValuesTests : TestProvider {
TestCase(name: "TestInlineClasses", method: withAutorelease(testInlineClasses)), TestCase(name: "TestInlineClasses", method: withAutorelease(testInlineClasses)),
TestCase(name: "TestShared", method: withAutorelease(testShared)), TestCase(name: "TestShared", method: withAutorelease(testShared)),
TestCase(name: "TestPureSwiftClasses", method: withAutorelease(testPureSwiftClasses)), TestCase(name: "TestPureSwiftClasses", method: withAutorelease(testPureSwiftClasses)),
TestCase(name: "TestNames", method: withAutorelease(testNames)),
] ]
} }
} }