Removed nullable types from generated code

This commit is contained in:
dsavvinov
2016-07-15 16:54:25 +03:00
parent 7912da79ba
commit 86f65d6a6a
4 changed files with 26 additions and 27 deletions
@@ -137,7 +137,7 @@ void ClassGenerator::generateMergeMethods(io::Printer *printer) const {
// Bytes type is handled separately // Bytes type is handled separately
else if (properties[i]->protoType == FieldDescriptor::TYPE_BYTES) { else if (properties[i]->protoType == FieldDescriptor::TYPE_BYTES) {
vars["initValue"] = properties[i]->getInitValue(); 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 // for all other cases just take other's field
@@ -159,7 +159,7 @@ void FieldGenerator::generateSerializationCode(io::Printer *printer, bool isRead
printer->Print(vars, "$fieldName$ = $converter$(input.read$type$($maybeFieldNumber$))\n"); printer->Print(vars, "$fieldName$ = $converter$(input.read$type$($maybeFieldNumber$))\n");
} }
else { else {
printer->Print(vars, "output.write$type$ ($maybeFieldNumber$$maybeComma$$fieldName$?.ord)\n"); printer->Print(vars, "output.write$type$ ($maybeFieldNumber$$maybeComma$$fieldName$.ord)\n");
} }
return; return;
} }
@@ -81,7 +81,6 @@ string protobufToKotlinField(FieldDescriptor const * descriptor) {
case FieldDescriptor::LABEL_REQUIRED: case FieldDescriptor::LABEL_REQUIRED:
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case FieldDescriptor::LABEL_OPTIONAL:
postamble = "?";
break; break;
case FieldDescriptor::LABEL_REPEATED: case FieldDescriptor::LABEL_REPEATED:
#ifndef KOTLIN_GENERATED_CODE_LANGUAGE_LEVEL_LOW #ifndef KOTLIN_GENERATED_CODE_LANGUAGE_LEVEL_LOW
@@ -1,17 +1,17 @@
class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email: kotlin.String? = "", phones: MutableList <PhoneNumber> = mutableListOf(), someBytes: ByteArray? = ByteArray(0)) { class Person private constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList <PhoneNumber> = mutableListOf(), someBytes: ByteArray = ByteArray(0)) {
var name : kotlin.String? var name : kotlin.String
private set private set
var id : Int? var id : Int
private set private set
var email : kotlin.String? var email : kotlin.String
private set private set
var phones : MutableList <PhoneNumber> var phones : MutableList <PhoneNumber>
private set private set
var someBytes : ByteArray? var someBytes : ByteArray
private set 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)) { class PhoneNumber private constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) {
var number : kotlin.String? var number : kotlin.String
private set private set
var type : PhoneType? var type : PhoneType
private set private set
@@ -57,20 +57,20 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email
fun writeToNoTag (output: CodedOutputStream): Unit { fun writeToNoTag (output: CodedOutputStream): Unit {
output.writeString (1, number) 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)) { class BuilderPhoneNumber constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) {
var number : kotlin.String? var number : kotlin.String
private set private set
fun setNumber(value: kotlin.String?): BuilderPhoneNumber { fun setNumber(value: kotlin.String): BuilderPhoneNumber {
number = value number = value
return this return this
} }
var type : PhoneType? var type : PhoneType
private set private set
fun setType(value: PhoneType?): BuilderPhoneNumber { fun setType(value: PhoneType): BuilderPhoneNumber {
type = value type = value
return this return this
} }
@@ -142,24 +142,24 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email
output.writeBytes (5, someBytes) output.writeBytes (5, someBytes)
} }
class BuilderPerson constructor (name: kotlin.String? = "", id: Int? = 0, email: kotlin.String? = "", phones: MutableList <PhoneNumber> = mutableListOf(), someBytes: ByteArray? = ByteArray(0)) { class BuilderPerson constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList <PhoneNumber> = mutableListOf(), someBytes: ByteArray = ByteArray(0)) {
var name : kotlin.String? var name : kotlin.String
private set private set
fun setName(value: kotlin.String?): BuilderPerson { fun setName(value: kotlin.String): BuilderPerson {
name = value name = value
return this return this
} }
var id : Int? var id : Int
private set private set
fun setId(value: Int?): BuilderPerson { fun setId(value: Int): BuilderPerson {
id = value id = value
return this return this
} }
var email : kotlin.String? var email : kotlin.String
private set private set
fun setEmail(value: kotlin.String?): BuilderPerson { fun setEmail(value: kotlin.String): BuilderPerson {
email = value email = value
return this return this
} }
@@ -185,9 +185,9 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email
return this return this
} }
var someBytes : ByteArray? var someBytes : ByteArray
private set private set
fun setSomeBytes(value: ByteArray?): BuilderPerson { fun setSomeBytes(value: ByteArray): BuilderPerson {
someBytes = value someBytes = value
return this return this
} }
@@ -257,7 +257,7 @@ class Person private constructor (name: kotlin.String? = "", id: Int? = 0, email
id = other.id id = other.id
email = other.email email = other.email
phones.addAll(other.phones) phones.addAll(other.phones)
someBytes?.plus(other.someBytes ?: ByteArray(0)) someBytes.plus(other.someBytes)
} }
fun mergeFrom (input: CodedInputStream) { fun mergeFrom (input: CodedInputStream) {