Skip to content

Commit b4c954a

Browse files
authored
Properly handle parameterized mapped superclass issue #891 (#892)
Refer to issue #891 for the complete report. This PR handles the issue by adding out keywords to the generated Q-classes when they are needed.
2 parents dc5aee5 + b8c1794 commit b4c954a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ 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+
@JvmOverloads
31+
fun Type.asTypeName(out: Boolean = false): TypeName = asClassName().let { className ->
3132
if (parameters.isNotEmpty())
32-
className.parameterizedBy(*parameters.map { it.asTypeName() }.toTypedArray()) else className
33+
className.parameterizedBy(*parameters.map { if (out) it.asOutTypeName() else it.asTypeName() }.toTypedArray()) else className
3334
}
3435

3536
fun Type.asClassName(): ClassName = when (this.fullName) {
@@ -57,7 +58,7 @@ fun Type.asClassName(): ClassName = when (this.fullName) {
5758
else -> ClassName(packageName, *enclosingTypeHierarchy().toTypedArray())
5859
}
5960

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

6263
private fun Type.enclosingTypeHierarchy(): List<String> {
6364
var current: Type? = this
@@ -76,6 +77,8 @@ fun KClass<*>.parameterizedBy(vararg types: TypeName) = asTypeName().parameteriz
7677

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

80+
fun KClass<*>.parameterizedByOut(vararg types: Type) = asTypeName().parameterizedBy(types.map { it.asTypeName(out = true) })
81+
7982
fun Collection<String>.joinToCode(
8083
format: String = "%S",
8184
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)