Temporary workaround to generate functions with optional parameters with bodies in common code.

This commit is contained in:
Ilya Gorbunov
2016-12-15 20:21:46 +03:00
parent b72e5c038d
commit b2ccea87f3
4 changed files with 212 additions and 24 deletions
@@ -318,6 +318,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
fun build(builder: Appendable, f: Family, primitive: PrimitiveType?, platform: Platform) {
val headerOnly: Boolean = platform == Platform.Common
val hasOptionalParams = (customSignature[platform, f] ?: signature).contains("=")
val returnType = returns[platform, f] ?: throw RuntimeException("No return type specified for $signature")
fun renderType(expression: String, receiver: String, self: String): String {
@@ -473,7 +474,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
}
builder.append(visibility[f] ?: "public").append(' ')
if (headerOnly) {
if (headerOnly && !hasOptionalParams) {
builder.append("header ")
}
if (external[platform, f] == true)
@@ -498,7 +499,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
if (receiverType.isNotEmpty()) builder.append('.')
builder.append("${(customSignature[platform, f] ?: signature).renderType()}: ${returnType.renderType()}")
if (headerOnly) {
if (headerOnly && !hasOptionalParams) {
builder.append("\n\n")
return
}