From 86f65d6a6a9f4b82e0f5e2ce237aceb46c212a65 Mon Sep 17 00:00:00 2001 From: dsavvinov Date: Fri, 15 Jul 2016 16:54:25 +0300 Subject: [PATCH] Removed nullable types from generated code --- .../kotlin/src/kotlin_class_generator.cc | 2 +- .../kotlin/src/kotlin_field_generator.cc | 2 +- .../kotlin/src/kotlin_name_resolver.cc | 1 - .../compiler/kotlin/test/addressbook.kt | 48 +++++++++---------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc index b0052f6a53e..2bdb6d2e1eb 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc @@ -137,7 +137,7 @@ void ClassGenerator::generateMergeMethods(io::Printer *printer) const { // Bytes type is handled separately else if (properties[i]->protoType == FieldDescriptor::TYPE_BYTES) { vars["initValue"] = properties[i]->getInitValue(); - printer->Print(vars, "$fieldName$?.plus(other.$fieldName$ ?: $initValue$)\n"); + printer->Print(vars, "$fieldName$.plus(other.$fieldName$)\n"); } // for all other cases just take other's field diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc index 4744b1a4bd0..d0e044c44ac 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc @@ -159,7 +159,7 @@ void FieldGenerator::generateSerializationCode(io::Printer *printer, bool isRead printer->Print(vars, "$fieldName$ = $converter$(input.read$type$($maybeFieldNumber$))\n"); } else { - printer->Print(vars, "output.write$type$ ($maybeFieldNumber$$maybeComma$$fieldName$?.ord)\n"); + printer->Print(vars, "output.write$type$ ($maybeFieldNumber$$maybeComma$$fieldName$.ord)\n"); } return; } diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc index f86eed8f361..ea8549b583c 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc @@ -81,7 +81,6 @@ string protobufToKotlinField(FieldDescriptor const * descriptor) { case FieldDescriptor::LABEL_REQUIRED: break; case FieldDescriptor::LABEL_OPTIONAL: - postamble = "?"; break; case FieldDescriptor::LABEL_REPEATED: #ifndef KOTLIN_GENERATED_CODE_LANGUAGE_LEVEL_LOW diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/addressbook.kt b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/addressbook.kt index 2ef32e3b811..357b50bb03a 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/addressbook.kt +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/addressbook.kt @@ -1,17 +1,17 @@ -class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email: kotlin.String? = "", phones: MutableList = mutableListOf(), someBytes: ByteArray? = ByteArray(0)) { - var name : kotlin.String? +class Person private constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList = mutableListOf(), someBytes: ByteArray = ByteArray(0)) { + var name : kotlin.String private set - var id : Int? + var id : Int private set - var email : kotlin.String? + var email : kotlin.String private set var phones : MutableList private set - var someBytes : ByteArray? + var someBytes : ByteArray private set @@ -38,11 +38,11 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email } } } - class PhoneNumber private constructor (number: kotlin.String? = "", type: PhoneType? = PhoneType.fromIntToPhoneType(0)) { - var number : kotlin.String? + class PhoneNumber private constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) { + var number : kotlin.String private set - var type : PhoneType? + var type : PhoneType private set @@ -57,20 +57,20 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email fun writeToNoTag (output: CodedOutputStream): Unit { output.writeString (1, number) - output.writeEnum (2, type?.ord) + output.writeEnum (2, type.ord) } - class BuilderPhoneNumber constructor (number: kotlin.String? = "", type: PhoneType? = PhoneType.fromIntToPhoneType(0)) { - var number : kotlin.String? + class BuilderPhoneNumber constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) { + var number : kotlin.String private set - fun setNumber(value: kotlin.String?): BuilderPhoneNumber { + fun setNumber(value: kotlin.String): BuilderPhoneNumber { number = value return this } - var type : PhoneType? + var type : PhoneType private set - fun setType(value: PhoneType?): BuilderPhoneNumber { + fun setType(value: PhoneType): BuilderPhoneNumber { type = value return this } @@ -142,24 +142,24 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email output.writeBytes (5, someBytes) } - class BuilderPerson constructor (name: kotlin.String? = "", id: Int? = 0, email: kotlin.String? = "", phones: MutableList = mutableListOf(), someBytes: ByteArray? = ByteArray(0)) { - var name : kotlin.String? + class BuilderPerson constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList = mutableListOf(), someBytes: ByteArray = ByteArray(0)) { + var name : kotlin.String private set - fun setName(value: kotlin.String?): BuilderPerson { + fun setName(value: kotlin.String): BuilderPerson { name = value return this } - var id : Int? + var id : Int private set - fun setId(value: Int?): BuilderPerson { + fun setId(value: Int): BuilderPerson { id = value return this } - var email : kotlin.String? + var email : kotlin.String private set - fun setEmail(value: kotlin.String?): BuilderPerson { + fun setEmail(value: kotlin.String): BuilderPerson { email = value return this } @@ -185,9 +185,9 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email return this } - var someBytes : ByteArray? + var someBytes : ByteArray private set - fun setSomeBytes(value: ByteArray?): BuilderPerson { + fun setSomeBytes(value: ByteArray): BuilderPerson { someBytes = value return this } @@ -257,7 +257,7 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email id = other.id email = other.email phones.addAll(other.phones) - someBytes?.plus(other.someBytes ?: ByteArray(0)) + someBytes.plus(other.someBytes) } fun mergeFrom (input: CodedInputStream) {