Skip to content

Commit

Permalink
chore(abg): use buildCodeBlock { ... } instead of CodeBlock.builder()
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Sep 6, 2024
1 parent 8b04bdb commit 16b9836
Showing 1 changed file with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asClassName
import com.squareup.kotlinpoet.asTypeName
import com.squareup.kotlinpoet.buildCodeBlock
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
Expand Down Expand Up @@ -471,15 +472,16 @@ private fun Metadata.buildCommonConstructorParameters(
.flatMap { (key, input) ->
val typedInput = inputTypings.containsKey(key)
val description = input.description.escapedForComments.removeTrailingWhitespacesForEachLine()
val kdocBuilder = CodeBlock.builder()
if (typedInput && !untypedClass && input.shouldBeRequiredInBinding()) {
kdocBuilder.add("%L", "<required>".escapedForComments)
if (description.isNotEmpty()) {
kdocBuilder.add(" ")
val kdoc =
buildCodeBlock {
if (typedInput && !untypedClass && input.shouldBeRequiredInBinding()) {
add("%L", "<required>".escapedForComments)
if (description.isNotEmpty()) {
add(" ")
}
}
add("%L", description)
}
}
kdocBuilder.add("%L", description)
val kdoc = kdocBuilder.build()

listOfNotNull(
untypedClass.takeIf { !it && typedInput }?.let {
Expand Down Expand Up @@ -545,19 +547,18 @@ private fun TypeSpec.Builder.addInitializerBlockIfNecessary(
return this
}

private fun Metadata.initializerBlock(inputTypings: Map<String, Typing>): CodeBlock {
val codeBlockBuilder = CodeBlock.builder()
var first = true
inputs
.filter { inputTypings.containsKey(it.key) }
.forEach { (key, input) ->
if (!first) {
codeBlockBuilder.add("\n")
}
first = false
val propertyName = key.toCamelCase()
codeBlockBuilder
.add(
private fun Metadata.initializerBlock(inputTypings: Map<String, Typing>) =
buildCodeBlock {
var first = true
inputs
.filter { inputTypings.containsKey(it.key) }
.forEach { (key, input) ->
if (!first) {
add("\n")
}
first = false
val propertyName = key.toCamelCase()
add(
"""
require(!((%1N != null) && (%1L_Untyped != null))) {
%2S
Expand All @@ -567,9 +568,8 @@ private fun Metadata.initializerBlock(inputTypings: Map<String, Typing>): CodeBl
propertyName,
"Only $propertyName or ${propertyName}_Untyped must be set, but not both",
)
if (input.shouldBeRequiredInBinding()) {
codeBlockBuilder
.add(
if (input.shouldBeRequiredInBinding()) {
add(
"""
require((%1N != null) || (%1L_Untyped != null)) {
%2S
Expand All @@ -579,10 +579,9 @@ private fun Metadata.initializerBlock(inputTypings: Map<String, Typing>): CodeBl
propertyName,
"Either $propertyName or ${propertyName}_Untyped must be set, one of them is required",
)
}
}
}
return codeBlockBuilder.build()
}
}

private fun actionKdoc(
metadata: Metadata,
Expand Down

0 comments on commit 16b9836

Please sign in to comment.