@@ -14,6 +14,7 @@ import com.squareup.kotlinpoet.PropertySpec
14
14
import com.squareup.kotlinpoet.TypeSpec
15
15
import com.squareup.kotlinpoet.asClassName
16
16
import com.squareup.kotlinpoet.asTypeName
17
+ import com.squareup.kotlinpoet.buildCodeBlock
17
18
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
18
19
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
19
20
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
@@ -471,15 +472,16 @@ private fun Metadata.buildCommonConstructorParameters(
471
472
.flatMap { (key, input) ->
472
473
val typedInput = inputTypings.containsKey(key)
473
474
val description = input.description.escapedForComments.removeTrailingWhitespacesForEachLine()
474
- val kdocBuilder = CodeBlock .builder()
475
- if (typedInput && ! untypedClass && input.shouldBeRequiredInBinding()) {
476
- kdocBuilder.add(" %L" , " <required>" .escapedForComments)
477
- if (description.isNotEmpty()) {
478
- kdocBuilder.add(" " )
475
+ val kdoc =
476
+ buildCodeBlock {
477
+ if (typedInput && ! untypedClass && input.shouldBeRequiredInBinding()) {
478
+ add(" %L" , " <required>" .escapedForComments)
479
+ if (description.isNotEmpty()) {
480
+ add(" " )
481
+ }
482
+ }
483
+ add(" %L" , description)
479
484
}
480
- }
481
- kdocBuilder.add(" %L" , description)
482
- val kdoc = kdocBuilder.build()
483
485
484
486
listOfNotNull(
485
487
untypedClass.takeIf { ! it && typedInput }?.let {
@@ -545,19 +547,18 @@ private fun TypeSpec.Builder.addInitializerBlockIfNecessary(
545
547
return this
546
548
}
547
549
548
- private fun Metadata.initializerBlock (inputTypings : Map <String , Typing >): CodeBlock {
549
- val codeBlockBuilder = CodeBlock .builder()
550
- var first = true
551
- inputs
552
- .filter { inputTypings.containsKey(it.key) }
553
- .forEach { (key, input) ->
554
- if (! first) {
555
- codeBlockBuilder.add(" \n " )
556
- }
557
- first = false
558
- val propertyName = key.toCamelCase()
559
- codeBlockBuilder
560
- .add(
550
+ private fun Metadata.initializerBlock (inputTypings : Map <String , Typing >) =
551
+ buildCodeBlock {
552
+ var first = true
553
+ inputs
554
+ .filter { inputTypings.containsKey(it.key) }
555
+ .forEach { (key, input) ->
556
+ if (! first) {
557
+ add(" \n " )
558
+ }
559
+ first = false
560
+ val propertyName = key.toCamelCase()
561
+ add(
561
562
"""
562
563
require(!((%1N != null) && (%1L_Untyped != null))) {
563
564
%2S
@@ -567,9 +568,8 @@ private fun Metadata.initializerBlock(inputTypings: Map<String, Typing>): CodeBl
567
568
propertyName,
568
569
" Only $propertyName or ${propertyName} _Untyped must be set, but not both" ,
569
570
)
570
- if (input.shouldBeRequiredInBinding()) {
571
- codeBlockBuilder
572
- .add(
571
+ if (input.shouldBeRequiredInBinding()) {
572
+ add(
573
573
"""
574
574
require((%1N != null) || (%1L_Untyped != null)) {
575
575
%2S
@@ -579,10 +579,9 @@ private fun Metadata.initializerBlock(inputTypings: Map<String, Typing>): CodeBl
579
579
propertyName,
580
580
" Either $propertyName or ${propertyName} _Untyped must be set, one of them is required" ,
581
581
)
582
+ }
582
583
}
583
- }
584
- return codeBlockBuilder.build()
585
- }
584
+ }
586
585
587
586
private fun actionKdoc (
588
587
metadata : Metadata ,
0 commit comments