Skip to content

Commit

Permalink
Fix DSL builder when only functions or only properties are configured
Browse files Browse the repository at this point in the history
  • Loading branch information
ALikhachev committed Sep 19, 2024
1 parent baab444 commit 788fb2b
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@ internal class KapiFenceRootBuilder(project: Project) : KapiFenceRootDsl {
}
}

private fun String.maybeWrapIntoClass(className: String): String? {
return if (isEmpty()) {
null
} else {
"class $className {\n$this\n}"
}
}

override fun deprecateMembers(
name: String,
body: KapiFenceClassDsl.() -> Unit,
) {
val funBuilder = StringBuilder()
funBuilder.appendLine("class $name {")
val propBuilder = StringBuilder()
propBuilder.appendLine("class $name {")
KapiFenceClassBuilder(funBuilder, propBuilder).body()
funBuilder.appendLine("}")
propBuilder.appendLine("}")
records_.add(funBuilder.toString())
records_.add(propBuilder.toString())
funBuilder.toString().maybeWrapIntoClass(name)?.let {
records_.add(it)
}
propBuilder.toString().maybeWrapIntoClass(name)?.let {
records_.add(it)
}
}
}

Expand Down

0 comments on commit 788fb2b

Please sign in to comment.