Skip to content

Commit 1bd2074

Browse files
committed
fix(model-api-gen): migration to kotlinpoet 1.14.2
All functions are required to explicitly specify the return type, otherwise `Unit` is generated. The previous version didn't generate any type in that case and the Kotlin compiler inferred it.
1 parent f3b9747 commit 1bd2074

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

model-api-gen/src/main/kotlin/org/modelix/metamodel/generator/MetaModelGenerator.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
101101
.joinToString(", ") { it.name }
102102
builder.addFunction(
103103
FunSpec.builder("getConcepts")
104+
.returns(List::class.asClassName().parameterizedBy(IConcept::class.asTypeName()))
104105
.addModifiers(KModifier.OVERRIDE)
105106
.addCode(language.getConcepts().map { it.conceptObjectType() }.toListLiteralCodeBlock())
106107
.build()
@@ -139,7 +140,9 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
139140
.build()
140141
)
141142

143+
val enumType = ClassName(enum.language.name, enum.name)
142144
val getLiteralFunBuilder = FunSpec.builder("getLiteralByMemberId")
145+
.returns(enumType)
143146
.addParameter("uid", String::class)
144147
val getLiteralCodeBuilder = CodeBlock.builder().beginControlFlow("return when (uid) {")
145148

@@ -166,6 +169,7 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
166169
val companion = TypeSpec.companionObjectBuilder()
167170
.addFunction(
168171
FunSpec.builder("defaultValue")
172+
.returns(enumType)
169173
.addCode("return values()[%L]", enum.defaultIndex)
170174
.build())
171175
.addFunction(
@@ -326,12 +330,12 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
326330
)
327331
}
328332

333+
val inputStepType = IMonoStep::class.asTypeName()
334+
.parameterizedBy(concept.nodeWrapperInterfaceType())
329335
addFunction(
330336
FunSpec.builder(feature.setterName())
331-
.receiver(
332-
IMonoStep::class.asTypeName()
333-
.parameterizedBy(concept.nodeWrapperInterfaceType())
334-
)
337+
.returns(inputStepType)
338+
.receiver(inputStepType)
335339
.addParameter("value", IMonoStep::class.asTypeName().parameterizedBy(feature.asKotlinType()))
336340
.addStatement(
337341
"return %T.setProperty(this, %T.%N, value)",
@@ -417,12 +421,14 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
417421
val instanceClassType = KClass::class.asClassName().parameterizedBy(concept.nodeWrapperImplType())
418422
addFunction(
419423
FunSpec.builder(GeneratedConcept<*, *>::getInstanceClass.name)
424+
.returns(KClass::class.asClassName().parameterizedBy(concept.nodeWrapperImplType()))
420425
.addModifiers(KModifier.OVERRIDE)
421426
.addStatement("""return %T::class""", concept.nodeWrapperImplType())
422427
.build()
423428
)
424429
addFunction(
425430
FunSpec.builder(GeneratedConcept<*, *>::typed.name)
431+
.returns(concept.conceptWrapperInterfaceType())
426432
.addModifiers(KModifier.OVERRIDE)
427433
.addStatement("""return %T""", concept.conceptWrapperInterfaceClass())
428434
.build()
@@ -434,6 +440,7 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
434440
)
435441
addFunction(
436442
FunSpec.builder(GeneratedConcept<*, *>::wrap.name)
443+
.returns(concept.nodeWrapperImplType())
437444
.addModifiers(KModifier.OVERRIDE)
438445
.addParameter("node", INode::class)
439446
.addStatement("return %T(node)", concept.nodeWrapperImplType())
@@ -442,6 +449,7 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
442449
concept.uid?.let { uid ->
443450
addFunction(
444451
FunSpec.builder(GeneratedConcept<*, *>::getUID.name)
452+
.returns(String::class)
445453
.addModifiers(KModifier.OVERRIDE)
446454
.addStatement(CodeBlock.of("return %S", uid).toString())
447455
.build()

0 commit comments

Comments
 (0)