From 33113ce9f9ef6d4240c4326564bb528087efcc94 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 19 Oct 2021 21:34:32 +0000 Subject: [PATCH 1/2] Fixing inlining and deprecation for repeated string fields in kotlin --- .../compiler/java/java_string_field.cc | 35 +++++++++---------- .../compiler/java/java_string_field_lite.cc | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index 28164c763379..cd6308b7f6ce 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -1,5 +1,4 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. +// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without @@ -968,16 +967,14 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // property for List WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print( - variables_, - "public val $kt_name$: " - "com.google.protobuf.kotlin.DslList" - "\n" - " @kotlin.OptIn" - "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - " get() = com.google.protobuf.kotlin.DslList(\n" - " $kt_dsl_builder$.${$get$capitalized_name$List$}$()\n" - " )\n"); + printer->Print(variables_, + "$kt_deprecation$public val $kt_name$: " + "com.google.protobuf.kotlin.DslList" + "\n" + " @kotlin.jvm.JvmSynthetic\n" + " get() = com.google.protobuf.kotlin.DslList(\n" + " $kt_dsl_builder$.${$get$capitalized_name$List$}$()\n" + " )\n"); // List.add(String) WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, @@ -994,13 +991,14 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += String WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ false); - printer->Print(variables_, + printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" - "public operator fun com.google.protobuf.kotlin.DslList" + "@Suppress(\"NOTHING_TO_INLINE\")\n" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(value: kotlin.String) {\n" - " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" + " add(value)\n" "}\n"); // List.addAll(Iterable) @@ -1019,14 +1017,15 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += Iterable WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ false); - printer->Print( + printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" - "public operator fun com.google.protobuf.kotlin.DslList" + "@Suppress(\"NOTHING_TO_INLINE\")\n" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(values: kotlin.collections.Iterable) {\n" - " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" + " addAll(values)\n" "}\n"); // List[Int] = String diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc index 57cd43677c48..183390331613 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -755,7 +755,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print( variables_, - "public val $kt_name$: " + "$kt_deprecation$public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "\n" " @kotlin.OptIn" From ad9eb238cc5293de5cc5c2607f9ccfb2f31e913c Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 19 Oct 2021 21:36:30 +0000 Subject: [PATCH 2/2] Fixing formatting --- src/google/protobuf/compiler/java/java_string_field.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index cd6308b7f6ce..1a0959e408bc 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -1,4 +1,5 @@ -// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without @@ -1017,7 +1018,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += Iterable WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ false); - printer->Print( + printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"