Skip to content

Commit a9df33d

Browse files
committed
Properly handle parameterized mapped superclass issue #891
1 parent bfc4ea2 commit a9df33d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

querydsl-tooling/querydsl-kotlin-codegen/src/main/kotlin/com/querydsl/kotlin/codegen/Extensions.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import com.squareup.kotlinpoet.asTypeName
2727
import com.squareup.kotlinpoet.joinToCode
2828
import kotlin.reflect.KClass
2929

30-
fun Type.asTypeName(): TypeName = asClassName().let { className ->
30+
fun Type.asTypeName(out: Boolean = false): TypeName = asClassName().let { className ->
3131
if (parameters.isNotEmpty())
32-
className.parameterizedBy(*parameters.map { it.asTypeName() }.toTypedArray()) else className
32+
className.parameterizedBy(*parameters.map { if (out) it.asOutTypeName() else it.asTypeName() }.toTypedArray()) else className
3333
}
3434

3535
fun Type.asClassName(): ClassName = when (this.fullName) {
@@ -57,7 +57,7 @@ fun Type.asClassName(): ClassName = when (this.fullName) {
5757
else -> ClassName(packageName, *enclosingTypeHierarchy().toTypedArray())
5858
}
5959

60-
fun Type.asOutTypeName() = WildcardTypeName.producerOf(asTypeName())
60+
fun Type.asOutTypeName() = WildcardTypeName.producerOf(asTypeName(out = true))
6161

6262
private fun Type.enclosingTypeHierarchy(): List<String> {
6363
var current: Type? = this
@@ -72,10 +72,12 @@ fun TypeMappings.getPathClassName(type: Type, model: EntityType) = getPathType(t
7272

7373
fun TypeMappings.getPathTypeName(type: Type, model: EntityType) = getPathType(type, model, false).asTypeName()
7474

75-
fun KClass<*>.parameterizedBy(vararg types: TypeName) = asTypeName().parameterizedBy(*types)
75+
fun KClass<*>.parameterizedBy(vararg types: TypeName) = asTypeName().let { if (types.isEmpty()) it else it.parameterizedBy(*types) }
7676

7777
fun KClass<*>.parameterizedBy(vararg types: Type) = asTypeName().parameterizedBy(types.map { it.asTypeName() })
7878

79+
fun KClass<*>.parameterizedByOut(vararg types: Type) = asTypeName().parameterizedBy(types.map { it.asTypeName(out = true) })
80+
7981
fun Collection<String>.joinToCode(
8082
format: String = "%S",
8183
separator: CharSequence = ", ",

querydsl-tooling/querydsl-kotlin-codegen/src/main/kotlin/com/querydsl/kotlin/codegen/KotlinEntitySerializer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ open class KotlinEntitySerializer @Inject constructor(
106106
}
107107
val superType = when (model.originalCategory) {
108108
TypeCategory.BOOLEAN, TypeCategory.STRING -> pathType.asTypeName()
109-
else -> pathType.parameterizedBy(model)
109+
else -> pathType.parameterizedByOut(model)
110110
}
111111
return TypeSpec.classBuilder(mappings.getPathClassName(model, model))
112112
.addAnnotations(model.annotations.map { AnnotationSpec.get(it) })

0 commit comments

Comments
 (0)