summaryrefslogtreecommitdiffstats
path: root/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc
diff options
context:
space:
mode:
authormikhnenko <[email protected]>2024-06-25 08:50:35 +0300
committermikhnenko <[email protected]>2024-06-25 09:00:27 +0300
commit509c9fc9e7b9c3b8be7307d72a4c966e5f9aa194 (patch)
tree4b8a6a44009906ac852e59efa0bc78bb12043a5b /contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc
parent7688f2313619a39a60ef3c2734d8efbc49a0a6db (diff)
Update protobuf to 3.20.2 and pyprotobuf to 3.20.3
Если это pull-request что-то сломал, то: - если это тест с канонизацией и еще нет pr с переканонизацией, то переканонизируйте пожалуйста сами - проверьте, что тест не флапает - приходите в [DEVTOOLSSUPPORT](https://st.yandex-team.ru/createTicket?queue=DEVTOOLSSUPPORT) - там вам обязательно помогут 987be5ed151f827f7f292f32420470b04b71a91d
Diffstat (limited to 'contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc')
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc54
1 files changed, 38 insertions, 16 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc
index e5343d6762e..9a5c25a538b 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc
@@ -40,6 +40,11 @@
#include <memory>
#include <vector>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/printer.h>
+#include <google/protobuf/wire_format.h>
+#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/java/java_context.h>
#include <google/protobuf/compiler/java/java_doc_comment.h>
#include <google/protobuf/compiler/java/java_enum.h>
@@ -50,11 +55,6 @@
#include <google/protobuf/compiler/java/java_message_builder_lite.h>
#include <google/protobuf/compiler/java/java_name_resolver.h>
#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/stubs/substitute.h>
namespace google {
namespace protobuf {
@@ -67,7 +67,7 @@ using internal::WireFormatLite;
namespace {
TProtoStringType MapValueImmutableClassdName(const Descriptor* descriptor,
ClassNameResolver* name_resolver) {
- const FieldDescriptor* value_field = descriptor->FindFieldByName("value");
+ const FieldDescriptor* value_field = descriptor->map_value();
GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type());
return name_resolver->GetImmutableClassName(value_field->message_type());
}
@@ -1273,6 +1273,9 @@ void ImmutableMessageGenerator::GenerateParsingConstructor(
printer->Print(
"} catch (com.google.protobuf.InvalidProtocolBufferException e) {\n"
" throw e.setUnfinishedMessage(this);\n"
+ "} catch (com.google.protobuf.UninitializedMessageException e) {\n"
+ " throw "
+ "e.asInvalidProtocolBufferException().setUnfinishedMessage(this);\n"
"} catch (java.io.IOException e) {\n"
" throw new com.google.protobuf.InvalidProtocolBufferException(\n"
" e).setUnfinishedMessage(this);\n"
@@ -1455,7 +1458,7 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const {
void ImmutableMessageGenerator::GenerateKotlinMembers(
io::Printer* printer) const {
printer->Print(
- "@kotlin.jvm.JvmSynthetic\n"
+ "@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n"
"public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): "
"$message$ "
@@ -1486,7 +1489,7 @@ void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers(
"kotlin.Unit): "
"$message$ =\n"
" $message_kt$.Dsl._create(this.toBuilder()).apply { block() "
- "}._build()\n",
+ "}._build()\n\n",
"message", name_resolver_->GetClassName(descriptor_, true), "message_kt",
name_resolver_->GetKotlinExtensionsClassName(descriptor_));
@@ -1495,6 +1498,24 @@ void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers(
ImmutableMessageGenerator(descriptor_->nested_type(i), context_)
.GenerateTopLevelKotlinMembers(printer);
}
+
+ GenerateKotlinOrNull(printer);
+}
+
+void ImmutableMessageGenerator::GenerateKotlinOrNull(io::Printer* printer) const {
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ const FieldDescriptor* field = descriptor_->field(i);
+ if (field->has_presence() && GetJavaType(field) == JAVATYPE_MESSAGE) {
+ printer->Print(
+ "val $full_classname$OrBuilder.$camelcase_name$OrNull: $full_name$?\n"
+ " get() = if (has$name$()) get$name$() else null\n\n",
+ "full_classname", name_resolver_->GetClassName(descriptor_, true),
+ "camelcase_name", context_->GetFieldGeneratorInfo(field)->name,
+ "full_name",
+ name_resolver_->GetImmutableClassName(field->message_type()), "name",
+ context_->GetFieldGeneratorInfo(field)->capitalized_name);
+ }
+ }
}
void ImmutableMessageGenerator::GenerateKotlinExtensions(
@@ -1504,7 +1525,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@Suppress(\"UNCHECKED_CAST\")\n"
"@kotlin.jvm.JvmSynthetic\n"
- "public operator fun <T> get(extension: "
+ "public operator fun <T : kotlin.Any> get(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>): T {\n"
" return if (extension.isRepeated) {\n"
" get(extension as com.google.protobuf.ExtensionLite<$message$, "
@@ -1520,7 +1541,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
"@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n"
- "public operator fun <E> get(\n"
+ "public operator fun <E : kotlin.Any> get(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, List<E>>\n"
"): com.google.protobuf.kotlin.ExtensionList<E, $message$> {\n"
" return com.google.protobuf.kotlin.ExtensionList(extension, "
@@ -1549,7 +1570,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.PublishedApi\n"
- "internal fun <T> setExtension(extension: "
+ "internal fun <T : kotlin.Any> setExtension(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>, "
"value: T) {\n"
" _builder.setExtension(extension, value)\n"
@@ -1592,7 +1613,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "public fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
+ "public fun <E : kotlin.Any> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.add(value: E) {\n"
" _builder.addExtension(this.extension, value)\n"
"}\n\n",
@@ -1601,7 +1622,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "public inline operator fun <E> "
+ "public inline operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign"
"(value: E) {\n"
@@ -1611,7 +1632,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "public fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
+ "public fun <E : kotlin.Any> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.addAll(values: Iterable<E>) {\n"
" for (value in values) {\n"
" add(value)\n"
@@ -1622,7 +1643,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "public inline operator fun <E> "
+ "public inline operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign(values: "
"Iterable<E>) {\n"
@@ -1632,7 +1653,8 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "public operator fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
+ "public operator fun <E : kotlin.Any> "
+ "com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.set(index: Int, value: "
"E) {\n"
" _builder.setExtension(this.extension, index, value)\n"