Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contracts to node append and tag declaration calls #264

Merged
merged 5 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 24 additions & 30 deletions buildSrc/src/main/kotlin/kotlinx/html/generate/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,7 @@ fun generate(pkg: String, todir: String, jsdir: String, wasmJsDir: String) {

repository.tags.values.filterIgnored().groupBy { it.name[0] }.entries.forEach { e ->
writeIntoFile("$todir/gen-tags-${e.key}.kt") {
packg(pkg)
emptyLine()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
fullImportsHeader(pkg)

e.value.forEach {
tagClass(repository, it, emptySet())
Expand Down Expand Up @@ -124,16 +115,7 @@ fun generate(pkg: String, todir: String, jsdir: String, wasmJsDir: String) {

FileOutputStream("$todir/gen-tag-unions.kt").writer(Charsets.UTF_8).use {
with(it) {
packg(pkg)
emptyLine()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
fullImportsHeader(pkg)

repository.groupUnions.values.forEach { union ->
clazz(
Expand Down Expand Up @@ -163,16 +145,7 @@ fun generate(pkg: String, todir: String, jsdir: String, wasmJsDir: String) {

FileOutputStream("$todir/gen-tag-groups.kt").writer(Charsets.UTF_8).use {
with(it) {
packg(pkg)
emptyLine()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
fullImportsHeader(pkg)

repository.tagGroups.values.forEach { group ->
val unions = repository.unionsByGroups[group.name].orEmpty().map { it.name }
Expand Down Expand Up @@ -319,6 +292,7 @@ private fun generateConsumerTags(
emptyLine()
packg(pkg)
emptyLine()
contractImports()
import("kotlinx.html.*")
import("kotlinx.html.attributes.*")

Expand Down Expand Up @@ -379,3 +353,23 @@ private fun Appendable.writeKotlinPoet(builder: FileSpec.Builder.() -> Unit) {
.build()
.writeTo(this)
}

private fun Appendable.fullImportsHeader(pkg: String) {
packg(pkg)
emptyLine()
contractImports()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
}

private fun Appendable.contractImports() {
import("kotlin.contracts.ExperimentalContracts")
import("kotlin.contracts.InvocationKind")
import("kotlin.contracts.contract")
}