aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc
diff options
context:
space:
mode:
authornechda <nechda@yandex-team.com>2024-08-29 23:50:27 +0300
committernechda <nechda@yandex-team.com>2024-08-30 00:05:25 +0300
commite10d6638f07a82edae3ea8197b9f5c0affcc07ea (patch)
tree571c38cec05813766a1ad290c9d51ce7ace52919 /contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc
parente79b38f2bbbf78d295d1901d2a79f898022d5224 (diff)
downloadydb-e10d6638f07a82edae3ea8197b9f5c0affcc07ea.tar.gz
Update cpp-protobuf to 22.5
Привет!\ Этот PR переключат cpp & python библиотеки protobuf на версию 22.5 Если у вас возникли проблемы после влития этого PR: 1. Если начали падать канон тесты, то проведите их переканонизацию 2. Прочитайте <https://wiki.yandex-team.ru/users/nechda/obnovlenie-cpp-protobuf-22.5/> страничку с основными изменениями 3. Если страничка в вики не помогла, то пишите в [DEVTOOLSSUPPORT](https://st.yandex-team.ru/DEVTOOLSSUPPORT) 7fecade616c20a841b9e9af7b7998bdfc8d2807d
Diffstat (limited to 'contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc')
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc91
1 files changed, 64 insertions, 27 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc
index 7fdd4ab9b8..ae07f8c66f 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc
@@ -32,19 +32,18 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/enum_lite.h>
+#include "google/protobuf/compiler/java/enum_lite.h"
-#include <map>
#include <string>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/compiler/java/context.h>
-#include <google/protobuf/compiler/java/doc_comment.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/stubs/map_util.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "y_absl/strings/str_cat.h"
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/doc_comment.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/descriptor.pb.h"
+#include "google/protobuf/io/printer.h"
namespace google {
namespace protobuf {
@@ -87,9 +86,9 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Indent();
for (int i = 0; i < canonical_values_.size(); i++) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["name"] = canonical_values_[i]->name();
- vars["number"] = StrCat(canonical_values_[i]->number());
+ vars["number"] = y_absl::StrCat(canonical_values_[i]->number());
WriteEnumValueDocComment(printer, canonical_values_[i]);
if (canonical_values_[i]->options().deprecated()) {
printer->Print("@java.lang.Deprecated\n");
@@ -110,7 +109,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
// -----------------------------------------------------------------
for (int i = 0; i < aliases_.size(); i++) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["classname"] = descriptor_->name();
vars["name"] = aliases_[i].value->name();
vars["canonical_name"] = aliases_[i].canonical_value->name();
@@ -121,9 +120,9 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
}
for (int i = 0; i < descriptor_->value_count(); i++) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["name"] = descriptor_->value(i)->name();
- vars["number"] = StrCat(descriptor_->value(i)->number());
+ vars["number"] = y_absl::StrCat(descriptor_->value(i)->number());
vars["{"] = "";
vars["}"] = "";
vars["deprecation"] = descriptor_->value(i)->options().deprecated()
@@ -153,17 +152,26 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Print(
" return value;\n"
"}\n"
- "\n"
- "/**\n"
- " * @param value The number of the enum to look for.\n"
- " * @return The enum associated with the given number.\n"
- " * @deprecated Use {@link #forNumber(int)} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "public static $classname$ valueOf(int value) {\n"
- " return forNumber(value);\n"
- "}\n"
- "\n"
+ "\n");
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ "/**\n"
+ " * @param value The number of the enum to look for.\n"
+ " * @return The enum associated with the given number.\n"
+ " * @deprecated Use {@link #forNumber(int)} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "public static $classname$ valueOf(int value) {\n"
+ " return forNumber(value);\n"
+ "}\n"
+ "\n",
+ "classname", descriptor_->name());
+ }
+
+ if (!context_->options().opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n");
+ }
+ printer->Print(
"public static $classname$ forNumber(int value) {\n"
" switch (value) {\n",
"classname", descriptor_->name());
@@ -173,7 +181,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < canonical_values_.size(); i++) {
printer->Print("case $number$: return $name$;\n", "name",
canonical_values_[i]->name(), "number",
- StrCat(canonical_values_[i]->number()));
+ y_absl::StrCat(canonical_values_[i]->number()));
}
printer->Outdent();
@@ -212,6 +220,35 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
" };\n"
"\n",
"classname", descriptor_->name());
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ "/**\n"
+ " * Override of toString that prints the number and name.\n"
+ " * This is primarily intended as a developer aid.\n"
+ " *\n"
+ " * <p>NOTE: This implementation is liable to change in the future,\n"
+ " * and should not be relied on in code.\n"
+ " */\n"
+ "@java.lang.Override\n"
+ "public java.lang.String toString() {\n"
+ " StringBuilder result = new StringBuilder(\"<\");\n"
+ " result.append(getClass().getName()).append('@')\n"
+ " .append(java.lang.Integer.toHexString(\n"
+ " java.lang.System.identityHashCode(this)));\n");
+ if (SupportUnknownEnumValue(descriptor_->file())) {
+ printer->Print(
+ " if (this != UNRECOGNIZED) {\n"
+ " result.append(\" number=\").append(getNumber());\n"
+ " }\n");
+ } else {
+ printer->Print(" result.append(\" number=\").append(getNumber());\n");
+ }
+ printer->Print(
+ " return result.append(\" name=\")\n"
+ " .append(name()).append('>').toString();\n"
+ "}\n"
+ "\n");
+ }
printer->Print(
"private final int value;\n\n"