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
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
@@ -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;
}
@@ -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
@@ -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)) {
var name : kotlin.String?
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
private set
var id : Int?
var id : Int
private set
var email : kotlin.String?
var email : kotlin.String
private set
var phones : MutableList <PhoneNumber>
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 <PhoneNumber> = mutableListOf(), someBytes: ByteArray? = ByteArray(0)) {
var name : kotlin.String?
class BuilderPerson constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList <PhoneNumber> = 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) {