Skip to content

Commit

Permalink
Revert "Fix generator for open class (use polymorphic serializers)"
Browse files Browse the repository at this point in the history
This reverts commit 8ef56aa.
  • Loading branch information
ForNeVeR committed Sep 15, 2023
1 parent 5a88a02 commit 6281e1b
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 1,354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,7 @@ open class CSharp50Generator(
protected fun Member.Reactive.customSerializers(containing: Declaration, leadingComma: Boolean, ignorePerClientId: Boolean = false): String {
if(context != null && !ignorePerClientId)
return leadingComma.condstr { ", " } + perClientIdMapValueFactory(containing)
val res = genericParams.joinToString {
val allowSpecificOpenTypeReference = false
it.readerDelegateRef(containing, allowSpecificOpenTypeReference) + ", " + it.writerDelegateRef(containing, allowSpecificOpenTypeReference)
}
val res = genericParams.joinToString { it.readerDelegateRef(containing, true) + ", " + it.writerDelegateRef(containing, false) }
return (genericParams.isNotEmpty() && leadingComma).condstr { ", " } + res
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,30 +263,30 @@ open class Kotlin11Generator(
protected fun Member.Reactive.customSerializers(scope: Declaration, ignorePerClientId: Boolean = false) : List<String> {
if (context != null && !ignorePerClientId)
return listOf(context!!.longRef(scope), perClientIdMapValueFactory(scope))
return genericParams.asList().map { it.serializerRef(scope, false) }
return genericParams.asList().map { it.serializerRef(scope) }
}

protected fun IDeclaration.sanitizedName(scope: IDeclaration) : String {
val needQualification = namespace != scope.namespace
return needQualification.condstr { namespace + "." } + name
}

protected fun IType.leafSerializerRef(scope: Declaration, allowSpecificOpenTypeReference: Boolean): String? {
protected fun IType.leafSerializerRef(scope: Declaration): String? {
return when (this) {
is Enum -> "${sanitizedName(scope)}.marshaller"
is PredefinedType -> "FrameworkMarshallers.$name"
is Declaration ->
this.getSetting(Intrinsic)?.marshallerObjectFqn ?: run {
val name = sanitizedName(scope)
if (isAbstract || isOpen && !allowSpecificOpenTypeReference) "AbstractPolymorphic($name)" else name
if (isAbstract) "AbstractPolymorphic($name)" else name
}

is IArray -> if (this.isPrimitivesArray) "FrameworkMarshallers.${substitutedName(scope)}" else null
else -> null
}
}

protected fun IType.serializerRef(scope: Declaration, allowSpecificOpenTypeReference: Boolean) : String = leafSerializerRef(scope, allowSpecificOpenTypeReference) ?: when(this) {
protected fun IType.serializerRef(scope: Declaration) : String = leafSerializerRef(scope) ?: when(this) {
is InternedScalar -> "__${name}At${internKey.keyName}Serializer"
else -> "__${name}Serializer"
}
Expand Down Expand Up @@ -450,7 +450,7 @@ open class Kotlin11Generator(
if(decl is Toplevel) {
decl.declaredTypes.forEach {
if(it is Context.Generated)
+"object ${it.keyName}: ${it.contextImplementationFqn}<${it.type.substitutedName(decl)}>(\"${it.keyName}\", ${it.isHeavyKey}, ${it.type.serializerRef(decl, false)})"
+"object ${it.keyName}: ${it.contextImplementationFqn}<${it.type.substitutedName(decl)}>(\"${it.keyName}\", ${it.isHeavyKey}, ${it.type.serializerRef(decl)})"
}
}
}
Expand Down Expand Up @@ -580,7 +580,7 @@ open class Kotlin11Generator(
}

protected fun PrettyPrinter.customSerializersTrait(decl: Declaration) {
fun IType.serializerBuilder() : String = leafSerializerRef(decl, false)?: when (this) {
fun IType.serializerBuilder() : String = leafSerializerRef(decl)?: when (this) {
is IArray -> itemType.serializerBuilder() + ".array()"
is IImmutableList -> itemType.serializerBuilder() + ".list()"
is INullable -> itemType.serializerBuilder() + ".nullable()"
Expand All @@ -593,10 +593,10 @@ open class Kotlin11Generator(
.filterIsInstance<Member.Reactive>()
.flatMap { it.genericParams.toList() }
.distinct()
.filter { it.leafSerializerRef(decl, false) == null }
.filter { it.leafSerializerRef(decl) == null }

allTypesForDelegation
.map { "private val ${it.serializerRef(decl, false)} = ${it.serializerBuilder()}" }
.map { "private val ${it.serializerRef(decl)} = ${it.serializerBuilder()}" }
.distinct()
.forEach { println(it) }
}
Expand All @@ -610,7 +610,7 @@ open class Kotlin11Generator(
protected fun PrettyPrinter.registerSerializersTrait(decl: Toplevel, types: List<Declaration>) {
block("override fun registerSerializersCore(serializers: ISerializers) ") {
types.filter { !it.isAbstract }.filterIsInstance<IType>().println {
"serializers.register(${it.serializerRef(decl, true)})"
"serializers.register(${it.serializerRef(decl)})"
}

if (decl is Root) {
Expand Down Expand Up @@ -727,8 +727,7 @@ open class Kotlin11Generator(
else -> "${ctorSimpleName(decl)}(${delegatedBy.reader()})"
}
is Member.Reactive -> {
val customSerializers = customSerializers(decl)
val params = (listOf("ctx", "buffer") + customSerializers).joinToString (", ")
val params = (listOf("ctx", "buffer") + customSerializers(decl)).joinToString (", ")
if(context != null) {
"RdPerContextMap.read(${context!!.longRef(decl)}, buffer) ${this.perClientIdMapValueFactory(decl)}"
} else {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6281e1b

Please sign in to comment.