Make generated code ordered same as before
Allow to fix signature for sorting when overriding it
This commit is contained in:
@@ -43,6 +43,10 @@ class MemberBuilder(
|
||||
lateinit var keyword: Keyword // fun/val/var
|
||||
lateinit var signature: String // name and params
|
||||
|
||||
var sortingSignature: String? = null
|
||||
get() = field ?: signature
|
||||
private set
|
||||
|
||||
val f get() = family
|
||||
|
||||
private val legacyMode = true
|
||||
@@ -93,7 +97,10 @@ class MemberBuilder(
|
||||
fun receiver(value: String) { customReceiver = value }
|
||||
@Deprecated("Use receiver()", ReplaceWith("receiver(value)"))
|
||||
fun customReceiver(value: String) = receiver(value)
|
||||
fun signature(value: String) { signature = value }
|
||||
fun signature(value: String, notForSorting: Boolean = false) {
|
||||
if (notForSorting) sortingSignature = signature
|
||||
signature = value
|
||||
}
|
||||
fun returns(type: String) { returns = type }
|
||||
|
||||
fun typeParam(typeParameterName: String) {
|
||||
|
||||
@@ -25,12 +25,32 @@ data class PlatformSourceFile(
|
||||
val sourceFile: SourceFile
|
||||
)
|
||||
|
||||
private val platformsToGenerate = Platform.values - Platform.Native
|
||||
|
||||
@JvmName("groupByFileAndWriteGroups")
|
||||
fun Sequence<TemplateGroup>.groupByFileAndWrite(
|
||||
fileNameBuilder: (PlatformSourceFile) -> File
|
||||
) {
|
||||
flatMap { group ->
|
||||
group.invoke()
|
||||
.flatMap { it.instantiate(platformsToGenerate) }
|
||||
.sortedBy { it.sortingSignature }
|
||||
}.groupByFileAndWrite(fileNameBuilder)
|
||||
}
|
||||
|
||||
@JvmName("groupByFileAndWriteTemplates")
|
||||
fun Sequence<MemberTemplate>.groupByFileAndWrite(
|
||||
fileNameBuilder: (PlatformSourceFile) -> File
|
||||
) {
|
||||
val groupedMembers = map { it.instantiate(Platform.values - Platform.Native) }.flatten().groupBy {
|
||||
PlatformSourceFile(it.platform, it.sourceFile)
|
||||
}
|
||||
flatMap { it.instantiate(platformsToGenerate) }
|
||||
.groupByFileAndWrite(fileNameBuilder)
|
||||
}
|
||||
|
||||
@JvmName("groupByFileAndWriteMembers")
|
||||
fun Sequence<MemberBuilder>.groupByFileAndWrite(
|
||||
fileNameBuilder: (PlatformSourceFile) -> File
|
||||
) {
|
||||
val groupedMembers = groupBy { PlatformSourceFile(it.platform, it.sourceFile) }
|
||||
|
||||
for ((psf, members) in groupedMembers) {
|
||||
val file = fileNameBuilder(psf)
|
||||
|
||||
Reference in New Issue
Block a user