aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/protoc/src/google/protobuf/compiler/java
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
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')
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/context.cc89
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/context.h28
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc184
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.h25
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum.cc79
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum.h7
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.cc350
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.h48
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.cc201
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.h28
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.cc91
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.h7
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/extension.cc51
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/extension.h19
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.cc28
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.h12
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/field.cc97
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/field.h49
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/file.cc150
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/file.h9
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/generator.cc80
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/generator.h15
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.cc20
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.h11
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.cc408
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.h91
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.cc23
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.h11
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.cc584
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.h12
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.cc295
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.h4
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message.cc548
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message.h20
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.cc576
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.h20
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.cc72
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.h11
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.cc496
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.h69
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.cc137
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.h27
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.cc268
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.h9
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.cc51
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.h103
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.cc99
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.h32
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/names.cc193
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/names.h37
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/options.h7
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.cc343
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.h48
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.cc195
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.h28
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/service.cc49
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/service.h12
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.cc63
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.h7
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.cc342
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.h44
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.cc183
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.h28
63 files changed, 3986 insertions, 3237 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/context.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/context.cc
index 463aa1f5ab..839fb6e2f5 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/context.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/context.cc
@@ -28,14 +28,18 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <google/protobuf/compiler/java/context.h>
+#include "google/protobuf/compiler/java/context.h"
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/compiler/java/field.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/stubs/map_util.h>
+#include <string>
+
+#include "y_absl/log/absl_log.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/string_view.h"
+#include "y_absl/strings/strip.h"
+#include "google/protobuf/compiler/java/field.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/descriptor.h"
namespace google {
namespace protobuf {
@@ -43,7 +47,7 @@ namespace compiler {
namespace java {
Context::Context(const FileDescriptor* file, const Options& options)
- : name_resolver_(new ClassNameResolver), options_(options) {
+ : name_resolver_(new ClassNameResolver(options)), options_(options) {
InitializeFieldGeneratorInfo(file);
}
@@ -54,11 +58,17 @@ ClassNameResolver* Context::GetNameResolver() const {
}
namespace {
+bool EqualWithSuffix(y_absl::string_view name1, y_absl::string_view suffix,
+ y_absl::string_view name2) {
+ if (!y_absl::ConsumeSuffix(&name2, suffix)) return false;
+ return name1 == name2;
+}
+
// Whether two fields have conflicting accessors (assuming name1 and name2
// are different). name1 and name2 are field1 and field2's camel-case name
// respectively.
-bool IsConflicting(const FieldDescriptor* field1, const TProtoStringType& name1,
- const FieldDescriptor* field2, const TProtoStringType& name2,
+bool IsConflicting(const FieldDescriptor* field1, y_absl::string_view name1,
+ const FieldDescriptor* field2, y_absl::string_view name2,
TProtoStringType* info) {
if (field1->is_repeated()) {
if (field2->is_repeated()) {
@@ -66,16 +76,18 @@ bool IsConflicting(const FieldDescriptor* field1, const TProtoStringType& name1,
return false;
} else {
// field1 is repeated, and field2 is not.
- if (name1 + "Count" == name2) {
- *info = "both repeated field \"" + field1->name() + "\" and singular " +
- "field \"" + field2->name() + "\" generate the method \"" +
- "get" + name1 + "Count()\"";
+ if (EqualWithSuffix(name1, "Count", name2)) {
+ *info = y_absl::StrCat("both repeated field \"", field1->name(),
+ "\" and singular ", "field \"", field2->name(),
+ "\" generate the method \"", "get", name1,
+ "Count()\"");
return true;
}
- if (name1 + "List" == name2) {
- *info = "both repeated field \"" + field1->name() + "\" and singular " +
- "field \"" + field2->name() + "\" generate the method \"" +
- "get" + name1 + "List()\"";
+ if (EqualWithSuffix(name1, "List", name2)) {
+ *info =
+ y_absl::StrCat("both repeated field \"", field1->name(),
+ "\" and singular ", "field \"", field2->name(),
+ "\" generate the method \"", "get", name1, "List()\"");
return true;
}
// Well, there are obviously many more conflicting cases, but it probably
@@ -131,15 +143,15 @@ void Context::InitializeFieldGeneratorInfoForFields(
std::vector<TProtoStringType> conflict_reason(fields.size());
for (int i = 0; i < fields.size(); ++i) {
const FieldDescriptor* field = fields[i];
- const TProtoStringType& name = UnderscoresToCapitalizedCamelCase(field);
+ const TProtoStringType& name = CapitalizedFieldName(field);
for (int j = i + 1; j < fields.size(); ++j) {
const FieldDescriptor* other = fields[j];
- const TProtoStringType& other_name = UnderscoresToCapitalizedCamelCase(other);
+ const TProtoStringType& other_name = CapitalizedFieldName(other);
if (name == other_name) {
is_conflict[i] = is_conflict[j] = true;
conflict_reason[i] = conflict_reason[j] =
- "capitalized name of field \"" + field->name() +
- "\" conflicts with field \"" + other->name() + "\"";
+ y_absl::StrCat("capitalized name of field \"", field->name(),
+ "\" conflicts with field \"", other->name(), "\"");
} else if (IsConflicting(field, name, other, other_name,
&conflict_reason[j])) {
is_conflict[i] = is_conflict[j] = true;
@@ -147,20 +159,21 @@ void Context::InitializeFieldGeneratorInfoForFields(
}
}
if (is_conflict[i]) {
- GOOGLE_LOG(WARNING) << "field \"" << field->full_name() << "\" is conflicting "
- << "with another field: " << conflict_reason[i];
+ Y_ABSL_LOG(WARNING) << "field \"" << field->full_name()
+ << "\" is conflicting "
+ << "with another field: " << conflict_reason[i];
}
}
for (int i = 0; i < fields.size(); ++i) {
const FieldDescriptor* field = fields[i];
FieldGeneratorInfo info;
info.name = CamelCaseFieldName(field);
- info.capitalized_name = UnderscoresToCapitalizedCamelCase(field);
+ info.capitalized_name = CapitalizedFieldName(field);
// For fields conflicting with some other fields, we append the field
// number to their field names in generated code to avoid conflicts.
if (is_conflict[i]) {
- info.name += StrCat(field->number());
- info.capitalized_name += StrCat(field->number());
+ y_absl::StrAppend(&info.name, field->number());
+ y_absl::StrAppend(&info.capitalized_name, field->number());
info.disambiguated_reason = conflict_reason[i];
}
field_generator_info_map_[field] = info;
@@ -169,24 +182,22 @@ void Context::InitializeFieldGeneratorInfoForFields(
const FieldGeneratorInfo* Context::GetFieldGeneratorInfo(
const FieldDescriptor* field) const {
- const FieldGeneratorInfo* result =
- FindOrNull(field_generator_info_map_, field);
- if (result == NULL) {
- GOOGLE_LOG(FATAL) << "Can not find FieldGeneratorInfo for field: "
- << field->full_name();
+ auto it = field_generator_info_map_.find(field);
+ if (it == field_generator_info_map_.end()) {
+ Y_ABSL_LOG(FATAL) << "Can not find FieldGeneratorInfo for field: "
+ << field->full_name();
}
- return result;
+ return &it->second;
}
const OneofGeneratorInfo* Context::GetOneofGeneratorInfo(
const OneofDescriptor* oneof) const {
- const OneofGeneratorInfo* result =
- FindOrNull(oneof_generator_info_map_, oneof);
- if (result == NULL) {
- GOOGLE_LOG(FATAL) << "Can not find OneofGeneratorInfo for oneof: "
- << oneof->name();
+ auto it = oneof_generator_info_map_.find(oneof);
+ if (it == oneof_generator_info_map_.end()) {
+ Y_ABSL_LOG(FATAL) << "Can not find OneofGeneratorInfo for oneof: "
+ << oneof->name();
}
- return result;
+ return &it->second;
}
// Does this message class have generated parsing, serialization, and other
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/context.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/context.h
index c224ab73f5..57b994a8e3 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/context.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/context.h
@@ -31,12 +31,13 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__
-#include <map>
#include <memory>
#include <vector>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/compiler/java/options.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/options.h"
+#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@@ -65,6 +66,8 @@ struct OneofGeneratorInfo;
class Context {
public:
Context(const FileDescriptor* file, const Options& options);
+ Context(const Context&) = delete;
+ Context& operator=(const Context&) = delete;
~Context();
// Get the name resolver associated with this context. The resolver
@@ -97,14 +100,27 @@ class Context {
const std::vector<const FieldDescriptor*>& fields);
std::unique_ptr<ClassNameResolver> name_resolver_;
- std::map<const FieldDescriptor*, FieldGeneratorInfo>
+ y_absl::flat_hash_map<const FieldDescriptor*, FieldGeneratorInfo>
field_generator_info_map_;
- std::map<const OneofDescriptor*, OneofGeneratorInfo>
+ y_absl::flat_hash_map<const OneofDescriptor*, OneofGeneratorInfo>
oneof_generator_info_map_;
Options options_;
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Context);
};
+template <typename Descriptor>
+void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer,
+ Descriptor* descriptor, bool immutable,
+ const TProtoStringType& suffix = "") {
+ if (IsOwnFile(descriptor, immutable)) {
+ PrintGeneratedAnnotation(printer, '$',
+ context->options().annotate_code
+ ? AnnotationFileName(descriptor, suffix)
+ : "",
+ context->options());
+ }
+}
+
+
} // namespace java
} // namespace compiler
} // namespace protobuf
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc
index ec7dce7d34..74fb087ccf 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc
@@ -32,13 +32,14 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/doc_comment.h>
+#include "google/protobuf/compiler/java/doc_comment.h"
#include <vector>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/strings/str_split.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/descriptor.pb.h"
+#include "google/protobuf/io/printer.h"
namespace google {
namespace protobuf {
@@ -103,26 +104,65 @@ TProtoStringType EscapeJavadoc(const TProtoStringType& input) {
return result;
}
+static TProtoStringType EscapeKdoc(const TProtoStringType& input) {
+ TProtoStringType result;
+ result.reserve(input.size() * 2);
+
+ char prev = 'a';
+
+ for (char c : input) {
+ switch (c) {
+ case '*':
+ // Avoid "/*".
+ if (prev == '/') {
+ result.append("&#42;");
+ } else {
+ result.push_back(c);
+ }
+ break;
+ case '/':
+ // Avoid "*/".
+ if (prev == '*') {
+ result.append("&#47;");
+ } else {
+ result.push_back(c);
+ }
+ break;
+ default:
+ result.push_back(c);
+ break;
+ }
+
+ prev = c;
+ }
+
+ return result;
+}
+
static void WriteDocCommentBodyForLocation(io::Printer* printer,
- const SourceLocation& location) {
+ const SourceLocation& location,
+ const bool kdoc) {
TProtoStringType comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;
if (!comments.empty()) {
- // TODO(kenton): Ideally we should parse the comment text as Markdown and
- // write it back as HTML, but this requires a Markdown parser. For now
- // we just use <pre> to get fixed-width text formatting.
-
- // If the comment itself contains block comment start or end markers,
- // HTML-escape them so that they don't accidentally close the doc comment.
- comments = EscapeJavadoc(comments);
+ if (kdoc) {
+ comments = EscapeKdoc(comments);
+ } else {
+ comments = EscapeJavadoc(comments);
+ }
- std::vector<TProtoStringType> lines = Split(comments, "\n");
+ std::vector<TProtoStringType> lines = y_absl::StrSplit(comments, "\n");
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
- printer->Print(" * <pre>\n");
+ if (kdoc) {
+ printer->Print(" * ```\n");
+ } else {
+ printer->Print(" * <pre>\n");
+ }
+
for (int i = 0; i < lines.size(); i++) {
// Most lines should start with a space. Watch out for lines that start
// with a /, since putting that right after the leading asterisk will
@@ -133,18 +173,23 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer,
printer->Print(" *$line$\n", "line", lines[i]);
}
}
- printer->Print(
- " * </pre>\n"
- " *\n");
+
+ if (kdoc) {
+ printer->Print(" * ```\n");
+ } else {
+ printer->Print(" * </pre>\n");
+ }
+ printer->Print(" *\n");
}
}
template <typename DescriptorType>
static void WriteDocCommentBody(io::Printer* printer,
- const DescriptorType* descriptor) {
+ const DescriptorType* descriptor,
+ const bool kdoc) {
SourceLocation location;
if (descriptor->GetSourceLocation(&location)) {
- WriteDocCommentBodyForLocation(printer, location);
+ WriteDocCommentBodyForLocation(printer, location, kdoc);
}
}
@@ -164,16 +209,36 @@ static TProtoStringType FirstLineOf(const TProtoStringType& value) {
return result;
}
-void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) {
+static void WriteDebugString(io::Printer* printer, const FieldDescriptor* field,
+ const bool kdoc) {
+ if (kdoc) {
+ printer->Print(" * `$def$`\n", "def",
+ EscapeKdoc(FirstLineOf(field->DebugString())));
+ } else {
+ printer->Print(" * <code>$def$</code>\n", "def",
+ EscapeJavadoc(FirstLineOf(field->DebugString())));
+ }
+}
+
+void WriteMessageDocComment(io::Printer* printer, const Descriptor* message,
+ const bool kdoc) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, message);
- printer->Print(
- " * Protobuf type {@code $fullname$}\n"
- " */\n",
- "fullname", EscapeJavadoc(message->full_name()));
+ WriteDocCommentBody(printer, message, kdoc);
+ if (kdoc) {
+ printer->Print(
+ " * Protobuf type `$fullname$`\n"
+ " */\n",
+ "fullname", EscapeKdoc(message->full_name()));
+ } else {
+ printer->Print(
+ " * Protobuf type {@code $fullname$}\n"
+ " */\n",
+ "fullname", EscapeJavadoc(message->full_name()));
+ }
}
-void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) {
+void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field,
+ const bool kdoc) {
// We start the comment with the main body based on the comments from the
// .proto file (if present). We then continue with the field declaration,
// e.g.:
@@ -181,9 +246,14 @@ void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) {
// And then we end with the javadoc tags if applicable.
// If the field is a group, the debug string might end with {.
printer->Print("/**\n");
- WriteDocCommentBody(printer, field);
- printer->Print(" * <code>$def$</code>\n", "def",
- EscapeJavadoc(FirstLineOf(field->DebugString())));
+ WriteDocCommentBody(printer, field, kdoc);
+ if (kdoc) {
+ printer->Print(" * `$def$`\n", "def",
+ EscapeKdoc(FirstLineOf(field->DebugString())));
+ } else {
+ printer->Print(" * <code>$def$</code>\n", "def",
+ EscapeJavadoc(FirstLineOf(field->DebugString())));
+ }
printer->Print(" */\n");
}
@@ -214,12 +284,11 @@ void WriteDeprecatedJavadoc(io::Printer* printer, const FieldDescriptor* field,
void WriteFieldAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
- const bool builder) {
+ const bool builder, const bool kdoc) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, field);
- printer->Print(" * <code>$def$</code>\n", "def",
- EscapeJavadoc(FirstLineOf(field->DebugString())));
- WriteDeprecatedJavadoc(printer, field, type);
+ WriteDocCommentBody(printer, field, kdoc);
+ WriteDebugString(printer, field, kdoc);
+ if (!kdoc) WriteDeprecatedJavadoc(printer, field, type);
switch (type) {
case HAZZER:
printer->Print(" * @return Whether the $name$ field is set.\n", "name",
@@ -273,12 +342,12 @@ void WriteFieldAccessorDocComment(io::Printer* printer,
void WriteFieldEnumValueAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
- const bool builder) {
+ const bool builder,
+ const bool kdoc) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, field);
- printer->Print(" * <code>$def$</code>\n", "def",
- EscapeJavadoc(FirstLineOf(field->DebugString())));
- WriteDeprecatedJavadoc(printer, field, type);
+ WriteDocCommentBody(printer, field, kdoc);
+ WriteDebugString(printer, field, kdoc);
+ if (!kdoc) WriteDeprecatedJavadoc(printer, field, type);
switch (type) {
case HAZZER:
// Should never happen
@@ -343,12 +412,12 @@ void WriteFieldEnumValueAccessorDocComment(io::Printer* printer,
void WriteFieldStringBytesAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
- const bool builder) {
+ const bool builder,
+ const bool kdoc) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, field);
- printer->Print(" * <code>$def$</code>\n", "def",
- EscapeJavadoc(FirstLineOf(field->DebugString())));
- WriteDeprecatedJavadoc(printer, field, type);
+ WriteDocCommentBody(printer, field, kdoc);
+ WriteDebugString(printer, field, kdoc);
+ if (!kdoc) WriteDeprecatedJavadoc(printer, field, type);
switch (type) {
case HAZZER:
// Should never happen
@@ -399,19 +468,28 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer,
// Enum
-void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) {
+void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_,
+ const bool kdoc) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, enum_);
- printer->Print(
- " * Protobuf enum {@code $fullname$}\n"
- " */\n",
- "fullname", EscapeJavadoc(enum_->full_name()));
+ WriteDocCommentBody(printer, enum_, kdoc);
+ if (kdoc) {
+ printer->Print(
+ " * Protobuf enum `$fullname$`\n"
+ " */\n",
+ "fullname", EscapeKdoc(enum_->full_name()));
+ } else {
+ printer->Print(
+ " * Protobuf enum {@code $fullname$}\n"
+ " */\n",
+ "fullname", EscapeJavadoc(enum_->full_name()));
+ }
}
void WriteEnumValueDocComment(io::Printer* printer,
const EnumValueDescriptor* value) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, value);
+ WriteDocCommentBody(printer, value, /* kdoc */ false);
+
printer->Print(
" * <code>$def$</code>\n"
" */\n",
@@ -421,7 +499,7 @@ void WriteEnumValueDocComment(io::Printer* printer,
void WriteServiceDocComment(io::Printer* printer,
const ServiceDescriptor* service) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, service);
+ WriteDocCommentBody(printer, service, /* kdoc */ false);
printer->Print(
" * Protobuf service {@code $fullname$}\n"
" */\n",
@@ -431,7 +509,7 @@ void WriteServiceDocComment(io::Printer* printer,
void WriteMethodDocComment(io::Printer* printer,
const MethodDescriptor* method) {
printer->Print("/**\n");
- WriteDocCommentBody(printer, method);
+ WriteDocCommentBody(printer, method, /* kdoc */ false);
printer->Print(
" * <code>$def$</code>\n"
" */\n",
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.h
index 52d6f77474..2c8ecc4047 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.h
@@ -35,10 +35,10 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__
-#include <google/protobuf/descriptor.h>
+#include "google/protobuf/descriptor.h"
// Must be included last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -67,21 +67,27 @@ enum FieldAccessorType {
LIST_MULTI_ADDER
};
-void WriteMessageDocComment(io::Printer* printer, const Descriptor* message);
-void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field);
+void WriteMessageDocComment(io::Printer* printer, const Descriptor* message,
+ const bool kdoc = false);
+void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field,
+ const bool kdoc = false);
void WriteFieldAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
- const bool builder = false);
+ const bool builder = false,
+ const bool kdoc = false);
void WriteFieldEnumValueAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
- const bool builder = false);
+ const bool builder = false,
+ const bool kdoc = false);
void WriteFieldStringBytesAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
- const bool builder = false);
-void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_);
+ const bool builder = false,
+ const bool kdoc = false);
+void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_,
+ const bool kdoc = false);
void WriteEnumValueDocComment(io::Printer* printer,
const EnumValueDescriptor* value);
void WriteServiceDocComment(io::Printer* printer,
@@ -90,6 +96,7 @@ void WriteMethodDocComment(io::Printer* printer,
const MethodDescriptor* method);
// Exposed for testing only.
+// Also called by proto1-Java code generator.
PROTOC_EXPORT TProtoStringType EscapeJavadoc(const TProtoStringType& input);
} // namespace java
@@ -97,6 +104,6 @@ PROTOC_EXPORT TProtoStringType EscapeJavadoc(const TProtoStringType& input);
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.cc
index 5ba5e630c0..000cd54882 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.cc
@@ -32,21 +32,21 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/enum.h>
+#include "google/protobuf/compiler/java/enum.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 "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"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -80,6 +80,10 @@ EnumGenerator::~EnumGenerator() {}
void EnumGenerator::Generate(io::Printer* printer) {
WriteEnumDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_);
+
+ if (!context_->options().opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
+ }
printer->Print(
"$deprecation$public enum $classname$\n"
" implements com.google.protobuf.ProtocolMessageEnum {\n",
@@ -99,10 +103,10 @@ void EnumGenerator::Generate(io::Printer* printer) {
}
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["index"] = StrCat(canonical_values_[i]->index());
- vars["number"] = StrCat(canonical_values_[i]->number());
+ vars["index"] = y_absl::StrCat(canonical_values_[i]->index());
+ 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");
@@ -131,7 +135,7 @@ void EnumGenerator::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();
@@ -142,9 +146,9 @@ void EnumGenerator::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()
@@ -181,23 +185,32 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print(
" return value;\n"
"}\n"
- "\n"
- "/**\n"
- " * @param value The numeric wire value of the corresponding enum "
- "entry.\n"
- " * @return The enum associated with the given numeric wire value.\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 numeric wire value of the corresponding enum "
+ "entry.\n"
+ " * @return The enum associated with the given numeric wire value.\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());
+ }
+ printer->Print(
"/**\n"
" * @param value The numeric wire value of the corresponding enum "
"entry.\n"
" * @return The enum associated with the given numeric wire value.\n"
- " */\n"
+ " */\n");
+ 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());
@@ -207,7 +220,7 @@ void EnumGenerator::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();
@@ -277,7 +290,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
" return $file$.getDescriptor().getEnumTypes().get($index$);\n",
"file",
name_resolver_->GetClassName(descriptor_->file(), immutable_api_),
- "index", StrCat(descriptor_->index()));
+ "index", y_absl::StrCat(descriptor_->index()));
} else {
printer->Print(
" return $parent$.$descriptor$.getEnumTypes().get($index$);\n",
@@ -290,7 +303,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
.no_standard_descriptor_accessor()
? "getDefaultInstance().getDescriptorForType()"
: "getDescriptor()",
- "index", StrCat(descriptor_->index()));
+ "index", y_absl::StrCat(descriptor_->index()));
}
printer->Print(
@@ -394,4 +407,4 @@ bool EnumGenerator::CanUseEnumValues() {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.h
index 0a2c363b53..ae85b0c34c 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum.h
@@ -37,7 +37,8 @@
#include <string>
#include <vector>
-#include <google/protobuf/descriptor.h>
+
+#include "google/protobuf/descriptor.h"
namespace google {
namespace protobuf {
@@ -62,6 +63,8 @@ class EnumGenerator {
public:
EnumGenerator(const EnumDescriptor* descriptor, bool immutable_api,
Context* context);
+ EnumGenerator(const EnumGenerator&) = delete;
+ EnumGenerator& operator=(const EnumGenerator&) = delete;
~EnumGenerator();
void Generate(io::Printer* printer);
@@ -88,8 +91,6 @@ class EnumGenerator {
ClassNameResolver* name_resolver_;
bool CanUseEnumValues();
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.cc
index 97e1742cc9..33ed3ae00f 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.cc
@@ -32,24 +32,24 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/enum_field.h>
+#include "google/protobuf/compiler/java/enum_field.h"
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "y_absl/container/flat_hash_map.h"
+#include "y_absl/log/absl_check.h"
+#include "y_absl/log/absl_log.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/io/printer.h"
+#include "google/protobuf/wire_format.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -58,62 +58,51 @@ namespace java {
namespace {
-void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
- int builderBitIndex, const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetEnumVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
name_resolver->GetImmutableClassName(descriptor->enum_type());
- (*variables)["kt_type"] = (*variables)["type"];
+ variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])});
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->enum_type());
- (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
+ (*variables)["default"] =
+ ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
- StrCat(descriptor->default_value_enum()->number());
- (*variables)["tag"] = StrCat(
+ y_absl::StrCat(descriptor->default_value_enum()->number());
+ (*variables)["tag"] = y_absl::StrCat(
static_cast<arc_i32>(internal::WireFormat::MakeTag(descriptor)));
- (*variables)["tag_size"] = StrCat(
+ (*variables)["tag_size"] = y_absl::StrCat(
internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
- (*variables)["on_changed"] = "onChanged();";
- // Use deprecated valueOf() method to be compatible with old generated code
- // for v2.5.0/v2.6.1.
- // TODO(xiaofeng): Use "forNumber" when we no longer support compatibility
- // with v2.5.0/v2.6.1, and remove the @SuppressWarnings annotations.
- (*variables)["for_number"] = "valueOf";
-
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
- (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
-
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
- (*variables)["set_has_field_bit_builder"] =
- GenerateSetBit(builderBitIndex) + ";";
- (*variables)["clear_has_field_bit_builder"] =
- GenerateClearBit(builderBitIndex) + ";";
-
+ y_absl::StrCat(GenerateSetBit(messageBitIndex), ";");
+ (*variables)["set_has_field_bit_to_local"] =
+ GenerateSetBitToLocal(messageBitIndex);
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
(*variables)["set_has_field_bit_message"] = "";
- (*variables)["set_has_field_bit_builder"] = "";
- (*variables)["clear_has_field_bit_builder"] = "";
-
- (*variables)["is_field_present_message"] =
- (*variables)["name"] + "_ != " + (*variables)["default"] +
- ".getNumber()";
+ (*variables)["set_has_field_bit_to_local"] = "";
+ variables->insert({"is_field_present_message",
+ y_absl::StrCat((*variables)["name"], "_ != ",
+ (*variables)["default"], ".getNumber()")});
}
// For repeated builders, one bit is used for whether the array is immutable.
@@ -121,22 +110,21 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex);
(*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex);
- // For repeated fields, one bit is used for whether the array is immutable
- // in the parsing constructor.
- (*variables)["get_mutable_bit_parser"] =
- GenerateGetBitMutableLocal(builderBitIndex);
- (*variables)["set_mutable_bit_parser"] =
- GenerateSetBitMutableLocal(builderBitIndex);
+ (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
+ // Note that these have a trailing ";".
+ (*variables)["set_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateSetBit(builderBitIndex), ";");
+ (*variables)["clear_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateClearBit(builderBitIndex), ";");
(*variables)["get_has_field_bit_from_local"] =
GenerateGetBitFromLocal(builderBitIndex);
- (*variables)["set_has_field_bit_to_local"] =
- GenerateSetBitToLocal(messageBitIndex);
if (SupportUnknownEnumValue(descriptor->file())) {
- (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED";
+ variables->insert(
+ {"unknown", y_absl::StrCat((*variables)["type"], ".UNRECOGNIZED")});
} else {
- (*variables)["unknown"] = (*variables)["default"];
+ variables->insert({"unknown", (*variables)["default"]});
}
}
@@ -147,21 +135,30 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ message_bit_index_(messageBitIndex),
+ builder_bit_index_(builderBitIndex),
+ name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
- &variables_);
+ &variables_, context);
}
ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {}
+int ImmutableEnumFieldGenerator::GetMessageBitIndex() const {
+ return message_bit_index_;
+}
+
+int ImmutableEnumFieldGenerator::GetBuilderBitIndex() const {
+ return builder_bit_index_;
+}
+
int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const {
return HasHasbit(descriptor_) ? 1 : 0;
}
-int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const {
- return GetNumBitsForMessage();
-}
+int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { return 1; }
void ImmutableEnumFieldGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
@@ -180,7 +177,7 @@ void ImmutableEnumFieldGenerator::GenerateInterfaceMembers(
}
void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
- printer->Print(variables_, "private int $name$_;\n");
+ printer->Print(variables_, "private int $name$_ = $default_number$;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
@@ -204,8 +201,7 @@ void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"@java.lang.Override $deprecation$public $type$ "
"${$get$capitalized_name$$}$() {\n"
- " @SuppressWarnings(\"deprecation\")\n"
- " $type$ result = $type$.$for_number$($name$_);\n"
+ " $type$ result = $type$.forNumber($name$_);\n"
" return result == null ? $unknown$ : result;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -236,9 +232,9 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder "
"${$set$capitalized_name$Value$}$(int value) {\n"
- " $set_has_field_bit_builder$\n"
" $name$_ = value;\n"
- " $on_changed$\n"
+ " $set_has_field_bit_builder$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -247,8 +243,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
- " @SuppressWarnings(\"deprecation\")\n"
- " $type$ result = $type$.$for_number$($name$_);\n"
+ " $type$ result = $type$.forNumber($name$_);\n"
" return result == null ? $unknown$ : result;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -262,7 +257,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
" }\n"
" $set_has_field_bit_builder$\n"
" $name$_ = value.getNumber();\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -273,7 +268,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
"$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $clear_has_field_bit_builder$\n"
" $name$_ = $default_number$;\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -281,9 +276,9 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$ var $kt_name$: $kt_type$\n"
+ "$kt_deprecation$public var $kt_name$: $kt_type$\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -291,18 +286,31 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
" $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n"
" }\n");
+ if (SupportUnknownEnumValue(descriptor_->file())) {
+ printer->Print(
+ variables_,
+ "$kt_deprecation$public var $kt_name$Value: kotlin.Int\n"
+ " @JvmName(\"${$get$kt_capitalized_name$Value$}$\")\n"
+ " get() = $kt_dsl_builder$.${$get$capitalized_name$Value$}$()\n"
+ " @JvmName(\"${$set$kt_capitalized_name$Value$}$\")\n"
+ " set(value) {\n"
+ " $kt_dsl_builder$.${$set$capitalized_name$Value$}$(value)\n"
+ " }\n");
+ }
+
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
if (HasHazzer(descriptor_)) {
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
}
@@ -320,9 +328,7 @@ void ImmutableEnumFieldGenerator::GenerateInitializationCode(
void ImmutableEnumFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "$name$_ = $default_number$;\n"
- "$clear_has_field_bit_builder$\n");
+ printer->Print(variables_, "$name$_ = $default_number$;\n");
}
void ImmutableEnumFieldGenerator::GenerateMergingCode(
@@ -339,47 +345,41 @@ void ImmutableEnumFieldGenerator::GenerateMergingCode(
" set$capitalized_name$Value(other.get$capitalized_name$Value());\n"
"}\n");
} else {
- GOOGLE_LOG(FATAL) << "Can't reach here.";
+ Y_ABSL_LOG(FATAL) << "Can't reach here.";
}
}
void ImmutableEnumFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
- if (HasHazzer(descriptor_)) {
- printer->Print(variables_,
- "if ($get_has_field_bit_from_local$) {\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n");
+ printer->Print(variables_,
+ "if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$_;\n");
+ if (GetNumBitsForMessage() > 0) {
+ printer->Print(variables_, " $set_has_field_bit_to_local$;\n");
}
- printer->Print(variables_, "result.$name$_ = $name$_;\n");
+ printer->Print("}\n");
}
-void ImmutableEnumFieldGenerator::GenerateParsingCode(
+void ImmutableEnumFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
- "int rawValue = input.readEnum();\n"
- "$set_has_field_bit_message$\n"
- "$name$_ = rawValue;\n");
+ "$name$_ = input.readEnum();\n"
+ "$set_has_field_bit_builder$\n");
} else {
printer->Print(variables_,
- "int rawValue = input.readEnum();\n"
- " @SuppressWarnings(\"deprecation\")\n"
- "$type$ value = $type$.$for_number$(rawValue);\n"
- "if (value == null) {\n"
- " unknownFields.mergeVarintField($number$, rawValue);\n"
+ "int tmpRaw = input.readEnum();\n"
+ "$type$ tmpValue =\n"
+ " $type$.forNumber(tmpRaw);\n"
+ "if (tmpValue == null) {\n"
+ " mergeUnknownVarintField($number$, tmpRaw);\n"
"} else {\n"
- " $set_has_field_bit_message$\n"
- " $name$_ = rawValue;\n"
+ " $name$_ = tmpRaw;\n"
+ " $set_has_field_bit_builder$\n"
"}\n");
}
}
-void ImmutableEnumFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- // noop for enums
-}
-
void ImmutableEnumFieldGenerator::GenerateSerializationCode(
io::Printer* printer) const {
printer->Print(variables_,
@@ -429,7 +429,7 @@ ImmutableEnumOneofFieldGenerator::~ImmutableEnumOneofFieldGenerator() {}
void ImmutableEnumOneofFieldGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
@@ -453,8 +453,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers(
printer->Print(variables_,
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
- " @SuppressWarnings(\"deprecation\")\n"
- " $type$ result = $type$.$for_number$(\n"
+ " $type$ result = $type$.forNumber(\n"
" (java.lang.Integer) $oneof_name$_);\n"
" return result == null ? $unknown$ : result;\n"
" }\n"
@@ -465,7 +464,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers(
void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -493,7 +492,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
"${$set$capitalized_name$Value$}$(int value) {\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = value;\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -503,14 +502,14 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
- " @SuppressWarnings(\"deprecation\")\n"
- " $type$ result = $type$.$for_number$(\n"
+ " $type$ result = $type$.forNumber(\n"
" (java.lang.Integer) $oneof_name$_);\n"
" return result == null ? $unknown$ : result;\n"
" }\n"
" return $default$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldAccessorDocComment(printer, descriptor_, SETTER,
/* builder */ true);
printer->Print(variables_,
@@ -521,10 +520,11 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
" }\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = value.getNumber();\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
printer->Print(
@@ -533,19 +533,21 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
" if ($has_oneof_case_message$) {\n"
" $clear_oneof_case_message$;\n"
" $oneof_name$_ = null;\n"
- " $on_changed$\n"
+ " onChanged();\n"
" }\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
+void ImmutableEnumOneofFieldGenerator::GenerateBuilderClearCode(
+ io::Printer* printer) const {
+ // No-op: Enum fields in oneofs are correctly cleared by clearing the oneof
+}
+
void ImmutableEnumOneofFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "if ($has_oneof_case_message$) {\n"
- " result.$oneof_name$_ = $oneof_name$_;\n"
- "}\n");
+ // No-Op: Handled by single statement for the oneof
}
void ImmutableEnumOneofFieldGenerator::GenerateMergingCode(
@@ -560,7 +562,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMergingCode(
}
}
-void ImmutableEnumOneofFieldGenerator::GenerateParsingCode(
+void ImmutableEnumOneofFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
@@ -570,10 +572,10 @@ void ImmutableEnumOneofFieldGenerator::GenerateParsingCode(
} else {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
- "@SuppressWarnings(\"deprecation\")\n"
- "$type$ value = $type$.$for_number$(rawValue);\n"
+ "$type$ value =\n"
+ " $type$.forNumber(rawValue);\n"
"if (value == null) {\n"
- " unknownFields.mergeVarintField($number$, rawValue);\n"
+ " mergeUnknownVarintField($number$, rawValue);\n"
"} else {\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = rawValue;\n"
@@ -634,11 +636,8 @@ void ImmutableEnumOneofFieldGenerator::GenerateHashCode(
RepeatedImmutableEnumFieldGenerator::RepeatedImmutableEnumFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
- SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
- context->GetFieldGeneratorInfo(descriptor), name_resolver_,
- &variables_);
-}
+ : ImmutableEnumFieldGenerator(descriptor, messageBitIndex, builderBitIndex,
+ context) {}
RepeatedImmutableEnumFieldGenerator::~RepeatedImmutableEnumFieldGenerator() {}
@@ -678,6 +677,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
io::Printer* printer) const {
printer->Print(
variables_,
+ "@SuppressWarnings(\"serial\")\n"
"private java.util.List<java.lang.Integer> $name$_;\n"
"private static final "
"com.google.protobuf.Internal.ListAdapter.Converter<\n"
@@ -685,8 +685,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
" new com.google.protobuf.Internal.ListAdapter.Converter<\n"
" java.lang.Integer, $type$>() {\n"
" public $type$ convert(java.lang.Integer from) {\n"
- " @SuppressWarnings(\"deprecation\")\n"
- " $type$ result = $type$.$for_number$(from);\n"
+ " $type$ result = $type$.forNumber(from);\n"
" return result == null ? $unknown$ : result;\n"
" }\n"
" };\n");
@@ -802,7 +801,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" }\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.set(index, value.getNumber());\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -816,7 +815,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" }\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.add(value.getNumber());\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -829,7 +828,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" for ($type$ value : values) {\n"
" $name$_.add(value.getNumber());\n"
" }\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -840,7 +839,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
"$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $name$_ = java.util.Collections.emptyList();\n"
" $clear_mutable_bit_builder$;\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -870,7 +869,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" int index, int value) {\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.set(index, value);\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -881,7 +880,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
"${$add$capitalized_name$Value$}$(int value) {\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.add(value);\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -895,7 +894,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" for (int value : values) {\n"
" $name$_.add(value);\n"
" }\n"
- " $on_changed$\n"
+ " onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
@@ -935,7 +934,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMergingCode(
" ensure$capitalized_name$IsMutable();\n"
" $name$_.addAll(other.$name$_);\n"
" }\n"
- " $on_changed$\n"
+ " onChanged();\n"
"}\n");
}
@@ -952,36 +951,29 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuildingCode(
"result.$name$_ = $name$_;\n");
}
-void RepeatedImmutableEnumFieldGenerator::GenerateParsingCode(
+void RepeatedImmutableEnumFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
// Read and store the enum
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
- "int rawValue = input.readEnum();\n"
- "if (!$get_mutable_bit_parser$) {\n"
- " $name$_ = new java.util.ArrayList<java.lang.Integer>();\n"
- " $set_mutable_bit_parser$;\n"
- "}\n"
- "$name$_.add(rawValue);\n");
+ "int tmpRaw = input.readEnum();\n"
+ "ensure$capitalized_name$IsMutable();\n"
+ "$name$_.add(tmpRaw);\n");
} else {
- printer->Print(
- variables_,
- "int rawValue = input.readEnum();\n"
- "@SuppressWarnings(\"deprecation\")\n"
- "$type$ value = $type$.$for_number$(rawValue);\n"
- "if (value == null) {\n"
- " unknownFields.mergeVarintField($number$, rawValue);\n"
- "} else {\n"
- " if (!$get_mutable_bit_parser$) {\n"
- " $name$_ = new java.util.ArrayList<java.lang.Integer>();\n"
- " $set_mutable_bit_parser$;\n"
- " }\n"
- " $name$_.add(rawValue);\n"
- "}\n");
+ printer->Print(variables_,
+ "int tmpRaw = input.readEnum();\n"
+ "$type$ tmpValue =\n"
+ " $type$.forNumber(tmpRaw);\n"
+ "if (tmpValue == null) {\n"
+ " mergeUnknownVarintField($number$, tmpRaw);\n"
+ "} else {\n"
+ " ensure$capitalized_name$IsMutable();\n"
+ " $name$_.add(tmpRaw);\n"
+ "}\n");
}
}
-void RepeatedImmutableEnumFieldGenerator::GenerateParsingCodeFromPacked(
+void RepeatedImmutableEnumFieldGenerator::GenerateBuilderParsingCodeFromPacked(
io::Printer* printer) const {
// Wrap GenerateParsingCode's contents with a while loop.
@@ -991,23 +983,13 @@ void RepeatedImmutableEnumFieldGenerator::GenerateParsingCodeFromPacked(
"while(input.getBytesUntilLimit() > 0) {\n");
printer->Indent();
- GenerateParsingCode(printer);
+ GenerateBuilderParsingCode(printer);
printer->Outdent();
printer->Print(variables_,
"}\n"
"input.popLimit(oldLimit);\n");
}
-
-void RepeatedImmutableEnumFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- printer->Print(
- variables_,
- "if ($get_mutable_bit_parser$) {\n"
- " $name$_ = java.util.Collections.unmodifiableList($name$_);\n"
- "}\n");
-}
-
void RepeatedImmutableEnumFieldGenerator::GenerateSerializationCode(
io::Printer* printer) const {
if (descriptor_->is_packed()) {
@@ -1085,12 +1067,12 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -1099,70 +1081,70 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
" )\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -1178,4 +1160,4 @@ TProtoStringType RepeatedImmutableEnumFieldGenerator::GetBoxedType() const {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.h
index 6cf28fb126..60285493a3 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field.h
@@ -35,10 +35,10 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -61,10 +61,15 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
explicit ImmutableEnumFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
Context* context);
+ ImmutableEnumFieldGenerator(const ImmutableEnumFieldGenerator&) = delete;
+ ImmutableEnumFieldGenerator& operator=(const ImmutableEnumFieldGenerator&) =
+ delete;
~ImmutableEnumFieldGenerator() override;
// implements ImmutableFieldGenerator
// ---------------------------------------
+ int GetMessageBitIndex() const override;
+ int GetBuilderBitIndex() const override;
int GetNumBitsForMessage() const override;
int GetNumBitsForBuilder() const override;
void GenerateInterfaceMembers(io::Printer* printer) const override;
@@ -72,10 +77,9 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderMembers(io::Printer* printer) const override;
void GenerateInitializationCode(io::Printer* printer) const override;
void GenerateBuilderClearCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -88,11 +92,10 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ int message_bit_index_;
+ int builder_bit_index_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
ClassNameResolver* name_resolver_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldGenerator);
};
class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator {
@@ -100,27 +103,33 @@ class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator {
ImmutableEnumOneofFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
Context* context);
+ ImmutableEnumOneofFieldGenerator(const ImmutableEnumOneofFieldGenerator&) =
+ delete;
+ ImmutableEnumOneofFieldGenerator& operator=(
+ const ImmutableEnumOneofFieldGenerator&) = delete;
~ImmutableEnumOneofFieldGenerator() override;
void GenerateMembers(io::Printer* printer) const override;
void GenerateBuilderMembers(io::Printer* printer) const override;
+ void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateEqualsCode(io::Printer* printer) const override;
void GenerateHashCode(io::Printer* printer) const override;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldGenerator);
};
-class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
+class RepeatedImmutableEnumFieldGenerator : public ImmutableEnumFieldGenerator {
public:
explicit RepeatedImmutableEnumFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, Context* context);
+ RepeatedImmutableEnumFieldGenerator(
+ const RepeatedImmutableEnumFieldGenerator&) = delete;
+ RepeatedImmutableEnumFieldGenerator& operator=(
+ const RepeatedImmutableEnumFieldGenerator&) = delete;
~RepeatedImmutableEnumFieldGenerator() override;
// implements ImmutableFieldGenerator ---------------------------------------
@@ -133,9 +142,9 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingCodeFromPacked(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCodeFromPacked(
+ io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -145,13 +154,6 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
void GenerateKotlinDslMembers(io::Printer* printer) const override;
TProtoStringType GetBoxedType() const override;
-
- private:
- const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
- ClassNameResolver* name_resolver_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.cc
index c90939ada6..0aa273c990 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.cc
@@ -32,24 +32,24 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/enum_field_lite.h>
+#include "google/protobuf/compiler/java/enum_field_lite.h"
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "y_absl/container/flat_hash_map.h"
+#include "y_absl/log/absl_check.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/str_join.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/io/printer.h"
+#include "google/protobuf/wire_format.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -65,53 +65,62 @@ bool EnableExperimentalRuntimeForLite() {
#endif // !PROTOBUF_EXPERIMENT
}
-void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
- int builderBitIndex, const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetEnumVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
name_resolver->GetImmutableClassName(descriptor->enum_type());
- (*variables)["kt_type"] = (*variables)["type"];
+ variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])});
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->enum_type());
- (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
+ (*variables)["default"] =
+ ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
- StrCat(descriptor->default_value_enum()->number());
- (*variables)["tag"] = StrCat(
+ y_absl::StrCat(descriptor->default_value_enum()->number());
+ (*variables)["tag"] = y_absl::StrCat(
static_cast<arc_i32>(internal::WireFormat::MakeTag(descriptor)));
- (*variables)["tag_size"] = StrCat(
+ (*variables)["tag_size"] = y_absl::StrCat(
internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (HasHasbit(descriptor)) {
+ if (!context->options().opensource_runtime) {
+ (*variables)["bit_field_id"] = y_absl::StrCat(messageBitIndex / 32);
+ (*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex);
+ (*variables)["bit_field_mask"] =
+ y_absl::StrCat(1 << (messageBitIndex % 32));
+ }
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateSetBit(messageBitIndex), ";");
(*variables)["clear_has_field_bit_message"] =
- GenerateClearBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateClearBit(messageBitIndex), ";");
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
(*variables)["set_has_field_bit_message"] = "";
(*variables)["clear_has_field_bit_message"] = "";
- (*variables)["is_field_present_message"] =
- (*variables)["name"] + "_ != " + (*variables)["default"] +
- ".getNumber()";
+ variables->insert({"is_field_present_message",
+ y_absl::StrCat((*variables)["name"], "_ != ",
+ (*variables)["default"], ".getNumber()")});
}
(*variables)["get_has_field_bit_from_local"] =
@@ -120,14 +129,18 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
GenerateSetBitToLocal(messageBitIndex);
if (SupportUnknownEnumValue(descriptor->file())) {
- (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED";
+ variables->insert(
+ {"unknown", y_absl::StrCat((*variables)["type"], ".UNRECOGNIZED")});
} else {
- (*variables)["unknown"] = (*variables)["default"];
+ variables->insert({"unknown", (*variables)["default"]});
}
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
(*variables)["null_check"] = "value.getClass();\n";
+ // Calls to Annotate() use variable ranges to know which text to annotate.
+ (*variables)["{"] = "";
+ (*variables)["}"] = "";
}
} // namespace
@@ -142,7 +155,7 @@ ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator(
name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
- &variables_);
+ &variables_, context);
}
ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator() {}
@@ -156,19 +169,37 @@ void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
if (HasHazzer(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
- "$deprecation$boolean has$capitalized_name$();\n");
+ "$deprecation$boolean ${$has$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
- "$deprecation$int get$capitalized_name$Value();\n");
+ "$deprecation$int ${$get$capitalized_name$Value$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
- printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n");
+ printer->Print(variables_,
+ "$deprecation$$type$ ${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableEnumFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "@com.google.protobuf.ProtoField(\n"
+ " fieldNumber=$number$,\n"
+ " type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
+ " isRequired=$required$)\n");
+ if (HasHazzer(descriptor_)) {
+ printer->Print(variables_,
+ "@com.google.protobuf.ProtoPresenceCheckedField(\n"
+ " presenceBitsId=$bit_field_id$,\n"
+ " mask=$bit_field_mask$)\n");
+ }
+ }
printer->Print(variables_, "private int $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
@@ -286,9 +317,9 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers(
void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$var $kt_name$: $kt_type$\n"
+ "$kt_deprecation$public var $kt_name$: $kt_type$\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -296,18 +327,31 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers(
" $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n"
" }\n");
+ if (SupportUnknownEnumValue(descriptor_->file())) {
+ printer->Print(
+ variables_,
+ "$kt_deprecation$public var $kt_name$Value: kotlin.Int\n"
+ " @JvmName(\"${$get$kt_capitalized_name$Value$}$\")\n"
+ " get() = $kt_dsl_builder$.${$get$capitalized_name$Value$}$()\n"
+ " @JvmName(\"${$set$kt_capitalized_name$Value$}$\")\n"
+ " set(value) {\n"
+ " $kt_dsl_builder$.${$set$capitalized_name$Value$}$(value)\n"
+ " }\n");
+ }
+
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
if (HasHazzer(descriptor_)) {
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
}
@@ -356,7 +400,7 @@ ImmutableEnumOneofFieldLiteGenerator::~ImmutableEnumOneofFieldLiteGenerator() {}
void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -432,7 +476,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo(
void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -501,7 +545,7 @@ RepeatedImmutableEnumFieldLiteGenerator::
name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
- &variables_);
+ &variables_, context);
}
RepeatedImmutableEnumFieldLiteGenerator::
@@ -514,29 +558,43 @@ int RepeatedImmutableEnumFieldLiteGenerator::GetNumBitsForMessage() const {
void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
- printer->Print(
- variables_,
- "$deprecation$java.util.List<$type$> get$capitalized_name$List();\n");
+ printer->Print(variables_,
+ "$deprecation$java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT);
printer->Print(variables_,
- "$deprecation$int get$capitalized_name$Count();\n");
+ "$deprecation$int ${$get$capitalized_name$Count$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER);
- printer->Print(variables_,
- "$deprecation$$type$ get$capitalized_name$(int index);\n");
+ printer->Print(
+ variables_,
+ "$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"$deprecation$java.util.List<java.lang.Integer>\n"
- "get$capitalized_name$ValueList();\n");
+ "${$get$capitalized_name$ValueList$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldEnumValueAccessorDocComment(printer, descriptor_,
LIST_INDEXED_GETTER);
- printer->Print(variables_,
- "$deprecation$int get$capitalized_name$Value(int index);\n");
+ printer->Print(
+ variables_,
+ "$deprecation$int ${$get$capitalized_name$Value$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "@com.google.protobuf.ProtoField(\n"
+ " fieldNumber=$number$,\n"
+ " type=com.google.protobuf.FieldType.$annotation_field_type$)\n");
+ }
printer->Print(
variables_,
"private com.google.protobuf.Internal.IntList $name$_;\n"
@@ -793,6 +851,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder "
"${$add$capitalized_name$Value$}$(int value) {\n"
+ " copyOnWrite();\n"
" instance.add$capitalized_name$Value(value);\n"
" return this;\n"
"}\n");
@@ -827,12 +886,12 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$ public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -841,70 +900,70 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers(
" )\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -920,4 +979,4 @@ TProtoStringType RepeatedImmutableEnumFieldLiteGenerator::GetBoxedType() const {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.h
index df2f6fa10a..824affda1e 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_field_lite.h
@@ -36,10 +36,10 @@
#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -62,6 +62,10 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator {
explicit ImmutableEnumFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context);
+ ImmutableEnumFieldLiteGenerator(const ImmutableEnumFieldLiteGenerator&) =
+ delete;
+ ImmutableEnumFieldLiteGenerator& operator=(
+ const ImmutableEnumFieldLiteGenerator&) = delete;
~ImmutableEnumFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator
@@ -79,13 +83,10 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldLiteGenerator);
};
class ImmutableEnumOneofFieldLiteGenerator
@@ -93,15 +94,16 @@ class ImmutableEnumOneofFieldLiteGenerator
public:
ImmutableEnumOneofFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, Context* context);
+ ImmutableEnumOneofFieldLiteGenerator(
+ const ImmutableEnumOneofFieldLiteGenerator&) = delete;
+ ImmutableEnumOneofFieldLiteGenerator& operator=(
+ const ImmutableEnumOneofFieldLiteGenerator&) = delete;
~ImmutableEnumOneofFieldLiteGenerator() override;
void GenerateMembers(io::Printer* printer) const override;
void GenerateBuilderMembers(io::Printer* printer) const override;
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16_t>* output) const override;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldLiteGenerator);
};
class RepeatedImmutableEnumFieldLiteGenerator
@@ -109,6 +111,10 @@ class RepeatedImmutableEnumFieldLiteGenerator
public:
explicit RepeatedImmutableEnumFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context);
+ RepeatedImmutableEnumFieldLiteGenerator(
+ const RepeatedImmutableEnumFieldLiteGenerator&) = delete;
+ RepeatedImmutableEnumFieldLiteGenerator& operator=(
+ const RepeatedImmutableEnumFieldLiteGenerator&) = delete;
~RepeatedImmutableEnumFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator ------------------------------------
@@ -125,11 +131,9 @@ class RepeatedImmutableEnumFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
Context* context_;
ClassNameResolver* name_resolver_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldLiteGenerator);
};
} // namespace java
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"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.h
index 50f3fe7b1a..309d539b2e 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/enum_lite.h
@@ -37,7 +37,8 @@
#include <string>
#include <vector>
-#include <google/protobuf/descriptor.h>
+
+#include "google/protobuf/descriptor.h"
namespace google {
namespace protobuf {
@@ -62,6 +63,8 @@ class EnumLiteGenerator {
public:
EnumLiteGenerator(const EnumDescriptor* descriptor, bool immutable_api,
Context* context);
+ EnumLiteGenerator(const EnumLiteGenerator&) = delete;
+ EnumLiteGenerator& operator=(const EnumLiteGenerator&) = delete;
~EnumLiteGenerator();
void Generate(io::Printer* printer);
@@ -86,8 +89,6 @@ class EnumLiteGenerator {
Context* context_;
ClassNameResolver* name_resolver_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumLiteGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.cc
index 0983366c4f..dd9e6eab18 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.cc
@@ -32,17 +32,18 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/extension.h>
+#include "google/protobuf/compiler/java/extension.h"
-#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 "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/io/printer.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -51,7 +52,9 @@ namespace java {
ImmutableExtensionGenerator::ImmutableExtensionGenerator(
const FieldDescriptor* descriptor, Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());
@@ -66,19 +69,21 @@ ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {}
void ExtensionGenerator::InitTemplateVars(
const FieldDescriptor* descriptor, const TProtoStringType& scope, bool immutable,
ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* vars_pointer) {
- std::map<TProtoStringType, TProtoStringType>& vars = *vars_pointer;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* vars_pointer,
+ Context* context) {
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>& vars = *vars_pointer;
vars["scope"] = scope;
vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor);
vars["containing_type"] =
name_resolver->GetClassName(descriptor->containing_type(), immutable);
- vars["number"] = StrCat(descriptor->number());
+ vars["number"] = y_absl::StrCat(descriptor->number());
vars["constant_name"] = FieldConstantName(descriptor);
- vars["index"] = StrCat(descriptor->index());
+ vars["index"] = y_absl::StrCat(descriptor->index());
vars["default"] = descriptor->is_repeated()
? ""
- : DefaultValue(descriptor, immutable, name_resolver);
- vars["type_constant"] = FieldTypeName(GetType(descriptor));
+ : DefaultValue(descriptor, immutable, name_resolver,
+ context->options());
+ vars["type_constant"] = TProtoStringType(FieldTypeName(GetType(descriptor)));
vars["packed"] = descriptor->is_packed() ? "true" : "false";
vars["enum_map"] = "null";
vars["prototype"] = "null";
@@ -89,12 +94,12 @@ void ExtensionGenerator::InitTemplateVars(
case JAVATYPE_MESSAGE:
singular_type =
name_resolver->GetClassName(descriptor->message_type(), immutable);
- vars["prototype"] = singular_type + ".getDefaultInstance()";
+ vars["prototype"] = y_absl::StrCat(singular_type, ".getDefaultInstance()");
break;
case JAVATYPE_ENUM:
singular_type =
name_resolver->GetClassName(descriptor->enum_type(), immutable);
- vars["enum_map"] = singular_type + ".internalGetValueMap()";
+ vars["enum_map"] = y_absl::StrCat(singular_type, ".internalGetValueMap()");
break;
case JAVATYPE_STRING:
singular_type = "java.lang.String";
@@ -103,20 +108,20 @@ void ExtensionGenerator::InitTemplateVars(
singular_type = immutable ? "com.google.protobuf.ByteString" : "byte[]";
break;
default:
- singular_type = BoxedPrimitiveTypeName(java_type);
+ singular_type = TProtoStringType(BoxedPrimitiveTypeName(java_type));
break;
}
vars["type"] = descriptor->is_repeated()
- ? "java.util.List<" + singular_type + ">"
+ ? y_absl::StrCat("java.util.List<", singular_type, ">")
: singular_type;
vars["singular_type"] = singular_type;
}
void ImmutableExtensionGenerator::Generate(io::Printer* printer) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
- &vars);
+ &vars, context_);
printer->Print(vars, "public static final int $constant_name$ = $number$;\n");
WriteFieldDocComment(printer, descriptor_);
@@ -156,7 +161,7 @@ int ImmutableExtensionGenerator::GenerateNonNestedInitializationCode(
printer->Print(
"$name$.internalInit(descriptor.getExtensions().get($index$));\n",
"name", UnderscoresToCamelCaseCheckReserved(descriptor_), "index",
- StrCat(descriptor_->index()));
+ y_absl::StrCat(descriptor_->index()));
bytecode_estimate += 21;
}
return bytecode_estimate;
@@ -174,4 +179,4 @@ int ImmutableExtensionGenerator::GenerateRegistrationCode(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.h
index f9bd326f9b..752a2de870 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension.h
@@ -35,10 +35,10 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__
-#include <map>
#include <string>
-#include <google/protobuf/stubs/common.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@@ -66,6 +66,8 @@ namespace java {
class ExtensionGenerator {
public:
explicit ExtensionGenerator() {}
+ ExtensionGenerator(const ExtensionGenerator&) = delete;
+ ExtensionGenerator& operator=(const ExtensionGenerator&) = delete;
virtual ~ExtensionGenerator() {}
virtual void Generate(io::Printer* printer) = 0;
@@ -82,16 +84,17 @@ class ExtensionGenerator {
static void InitTemplateVars(
const FieldDescriptor* descriptor, const TProtoStringType& scope,
bool immutable, ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* vars_pointer);
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* vars_pointer,
+ Context* context);
};
class ImmutableExtensionGenerator : public ExtensionGenerator {
public:
explicit ImmutableExtensionGenerator(const FieldDescriptor* descriptor,
Context* context);
+ ImmutableExtensionGenerator(const ImmutableExtensionGenerator&) = delete;
+ ImmutableExtensionGenerator& operator=(const ImmutableExtensionGenerator&) =
+ delete;
~ImmutableExtensionGenerator() override;
void Generate(io::Printer* printer) override;
@@ -102,9 +105,7 @@ class ImmutableExtensionGenerator : public ExtensionGenerator {
const FieldDescriptor* descriptor_;
ClassNameResolver* name_resolver_;
TProtoStringType scope_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionGenerator);
+ Context* context_;
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.cc
index d51d9d2ba8..99345242a1 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.cc
@@ -28,17 +28,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <google/protobuf/compiler/java/extension_lite.h>
+#include "google/protobuf/compiler/java/extension_lite.h"
-#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 <string>
+
+#include "y_absl/container/flat_hash_map.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/io/printer.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -47,7 +49,9 @@ namespace java {
ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator(
const FieldDescriptor* descriptor, Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());
@@ -59,10 +63,10 @@ ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator(
ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {}
void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
- &vars);
+ &vars, context_);
printer->Print(vars, "public static final int $constant_name$ = $number$;\n");
WriteFieldDocComment(printer, descriptor_);
@@ -117,4 +121,4 @@ int ImmutableExtensionLiteGenerator::GenerateRegistrationCode(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.h
index 0d013c862c..0c74bc5095 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/extension_lite.h
@@ -31,11 +31,10 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_LITE_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_LITE_H__
-#include <map>
#include <string>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/compiler/java/extension.h>
+#include "google/protobuf/compiler/java/extension.h"
+#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@@ -49,6 +48,10 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator {
public:
explicit ImmutableExtensionLiteGenerator(const FieldDescriptor* descriptor,
Context* context);
+ ImmutableExtensionLiteGenerator(const ImmutableExtensionLiteGenerator&) =
+ delete;
+ ImmutableExtensionLiteGenerator& operator=(
+ const ImmutableExtensionLiteGenerator&) = delete;
~ImmutableExtensionLiteGenerator() override;
void Generate(io::Printer* printer) override;
@@ -63,8 +66,7 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator {
const FieldDescriptor* descriptor_;
ClassNameResolver* name_resolver_;
TProtoStringType scope_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionLiteGenerator);
+ Context* context_;
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/field.cc
index 84487ac7a1..4701dc6322 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/field.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/field.cc
@@ -32,27 +32,28 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
#include <memory>
+#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/stubs/substitute.h>
-#include <google/protobuf/compiler/java/context.h>
-#include <google/protobuf/compiler/java/enum_field.h>
-#include <google/protobuf/compiler/java/enum_field_lite.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/map_field.h>
-#include <google/protobuf/compiler/java/map_field_lite.h>
-#include <google/protobuf/compiler/java/message_field.h>
-#include <google/protobuf/compiler/java/message_field_lite.h>
-#include <google/protobuf/compiler/java/primitive_field.h>
-#include <google/protobuf/compiler/java/primitive_field_lite.h>
-#include <google/protobuf/compiler/java/string_field.h>
-#include <google/protobuf/compiler/java/string_field_lite.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "y_absl/log/absl_log.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/substitute.h"
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/enum_field.h"
+#include "google/protobuf/compiler/java/enum_field_lite.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/map_field.h"
+#include "google/protobuf/compiler/java/map_field_lite.h"
+#include "google/protobuf/compiler/java/message_field.h"
+#include "google/protobuf/compiler/java/message_field_lite.h"
+#include "google/protobuf/compiler/java/primitive_field.h"
+#include "google/protobuf/compiler/java/primitive_field_lite.h"
+#include "google/protobuf/compiler/java/string_field.h"
+#include "google/protobuf/compiler/java/string_field_lite.h"
+#include "google/protobuf/io/printer.h"
namespace google {
@@ -185,15 +186,15 @@ static inline void ReportUnexpectedPackedFieldsCall(io::Printer* printer) {
// but this method should be overridden.
// - This FieldGenerator doesn't support packing, and this method
// should never have been called.
- GOOGLE_LOG(FATAL) << "GenerateParsingCodeFromPacked() "
- << "called on field generator that does not support packing.";
+ Y_ABSL_LOG(FATAL) << "GenerateBuilderParsingCodeFromPacked() "
+ << "called on field generator that does not support packing.";
}
} // namespace
ImmutableFieldGenerator::~ImmutableFieldGenerator() {}
-void ImmutableFieldGenerator::GenerateParsingCodeFromPacked(
+void ImmutableFieldGenerator::GenerateBuilderParsingCodeFromPacked(
io::Printer* printer) const {
ReportUnexpectedPackedFieldsCall(printer);
}
@@ -241,16 +242,16 @@ template <>
FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap() {}
-void SetCommonFieldVariables(const FieldDescriptor* descriptor,
- const FieldGeneratorInfo* info,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetCommonFieldVariables(
+ const FieldDescriptor* descriptor, const FieldGeneratorInfo* info,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables) {
(*variables)["field_name"] = descriptor->name();
(*variables)["name"] = info->name;
(*variables)["classname"] = descriptor->containing_type()->name();
(*variables)["capitalized_name"] = info->capitalized_name;
(*variables)["disambiguated_reason"] = info->disambiguated_reason;
(*variables)["constant_name"] = FieldConstantName(descriptor);
- (*variables)["number"] = StrCat(descriptor->number());
+ (*variables)["number"] = y_absl::StrCat(descriptor->number());
(*variables)["kt_dsl_builder"] = "_builder";
// These variables are placeholders to pick out the beginning and ends of
// identifiers for annotations (when doing so with existing variables would
@@ -258,46 +259,50 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
// empty string.
(*variables)["{"] = "";
(*variables)["}"] = "";
- (*variables)["kt_name"] =
- IsForbiddenKotlin(info->name) ? info->name + "_" : info->name;
- (*variables)["kt_capitalized_name"] = IsForbiddenKotlin(info->name)
- ? info->capitalized_name + "_"
- : info->capitalized_name;
+ (*variables)["kt_name"] = IsForbiddenKotlin(info->name)
+ ? y_absl::StrCat(info->name, "_")
+ : info->name;
+ (*variables)["kt_capitalized_name"] =
+ IsForbiddenKotlin(info->name) ? y_absl::StrCat(info->capitalized_name, "_")
+ : info->capitalized_name;
if (!descriptor->is_repeated()) {
- (*variables)["annotation_field_type"] = FieldTypeName(descriptor->type());
+ (*variables)["annotation_field_type"] =
+ TProtoStringType(FieldTypeName(descriptor->type()));
} else if (GetJavaType(descriptor) == JAVATYPE_MESSAGE &&
IsMapEntry(descriptor->message_type())) {
(*variables)["annotation_field_type"] =
- TProtoStringType(FieldTypeName(descriptor->type())) + "MAP";
+ y_absl::StrCat(FieldTypeName(descriptor->type()), "MAP");
} else {
(*variables)["annotation_field_type"] =
- TProtoStringType(FieldTypeName(descriptor->type())) + "_LIST";
+ y_absl::StrCat(FieldTypeName(descriptor->type()), "_LIST");
if (descriptor->is_packed()) {
- (*variables)["annotation_field_type"] =
- (*variables)["annotation_field_type"] + "_PACKED";
+ variables->insert(
+ {"annotation_field_type",
+ y_absl::StrCat(FieldTypeName(descriptor->type()), "_LIST_PACKED")});
}
}
}
-void SetCommonOneofVariables(const FieldDescriptor* descriptor,
- const OneofGeneratorInfo* info,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetCommonOneofVariables(
+ const FieldDescriptor* descriptor, const OneofGeneratorInfo* info,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables) {
(*variables)["oneof_name"] = info->name;
(*variables)["oneof_capitalized_name"] = info->capitalized_name;
(*variables)["oneof_index"] =
- StrCat(descriptor->containing_oneof()->index());
+ y_absl::StrCat(descriptor->containing_oneof()->index());
(*variables)["oneof_stored_type"] = GetOneofStoredType(descriptor);
(*variables)["set_oneof_case_message"] =
- info->name + "Case_ = " + StrCat(descriptor->number());
- (*variables)["clear_oneof_case_message"] = info->name + "Case_ = 0";
+ y_absl::StrCat(info->name, "Case_ = ", descriptor->number());
+ (*variables)["clear_oneof_case_message"] =
+ y_absl::StrCat(info->name, "Case_ = 0");
(*variables)["has_oneof_case_message"] =
- info->name + "Case_ == " + StrCat(descriptor->number());
+ y_absl::StrCat(info->name, "Case_ == ", descriptor->number());
}
-void PrintExtraFieldInfo(const std::map<TProtoStringType, TProtoStringType>& variables,
- io::Printer* printer) {
- const std::map<TProtoStringType, TProtoStringType>::const_iterator it =
- variables.find("disambiguated_reason");
+void PrintExtraFieldInfo(
+ const y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>& variables,
+ io::Printer* printer) {
+ auto it = variables.find("disambiguated_reason");
if (it != variables.end() && !it->second.empty()) {
printer->Print(
variables,
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/field.h
index 481fbdb456..1229ce3a8a 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/field.h
@@ -36,13 +36,13 @@
#define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__
#include <cstdint>
-#include <map>
#include <memory>
#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/descriptor.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "y_absl/log/absl_check.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@@ -66,8 +66,12 @@ namespace java {
class ImmutableFieldGenerator {
public:
ImmutableFieldGenerator() {}
+ ImmutableFieldGenerator(const ImmutableFieldGenerator&) = delete;
+ ImmutableFieldGenerator& operator=(const ImmutableFieldGenerator&) = delete;
virtual ~ImmutableFieldGenerator();
+ virtual int GetMessageBitIndex() const = 0;
+ virtual int GetBuilderBitIndex() const = 0;
virtual int GetNumBitsForMessage() const = 0;
virtual int GetNumBitsForBuilder() const = 0;
virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
@@ -77,9 +81,8 @@ class ImmutableFieldGenerator {
virtual void GenerateBuilderClearCode(io::Printer* printer) const = 0;
virtual void GenerateMergingCode(io::Printer* printer) const = 0;
virtual void GenerateBuildingCode(io::Printer* printer) const = 0;
- virtual void GenerateParsingCode(io::Printer* printer) const = 0;
- virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const;
- virtual void GenerateParsingDoneCode(io::Printer* printer) const = 0;
+ virtual void GenerateBuilderParsingCode(io::Printer* printer) const = 0;
+ virtual void GenerateBuilderParsingCodeFromPacked(io::Printer* printer) const;
virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
virtual void GenerateFieldBuilderInitializationCode(
@@ -90,14 +93,14 @@ class ImmutableFieldGenerator {
virtual void GenerateHashCode(io::Printer* printer) const = 0;
virtual TProtoStringType GetBoxedType() const = 0;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator);
};
class ImmutableFieldLiteGenerator {
public:
ImmutableFieldLiteGenerator() {}
+ ImmutableFieldLiteGenerator(const ImmutableFieldLiteGenerator&) = delete;
+ ImmutableFieldLiteGenerator& operator=(const ImmutableFieldLiteGenerator&) =
+ delete;
virtual ~ImmutableFieldLiteGenerator();
virtual int GetNumBitsForMessage() const = 0;
@@ -110,9 +113,6 @@ class ImmutableFieldLiteGenerator {
virtual void GenerateKotlinDslMembers(io::Printer* printer) const = 0;
virtual TProtoStringType GetBoxedType() const = 0;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldLiteGenerator);
};
@@ -121,6 +121,8 @@ template <typename FieldGeneratorType>
class FieldGeneratorMap {
public:
explicit FieldGeneratorMap(const Descriptor* descriptor, Context* context);
+ FieldGeneratorMap(const FieldGeneratorMap&) = delete;
+ FieldGeneratorMap& operator=(const FieldGeneratorMap&) = delete;
~FieldGeneratorMap();
const FieldGeneratorType& get(const FieldDescriptor* field) const;
@@ -128,14 +130,12 @@ class FieldGeneratorMap {
private:
const Descriptor* descriptor_;
std::vector<std::unique_ptr<FieldGeneratorType>> field_generators_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
};
template <typename FieldGeneratorType>
inline const FieldGeneratorType& FieldGeneratorMap<FieldGeneratorType>::get(
const FieldDescriptor* field) const {
- GOOGLE_CHECK_EQ(field->containing_type(), descriptor_);
+ Y_ABSL_CHECK_EQ(field->containing_type(), descriptor_);
return *field_generators_[field->index()];
}
@@ -170,18 +170,19 @@ struct OneofGeneratorInfo {
};
// Set some common variables used in variable FieldGenerators.
-void SetCommonFieldVariables(const FieldDescriptor* descriptor,
- const FieldGeneratorInfo* info,
- std::map<TProtoStringType, TProtoStringType>* variables);
+void SetCommonFieldVariables(
+ const FieldDescriptor* descriptor, const FieldGeneratorInfo* info,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables);
// Set some common oneof variables used in OneofFieldGenerators.
-void SetCommonOneofVariables(const FieldDescriptor* descriptor,
- const OneofGeneratorInfo* info,
- std::map<TProtoStringType, TProtoStringType>* variables);
+void SetCommonOneofVariables(
+ const FieldDescriptor* descriptor, const OneofGeneratorInfo* info,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables);
// Print useful comments before a field's accessors.
-void PrintExtraFieldInfo(const std::map<TProtoStringType, TProtoStringType>& variables,
- io::Printer* printer);
+void PrintExtraFieldInfo(
+ const y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>& variables,
+ io::Printer* printer);
} // namespace java
} // namespace compiler
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/file.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/file.cc
index 401599765b..da961fc088 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/file.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/file.cc
@@ -32,30 +32,32 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/file.h>
+#include "google/protobuf/compiler/java/file.h"
#include <memory>
-#include <set>
-
-#include <google/protobuf/compiler/code_generator.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/io/zero_copy_stream.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/compiler/java/context.h>
-#include <google/protobuf/compiler/java/enum.h>
-#include <google/protobuf/compiler/java/enum_lite.h>
-#include <google/protobuf/compiler/java/extension.h>
-#include <google/protobuf/compiler/java/generator_factory.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/message.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/compiler/java/service.h>
-#include <google/protobuf/compiler/java/shared_code_generator.h>
-#include <google/protobuf/descriptor.pb.h>
+#include <vector>
+
+#include "y_absl/container/btree_set.h"
+#include "y_absl/log/absl_log.h"
+#include "y_absl/strings/str_cat.h"
+#include "google/protobuf/compiler/code_generator.h"
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/enum.h"
+#include "google/protobuf/compiler/java/enum_lite.h"
+#include "google/protobuf/compiler/java/extension.h"
+#include "google/protobuf/compiler/java/generator_factory.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/message.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/compiler/java/service.h"
+#include "google/protobuf/compiler/java/shared_code_generator.h"
+#include "google/protobuf/descriptor.pb.h"
+#include "google/protobuf/dynamic_message.h"
+#include "google/protobuf/io/printer.h"
+#include "google/protobuf/io/zero_copy_stream.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -76,8 +78,8 @@ struct FieldDescriptorCompare {
}
};
-typedef std::set<const FieldDescriptor*, FieldDescriptorCompare>
- FieldDescriptorSet;
+using FieldDescriptorSet =
+ y_absl::btree_set<const FieldDescriptor*, FieldDescriptorCompare>;
// Recursively searches the given message to collect extensions.
// Returns true if all the extensions can be recognized. The extensions will be
@@ -131,7 +133,7 @@ void CollectExtensions(const FileDescriptorProto& file_proto,
// builder-pool to find out all extensions.
const Descriptor* file_proto_desc = alternate_pool.FindMessageTypeByName(
file_proto.GetDescriptor()->full_name());
- GOOGLE_CHECK(file_proto_desc)
+ Y_ABSL_CHECK(file_proto_desc)
<< "Find unknown fields in FileDescriptorProto when building "
<< file_proto.name()
<< ". It's likely that those fields are custom options, however, "
@@ -140,14 +142,14 @@ void CollectExtensions(const FileDescriptorProto& file_proto,
DynamicMessageFactory factory;
std::unique_ptr<Message> dynamic_file_proto(
factory.GetPrototype(file_proto_desc)->New());
- GOOGLE_CHECK(dynamic_file_proto.get() != NULL);
- GOOGLE_CHECK(dynamic_file_proto->ParseFromString(file_data));
+ Y_ABSL_CHECK(dynamic_file_proto.get() != NULL);
+ Y_ABSL_CHECK(dynamic_file_proto->ParseFromString(file_data));
// Collect the extensions again from the dynamic message. There should be no
// more unknown fields this time, i.e. all the custom options should be
// parsed as extensions now.
extensions->clear();
- GOOGLE_CHECK(CollectExtensions(*dynamic_file_proto, extensions))
+ Y_ABSL_CHECK(CollectExtensions(*dynamic_file_proto, extensions))
<< "Find unknown fields in FileDescriptorProto when building "
<< file_proto.name()
<< ". It's likely that those fields are custom options, however, "
@@ -175,10 +177,10 @@ void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate,
if ((*bytecode_estimate) > bytesPerMethod) {
++(*method_num);
- printer->Print(chain_statement, "method_num", StrCat(*method_num));
+ printer->Print(chain_statement, "method_num", y_absl::StrCat(*method_num));
printer->Outdent();
printer->Print("}\n");
- printer->Print(method_decl, "method_num", StrCat(*method_num));
+ printer->Print(method_decl, "method_num", y_absl::StrCat(*method_num));
printer->Indent();
*bytecode_estimate = 0;
}
@@ -188,7 +190,7 @@ void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate,
FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options,
bool immutable_api)
: file_(file),
- java_package_(FileJavaPackage(file, immutable_api)),
+ java_package_(FileJavaPackage(file, immutable_api, options)),
message_generators_(file->message_type_count()),
extension_generators_(file->extension_count()),
context_(new Context(file, options)),
@@ -196,7 +198,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options,
options_(options),
immutable_api_(immutable_api) {
classname_ = name_resolver_->GetFileClassName(file, immutable_api);
- generator_factory_.reset(new ImmutableGeneratorFactory(context_.get()));
+ generator_factory_.reset(new ImmutableGeneratorFactory(context_.get()));
for (int i = 0; i < file_->message_type_count(); ++i) {
message_generators_[i].reset(
generator_factory_->NewMessageGenerator(file_->message_type(i)));
@@ -232,7 +234,7 @@ bool FileGenerator::Validate(TProtoStringType* error) {
// because filenames are case-insensitive on those platforms.
if (name_resolver_->HasConflictingClassName(
file_, classname_, NameEquality::EQUAL_IGNORE_CASE)) {
- GOOGLE_LOG(WARNING)
+ Y_ABSL_LOG(WARNING)
<< file_->name() << ": The file's outer class name, \"" << classname_
<< "\", matches the name of one of the types declared inside it when "
<< "case is ignored. This can cause compilation issues on Windows / "
@@ -244,7 +246,7 @@ bool FileGenerator::Validate(TProtoStringType* error) {
// Print a warning if optimize_for = LITE_RUNTIME is used.
if (file_->options().optimize_for() == FileOptions::LITE_RUNTIME &&
!options_.enforce_lite) {
- GOOGLE_LOG(WARNING)
+ Y_ABSL_LOG(WARNING)
<< "The optimize_for = LITE_RUNTIME option is no longer supported by "
<< "protobuf Java code generator and is ignored--protoc will always "
<< "generate full runtime code for Java. To use Java Lite runtime, "
@@ -271,8 +273,13 @@ void FileGenerator::Generate(io::Printer* printer) {
"package", java_package_);
}
PrintGeneratedAnnotation(
- printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : "");
+ printer, '$',
+ options_.annotate_code ? y_absl::StrCat(classname_, ".java.pb.meta") : "",
+ options_);
+ if (!options_.opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
+ }
printer->Print(
"$deprecation$public final class $classname$ {\n"
" private $ctor$() {}\n",
@@ -401,11 +408,14 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable(
" descriptor;\n"
"static {\n",
// TODO(dweis): Mark this as final.
- "final", "");
+ "final", options_.opensource_runtime ? "" : "final");
printer->Indent();
- SharedCodeGenerator shared_code_generator(file_, options_);
- shared_code_generator.GenerateDescriptors(printer);
+ if (options_.opensource_runtime) {
+ SharedCodeGenerator shared_code_generator(file_, options_);
+ shared_code_generator.GenerateDescriptors(printer);
+ } else {
+ }
int bytecode_estimate = 0;
int method_num = 0;
@@ -449,16 +459,16 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable(
FieldDescriptorSet extensions;
CollectExtensions(file_proto, *file_->pool(), &extensions, file_data);
- if (extensions.size() > 0) {
+ if (!extensions.empty()) {
// Must construct an ExtensionRegistry containing all existing extensions
// and use it to parse the descriptor data again to recognize extensions.
printer->Print(
"com.google.protobuf.ExtensionRegistry registry =\n"
" com.google.protobuf.ExtensionRegistry.newInstance();\n");
FieldDescriptorSet::iterator it;
- for (it = extensions.begin(); it != extensions.end(); it++) {
+ for (const FieldDescriptor* field : extensions) {
std::unique_ptr<ExtensionGenerator> generator(
- generator_factory_->NewExtensionGenerator(*it));
+ generator_factory_->NewExtensionGenerator(field));
bytecode_estimate += generator->GenerateRegistrationCode(printer);
MaybeRestartJavaMethod(
printer, &bytecode_estimate, &method_num,
@@ -499,8 +509,8 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
printer->Print(
"descriptor = $immutable_package$.$descriptor_classname$.descriptor;\n",
- "immutable_package", FileJavaPackage(file_, true), "descriptor_classname",
- name_resolver_->GetDescriptorClassName(file_));
+ "immutable_package", FileJavaPackage(file_, true, options_),
+ "descriptor_classname", name_resolver_->GetDescriptorClassName(file_));
for (int i = 0; i < file_->message_type_count(); i++) {
message_generators_[i]->GenerateStaticVariableInitializers(printer);
@@ -518,7 +528,7 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
FieldDescriptorSet extensions;
CollectExtensions(file_proto, *file_->pool(), &extensions, file_data);
- if (extensions.size() > 0) {
+ if (!extensions.empty()) {
// Try to load immutable messages' outer class. Its initialization code
// will take care of interpreting custom options.
printer->Print(
@@ -539,17 +549,18 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
"com.google.protobuf.ExtensionRegistry registry =\n"
" com.google.protobuf.ExtensionRegistry.newInstance();\n"
"com.google.protobuf.MessageLite defaultExtensionInstance = null;\n");
- FieldDescriptorSet::iterator it;
- for (it = extensions.begin(); it != extensions.end(); it++) {
- const FieldDescriptor* field = *it;
+
+ for (const FieldDescriptor* field : extensions) {
TProtoStringType scope;
if (field->extension_scope() != NULL) {
- scope = name_resolver_->GetMutableClassName(field->extension_scope()) +
- ".getDescriptor()";
+ scope = y_absl::StrCat(
+ name_resolver_->GetMutableClassName(field->extension_scope()),
+ ".getDescriptor()");
} else {
- scope = FileJavaPackage(field->file(), true) + "." +
- name_resolver_->GetDescriptorClassName(field->file()) +
- ".descriptor";
+ scope =
+ y_absl::StrCat(FileJavaPackage(field->file(), true, options_), ".",
+ name_resolver_->GetDescriptorClassName(field->file()),
+ ".descriptor");
}
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
printer->Print(
@@ -560,11 +571,11 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
" $scope$.getExtensions().get($index$),\n"
" (com.google.protobuf.Message) defaultExtensionInstance);\n"
"}\n",
- "scope", scope, "index", StrCat(field->index()), "class",
+ "scope", scope, "index", y_absl::StrCat(field->index()), "class",
name_resolver_->GetImmutableClassName(field->message_type()));
} else {
printer->Print("registry.add($scope$.getExtensions().get($index$));\n",
- "scope", scope, "index", StrCat(field->index()));
+ "scope", scope, "index", y_absl::StrCat(field->index()));
}
}
printer->Print(
@@ -598,9 +609,9 @@ static void GenerateSibling(
GeneratorClass* generator,
void (GeneratorClass::*pfn)(io::Printer* printer)) {
TProtoStringType filename =
- package_dir + descriptor->name() + name_suffix + ".java";
+ y_absl::StrCat(package_dir, descriptor->name(), name_suffix, ".java");
file_list->push_back(filename);
- TProtoStringType info_full_path = filename + ".pb.meta";
+ TProtoStringType info_full_path = y_absl::StrCat(filename, ".pb.meta");
GeneratedCodeInfo annotations;
io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector(
&annotations);
@@ -682,6 +693,23 @@ TProtoStringType FileGenerator::GetKotlinClassname() {
return name_resolver_->GetFileClassName(file_, immutable_api_, true);
}
+void FileGenerator::GenerateKotlin(io::Printer* printer) {
+ printer->Print(
+ "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
+ "// source: $filename$\n"
+ "\n",
+ "filename", file_->name());
+ printer->Print(
+ "// Generated files should ignore deprecation warnings\n"
+ "@file:Suppress(\"DEPRECATION\")\n");
+ if (!java_package_.empty()) {
+ printer->Print(
+ "package $package$;\n"
+ "\n",
+ "package", EscapeKotlinKeywords(java_package_));
+ }
+}
+
void FileGenerator::GenerateKotlinSiblings(
const TProtoStringType& package_dir, GeneratorContext* context,
std::vector<TProtoStringType>* file_list,
@@ -692,9 +720,10 @@ void FileGenerator::GenerateKotlinSiblings(
auto open_file = [context](const TProtoStringType& filename) {
return std::unique_ptr<io::ZeroCopyOutputStream>(context->Open(filename));
};
- TProtoStringType filename = package_dir + descriptor->name() + "Kt.kt";
+ TProtoStringType filename =
+ y_absl::StrCat(package_dir, descriptor->name(), "Kt.kt");
file_list->push_back(filename);
- TProtoStringType info_full_path = filename + ".pb.meta";
+ TProtoStringType info_full_path = y_absl::StrCat(filename, ".pb.meta");
GeneratedCodeInfo annotations;
io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector(
&annotations);
@@ -704,15 +733,18 @@ void FileGenerator::GenerateKotlinSiblings(
options_.annotate_code ? &annotation_collector : nullptr);
printer.Print(
- "//Generated by the protocol buffer compiler. DO NOT EDIT!\n"
+ "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n"
"\n",
"filename", descriptor->file()->name());
+ printer.Print(
+ "// Generated files should ignore deprecation warnings\n"
+ "@file:Suppress(\"DEPRECATION\")\n");
if (!java_package_.empty()) {
printer.Print(
"package $package$;\n"
"\n",
- "package", java_package_);
+ "package", EscapeKotlinKeywords(java_package_));
}
generator->GenerateKotlinMembers(&printer);
@@ -736,4 +768,4 @@ bool FileGenerator::ShouldIncludeDependency(const FileDescriptor* descriptor,
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/file.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/file.h
index 0063a18816..c8934c4bfe 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/file.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/file.h
@@ -39,8 +39,8 @@
#include <string>
#include <vector>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/compiler/java/options.h>
+#include "google/protobuf/compiler/java/options.h"
+#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@@ -70,6 +70,8 @@ class FileGenerator {
public:
FileGenerator(const FileDescriptor* file, const Options& options,
bool immutable_api = true);
+ FileGenerator(const FileGenerator&) = delete;
+ FileGenerator& operator=(const FileGenerator&) = delete;
~FileGenerator();
// Checks for problems that would otherwise lead to cryptic compile errors.
@@ -80,6 +82,7 @@ class FileGenerator {
void Generate(io::Printer* printer);
TProtoStringType GetKotlinClassname();
+ void GenerateKotlin(io::Printer* printer);
void GenerateKotlinSiblings(const TProtoStringType& package_dir,
GeneratorContext* generator_context,
std::vector<TProtoStringType>* file_list,
@@ -114,8 +117,6 @@ class FileGenerator {
ClassNameResolver* name_resolver_;
const Options options_;
bool immutable_api_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.cc
index 03be2a417e..cac13d8cbc 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.cc
@@ -32,23 +32,22 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/generator.h>
+#include "google/protobuf/compiler/java/generator.h"
+
+#include <utility>
+#include <vector>
#include <memory>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/io/zero_copy_stream.h>
-#include <google/protobuf/stubs/stringprintf.h>
-#include <google/protobuf/compiler/java/file.h>
-#include <google/protobuf/compiler/java/generator_factory.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/compiler/java/options.h>
-#include <google/protobuf/compiler/java/shared_code_generator.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/strings/str_format.h"
+#include "google/protobuf/compiler/java/file.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/compiler/java/options.h"
+#include "google/protobuf/compiler/java/shared_code_generator.h"
+#include "google/protobuf/descriptor.pb.h"
-#include <google/protobuf/stubs/strutil.h>
namespace google {
namespace protobuf {
@@ -74,25 +73,27 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
ParseGeneratorParameter(parameter, &options);
Options file_options;
- for (int i = 0; i < options.size(); i++) {
- if (options[i].first == "output_list_file") {
- file_options.output_list_file = options[i].second;
- } else if (options[i].first == "immutable") {
+ file_options.opensource_runtime = opensource_runtime_;
+
+ for (auto& option : options) {
+ if (option.first == "output_list_file") {
+ file_options.output_list_file = option.second;
+ } else if (option.first == "immutable") {
file_options.generate_immutable_code = true;
- } else if (options[i].first == "mutable") {
+ } else if (option.first == "mutable") {
file_options.generate_mutable_code = true;
- } else if (options[i].first == "shared") {
+ } else if (option.first == "shared") {
file_options.generate_shared_code = true;
- } else if (options[i].first == "lite") {
+ } else if (option.first == "lite") {
// Note: Java Lite does not guarantee API/ABI stability. We may choose to
// break existing API in order to boost performance / reduce code size.
file_options.enforce_lite = true;
- } else if (options[i].first == "annotate_code") {
+ } else if (option.first == "annotate_code") {
file_options.annotate_code = true;
- } else if (options[i].first == "annotation_list_file") {
- file_options.annotation_list_file = options[i].second;
+ } else if (option.first == "annotation_list_file") {
+ file_options.annotation_list_file = option.second;
} else {
- *error = "Unknown generator option: " + options[i].first;
+ *error = y_absl::StrCat("Unknown generator option: ", option.first);
return false;
}
}
@@ -117,35 +118,31 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
std::vector<TProtoStringType> all_annotations;
- std::vector<FileGenerator*> file_generators;
+ std::vector<std::unique_ptr<FileGenerator>> file_generators;
if (file_options.generate_immutable_code) {
- file_generators.push_back(new FileGenerator(file, file_options,
- /* immutable = */ true));
+ file_generators.emplace_back(
+ std::make_unique<FileGenerator>(file, file_options,
+ /* immutable = */ true));
}
if (file_options.generate_mutable_code) {
- file_generators.push_back(new FileGenerator(file, file_options,
- /* mutable = */ false));
+ file_generators.emplace_back(
+ std::make_unique<FileGenerator>(file, file_options,
+ /* mutable = */ false));
}
- for (int i = 0; i < file_generators.size(); ++i) {
- if (!file_generators[i]->Validate(error)) {
- for (int j = 0; j < file_generators.size(); ++j) {
- delete file_generators[j];
- }
+ for (auto& file_generator : file_generators) {
+ if (!file_generator->Validate(error)) {
return false;
}
}
- for (int i = 0; i < file_generators.size(); ++i) {
- FileGenerator* file_generator = file_generators[i];
-
+ for (auto& file_generator : file_generators) {
TProtoStringType package_dir = JavaPackageToDir(file_generator->java_package());
- TProtoStringType java_filename = package_dir;
- java_filename += file_generator->classname();
- java_filename += ".java";
+ TProtoStringType java_filename =
+ y_absl::StrCat(package_dir, file_generator->classname(), ".java");
all_files.push_back(java_filename);
- TProtoStringType info_full_path = java_filename + ".pb.meta";
+ TProtoStringType info_full_path = y_absl::StrCat(java_filename, ".pb.meta");
if (file_options.annotate_code) {
all_annotations.push_back(info_full_path);
}
@@ -174,9 +171,6 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
}
- for (int i = 0; i < file_generators.size(); ++i) {
- delete file_generators[i];
- }
file_generators.clear();
// Generate output list if requested.
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.h
index e08c980788..32225a0762 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator.h
@@ -38,10 +38,11 @@
#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__
#include <string>
-#include <google/protobuf/compiler/code_generator.h>
+
+#include "google/protobuf/compiler/code_generator.h"
// Must be included last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -55,6 +56,8 @@ namespace java {
class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
public:
JavaGenerator();
+ JavaGenerator(const JavaGenerator&) = delete;
+ JavaGenerator& operator=(const JavaGenerator&) = delete;
~JavaGenerator() override;
// implements CodeGenerator ----------------------------------------
@@ -63,8 +66,12 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
uint64_t GetSupportedFeatures() const override;
+ void set_opensource_runtime(bool opensource) {
+ opensource_runtime_ = opensource;
+ }
+
private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator);
+ bool opensource_runtime_ = PROTO2_IS_OSS;
};
} // namespace java
@@ -72,6 +79,6 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.cc
index dd526ba7c7..86baf0b06d 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.cc
@@ -30,17 +30,17 @@
// Author: liujisi@google.com (Pherl Liu)
-#include <google/protobuf/compiler/java/generator_factory.h>
+#include "google/protobuf/compiler/java/generator_factory.h"
-#include <google/protobuf/compiler/java/context.h>
-#include <google/protobuf/compiler/java/enum_field.h>
-#include <google/protobuf/compiler/java/extension.h>
-#include <google/protobuf/compiler/java/extension_lite.h>
-#include <google/protobuf/compiler/java/field.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/message.h>
-#include <google/protobuf/compiler/java/message_lite.h>
-#include <google/protobuf/compiler/java/service.h>
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/enum_field.h"
+#include "google/protobuf/compiler/java/extension.h"
+#include "google/protobuf/compiler/java/extension_lite.h"
+#include "google/protobuf/compiler/java/field.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/message.h"
+#include "google/protobuf/compiler/java/message_lite.h"
+#include "google/protobuf/compiler/java/service.h"
namespace google {
namespace protobuf {
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.h
index 807bca383a..b2fb0546e9 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/generator_factory.h
@@ -33,7 +33,7 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__
-#include <google/protobuf/stubs/common.h>
+#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@@ -59,6 +59,8 @@ namespace java {
class GeneratorFactory {
public:
GeneratorFactory();
+ GeneratorFactory(const GeneratorFactory&) = delete;
+ GeneratorFactory& operator=(const GeneratorFactory&) = delete;
virtual ~GeneratorFactory();
virtual MessageGenerator* NewMessageGenerator(
@@ -69,15 +71,15 @@ class GeneratorFactory {
virtual ServiceGenerator* NewServiceGenerator(
const ServiceDescriptor* descriptor) const = 0;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorFactory);
};
// Factory that creates generators for immutable-default messages.
class ImmutableGeneratorFactory : public GeneratorFactory {
public:
ImmutableGeneratorFactory(Context* context);
+ ImmutableGeneratorFactory(const ImmutableGeneratorFactory&) = delete;
+ ImmutableGeneratorFactory& operator=(const ImmutableGeneratorFactory&) =
+ delete;
~ImmutableGeneratorFactory() override;
MessageGenerator* NewMessageGenerator(
@@ -91,7 +93,6 @@ class ImmutableGeneratorFactory : public GeneratorFactory {
private:
Context* context_;
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableGeneratorFactory);
};
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.cc
index 96444c58fa..ada6babab5 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.cc
@@ -32,25 +32,31 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/helpers.h>
+#include "google/protobuf/compiler/java/helpers.h"
#include <algorithm>
#include <cstdint>
#include <limits>
-#include <unordered_set>
#include <vector>
-#include <google/protobuf/wire_format.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/stubs/stringprintf.h>
-#include <google/protobuf/stubs/substitute.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/compiler/java/names.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/stubs/hash.h> // for hash<T *>
+#include "y_absl/container/flat_hash_set.h"
+#include "y_absl/log/absl_check.h"
+#include "y_absl/log/absl_log.h"
+#include "y_absl/strings/ascii.h"
+#include "y_absl/strings/escaping.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/str_format.h"
+#include "y_absl/strings/str_replace.h"
+#include "y_absl/strings/str_split.h"
+#include "y_absl/strings/string_view.h"
+#include "y_absl/strings/substitute.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/descriptor.pb.h"
+#include "google/protobuf/io/strtod.h"
+#include "google/protobuf/wire_format.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -65,78 +71,9 @@ const char kThickSeparator[] =
const char kThinSeparator[] =
"// -------------------------------------------------------------------\n";
-namespace {
-
-const char* kDefaultPackage = "";
-
-// Names that should be avoided (in UpperCamelCase format).
-// Using them will cause the compiler to generate accessors whose names
-// collide with methods defined in base classes.
-// Keep this list in sync with specialFieldNames in
-// java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
-const char* kForbiddenWordList[] = {
- // java.lang.Object:
- "Class",
- // com.google.protobuf.MessageLiteOrBuilder:
- "DefaultInstanceForType",
- // com.google.protobuf.MessageLite:
- "ParserForType",
- "SerializedSize",
- // com.google.protobuf.MessageOrBuilder:
- "AllFields",
- "DescriptorForType",
- "InitializationErrorString",
- "UnknownFields",
- // obsolete. kept for backwards compatibility of generated code
- "CachedSize",
-};
-
-const std::unordered_set<TProtoStringType>* kReservedNames =
- new std::unordered_set<TProtoStringType>({
- "abstract", "assert", "boolean", "break", "byte",
- "case", "catch", "char", "class", "const",
- "continue", "default", "do", "double", "else",
- "enum", "extends", "final", "finally", "float",
- "for", "goto", "if", "implements", "import",
- "instanceof", "int", "interface", "long", "native",
- "new", "package", "private", "protected", "public",
- "return", "short", "static", "strictfp", "super",
- "switch", "synchronized", "this", "throw", "throws",
- "transient", "try", "void", "volatile", "while",
- });
-
-bool IsForbidden(const TProtoStringType& field_name) {
- for (int i = 0; i < GOOGLE_ARRAYSIZE(kForbiddenWordList); ++i) {
- if (UnderscoresToCamelCase(field_name, true) == kForbiddenWordList[i]) {
- return true;
- }
- }
- return false;
-}
-
-TProtoStringType FieldName(const FieldDescriptor* field) {
- TProtoStringType field_name;
- // Groups are hacky: The name of the field is just the lower-cased name
- // of the group type. In Java, though, we would like to retain the original
- // capitalization of the type name.
- if (GetType(field) == FieldDescriptor::TYPE_GROUP) {
- field_name = field->message_type()->name();
- } else {
- field_name = field->name();
- }
- if (IsForbidden(field_name)) {
- // Append a trailing "#" to indicate that the name should be decorated to
- // avoid collision with other names.
- field_name += "#";
- }
- return field_name;
-}
-
-
-} // namespace
-
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,
- const TProtoStringType& annotation_file) {
+ y_absl::string_view annotation_file,
+ Options options) {
if (annotation_file.empty()) {
return;
}
@@ -149,14 +86,14 @@ void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,
printer->Print(ptemplate.c_str(), "annotation_file", annotation_file);
}
-void PrintEnumVerifierLogic(io::Printer* printer,
- const FieldDescriptor* descriptor,
- const std::map<TProtoStringType, TProtoStringType>& variables,
- const char* var_name,
- const char* terminating_string, bool enforce_lite) {
+void PrintEnumVerifierLogic(
+ io::Printer* printer, const FieldDescriptor* descriptor,
+ const y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>& variables,
+ y_absl::string_view var_name, y_absl::string_view terminating_string,
+ bool enforce_lite) {
TProtoStringType enum_verifier_string =
- enforce_lite ? StrCat(var_name, ".internalGetVerifier()")
- : StrCat(
+ enforce_lite ? y_absl::StrCat(var_name, ".internalGetVerifier()")
+ : y_absl::StrCat(
"new com.google.protobuf.Internal.EnumVerifier() {\n"
" @java.lang.Override\n"
" public boolean isInRange(int number) {\n"
@@ -165,14 +102,13 @@ void PrintEnumVerifierLogic(io::Printer* printer,
".forNumber(number) != null;\n"
" }\n"
" }");
- printer->Print(
- variables,
- StrCat(enum_verifier_string, terminating_string).c_str());
+ printer->Print(variables,
+ y_absl::StrCat(enum_verifier_string, terminating_string));
}
-TProtoStringType UnderscoresToCamelCase(const TProtoStringType& input,
+TProtoStringType UnderscoresToCamelCase(y_absl::string_view input,
bool cap_next_letter) {
- GOOGLE_CHECK(!input.empty());
+ Y_ABSL_CHECK(!input.empty());
TProtoStringType result;
// Note: I distrust ctype.h due to locales.
for (int i = 0; i < input.size(); i++) {
@@ -207,7 +143,7 @@ TProtoStringType UnderscoresToCamelCase(const TProtoStringType& input,
return result;
}
-TProtoStringType ToCamelCase(const TProtoStringType& input, bool lower_first) {
+TProtoStringType ToCamelCase(y_absl::string_view input, bool lower_first) {
bool capitalize_next = !lower_first;
TProtoStringType result;
result.reserve(input.size());
@@ -216,7 +152,7 @@ TProtoStringType ToCamelCase(const TProtoStringType& input, bool lower_first) {
if (i == '_') {
capitalize_next = true;
} else if (capitalize_next) {
- result.push_back(ToUpperCh(i));
+ result.push_back(y_absl::ascii_toupper(i));
capitalize_next = false;
} else {
result.push_back(i);
@@ -225,146 +161,83 @@ TProtoStringType ToCamelCase(const TProtoStringType& input, bool lower_first) {
// Lower-case the first letter.
if (lower_first && !result.empty()) {
- result[0] = ToLowerCh(result[0]);
+ result[0] = y_absl::ascii_tolower(result[0]);
}
return result;
}
-char ToUpperCh(char ch) {
- return (ch >= 'a' && ch <= 'z') ? (ch - 'a' + 'A') : ch;
-}
-
-char ToLowerCh(char ch) {
- return (ch >= 'A' && ch <= 'Z') ? (ch - 'A' + 'a') : ch;
-}
-
-TProtoStringType UnderscoresToCamelCase(const FieldDescriptor* field) {
- return UnderscoresToCamelCase(FieldName(field), false);
-}
-
-TProtoStringType UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) {
- return UnderscoresToCamelCase(FieldName(field), true);
-}
-
-TProtoStringType CapitalizedFieldName(const FieldDescriptor* field) {
- return UnderscoresToCapitalizedCamelCase(field);
-}
-
-TProtoStringType UnderscoresToCamelCase(const MethodDescriptor* method) {
- return UnderscoresToCamelCase(method->name(), false);
-}
-
-TProtoStringType UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) {
- TProtoStringType name = UnderscoresToCamelCase(field);
- if (kReservedNames->find(name) != kReservedNames->end()) {
- return name + "_";
- }
- return name;
-}
-
// Names that should be avoided as field names in Kotlin.
// All Kotlin hard keywords are in this list.
-const std::unordered_set<TProtoStringType>* kKotlinForbiddenNames =
- new std::unordered_set<TProtoStringType>({
- "as", "as?", "break", "class", "continue", "do", "else",
- "false", "for", "fun", "if", "in", "!in", "interface",
- "is", "!is", "null", "object", "package", "return", "super",
- "this", "throw", "true", "try", "typealias", "typeof", "val",
- "var", "when", "while",
- });
-
-bool IsForbiddenKotlin(const TProtoStringType& field_name) {
- return kKotlinForbiddenNames->find(field_name) !=
- kKotlinForbiddenNames->end();
+bool IsForbiddenKotlin(y_absl::string_view field_name) {
+ static const auto& kKotlinForbiddenNames =
+ *new y_absl::flat_hash_set<y_absl::string_view>({
+ "as", "as?", "break", "class", "continue", "do",
+ "else", "false", "for", "fun", "if", "in",
+ "!in", "interface", "is", "!is", "null", "object",
+ "package", "return", "super", "this", "throw", "true",
+ "try", "typealias", "typeof", "val", "var", "when",
+ "while",
+ });
+
+ return kKotlinForbiddenNames.contains(field_name);
+}
+
+TProtoStringType EscapeKotlinKeywords(TProtoStringType name) {
+ std::vector<TProtoStringType> escaped_packages;
+ std::vector<TProtoStringType> packages = y_absl::StrSplit(name, "."); // NOLINT
+ for (y_absl::string_view package : packages) {
+ if (IsForbiddenKotlin(package)) {
+ escaped_packages.push_back(y_absl::StrCat("`", package, "`"));
+ } else {
+ escaped_packages.emplace_back(package);
+ }
+ }
+ return y_absl::StrJoin(escaped_packages, ".");
}
TProtoStringType UniqueFileScopeIdentifier(const Descriptor* descriptor) {
- return "static_" + StringReplace(descriptor->full_name(), ".", "_", true);
+ return y_absl::StrCat(
+ "static_", y_absl::StrReplaceAll(descriptor->full_name(), {{".", "_"}}));
}
TProtoStringType CamelCaseFieldName(const FieldDescriptor* field) {
TProtoStringType fieldName = UnderscoresToCamelCase(field);
if ('0' <= fieldName[0] && fieldName[0] <= '9') {
- return '_' + fieldName;
+ return y_absl::StrCat("_", fieldName);
}
return fieldName;
}
TProtoStringType FileClassName(const FileDescriptor* file, bool immutable) {
- ClassNameResolver name_resolver;
- return name_resolver.GetFileClassName(file, immutable);
-}
-
-TProtoStringType FileJavaPackage(const FileDescriptor* file, bool immutable) {
- TProtoStringType result;
-
- if (file->options().has_java_package()) {
- result = file->options().java_package();
- } else {
- result = kDefaultPackage;
- if (!file->package().empty()) {
- if (!result.empty()) result += '.';
- result += file->package();
- }
- }
-
- return result;
-}
-
-TProtoStringType FileJavaPackage(const FileDescriptor* file) {
- return FileJavaPackage(file, true /* immutable */);
+ return ClassNameResolver().GetFileClassName(file, immutable);
}
TProtoStringType JavaPackageToDir(TProtoStringType package_name) {
- TProtoStringType package_dir = StringReplace(package_name, ".", "/", true);
- if (!package_dir.empty()) package_dir += "/";
+ TProtoStringType package_dir = y_absl::StrReplaceAll(package_name, {{".", "/"}});
+ if (!package_dir.empty()) y_absl::StrAppend(&package_dir, "/");
return package_dir;
}
-TProtoStringType ClassName(const Descriptor* descriptor) {
- ClassNameResolver name_resolver;
- return name_resolver.GetClassName(descriptor, true);
-}
-
-TProtoStringType ClassName(const EnumDescriptor* descriptor) {
- ClassNameResolver name_resolver;
- return name_resolver.GetClassName(descriptor, true);
-}
-
-TProtoStringType ClassName(const ServiceDescriptor* descriptor) {
- ClassNameResolver name_resolver;
- return name_resolver.GetClassName(descriptor, true);
-}
-
-TProtoStringType ClassName(const FileDescriptor* descriptor) {
- ClassNameResolver name_resolver;
- return name_resolver.GetClassName(descriptor, true);
-}
-
-
TProtoStringType ExtraMessageInterfaces(const Descriptor* descriptor) {
- TProtoStringType interfaces = "// @@protoc_insertion_point(message_implements:" +
- descriptor->full_name() + ")";
- return interfaces;
+ return y_absl::StrCat("// @@protoc_insertion_point(message_implements:",
+ descriptor->full_name(), ")");
}
TProtoStringType ExtraBuilderInterfaces(const Descriptor* descriptor) {
- TProtoStringType interfaces = "// @@protoc_insertion_point(builder_implements:" +
- descriptor->full_name() + ")";
- return interfaces;
+ return y_absl::StrCat("// @@protoc_insertion_point(builder_implements:",
+ descriptor->full_name(), ")");
}
TProtoStringType ExtraMessageOrBuilderInterfaces(const Descriptor* descriptor) {
- TProtoStringType interfaces = "// @@protoc_insertion_point(interface_extends:" +
- descriptor->full_name() + ")";
- return interfaces;
+ return y_absl::StrCat("// @@protoc_insertion_point(interface_extends:",
+ descriptor->full_name(), ")");
}
TProtoStringType FieldConstantName(const FieldDescriptor* field) {
- TProtoStringType name = field->name() + "_FIELD_NUMBER";
- ToUpper(&name);
+ TProtoStringType name = y_absl::StrCat(field->name(), "_FIELD_NUMBER");
+ y_absl::AsciiStrToUpper(&name);
return name;
}
@@ -414,11 +287,11 @@ JavaType GetJavaType(const FieldDescriptor* field) {
// types are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
return JAVATYPE_INT;
}
-const char* PrimitiveTypeName(JavaType type) {
+y_absl::string_view PrimitiveTypeName(JavaType type) {
switch (type) {
case JAVATYPE_INT:
return "int";
@@ -435,23 +308,23 @@ const char* PrimitiveTypeName(JavaType type) {
case JAVATYPE_BYTES:
return "com.google.protobuf.ByteString";
case JAVATYPE_ENUM:
- return NULL;
+ return {};
case JAVATYPE_MESSAGE:
- return NULL;
+ return {};
// No default because we want the compiler to complain if any new
// JavaTypes are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return NULL;
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
+ return {};
}
-const char* PrimitiveTypeName(const FieldDescriptor* descriptor) {
+y_absl::string_view PrimitiveTypeName(const FieldDescriptor* descriptor) {
return PrimitiveTypeName(GetJavaType(descriptor));
}
-const char* BoxedPrimitiveTypeName(JavaType type) {
+y_absl::string_view BoxedPrimitiveTypeName(JavaType type) {
switch (type) {
case JAVATYPE_INT:
return "java.lang.Integer";
@@ -468,23 +341,23 @@ const char* BoxedPrimitiveTypeName(JavaType type) {
case JAVATYPE_BYTES:
return "com.google.protobuf.ByteString";
case JAVATYPE_ENUM:
- return NULL;
+ return {};
case JAVATYPE_MESSAGE:
- return NULL;
+ return {};
// No default because we want the compiler to complain if any new
// JavaTypes are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return NULL;
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
+ return {};
}
-const char* BoxedPrimitiveTypeName(const FieldDescriptor* descriptor) {
+y_absl::string_view BoxedPrimitiveTypeName(const FieldDescriptor* descriptor) {
return BoxedPrimitiveTypeName(GetJavaType(descriptor));
}
-const char* KotlinTypeName(JavaType type) {
+y_absl::string_view KotlinTypeName(JavaType type) {
switch (type) {
case JAVATYPE_INT:
return "kotlin.Int";
@@ -501,16 +374,16 @@ const char* KotlinTypeName(JavaType type) {
case JAVATYPE_BYTES:
return "com.google.protobuf.ByteString";
case JAVATYPE_ENUM:
- return NULL;
+ return {};
case JAVATYPE_MESSAGE:
- return NULL;
+ return {};
// No default because we want the compiler to complain if any new
// JavaTypes are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return NULL;
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
+ return {};
}
TProtoStringType GetOneofStoredType(const FieldDescriptor* field) {
@@ -519,13 +392,13 @@ TProtoStringType GetOneofStoredType(const FieldDescriptor* field) {
case JAVATYPE_ENUM:
return "java.lang.Integer";
case JAVATYPE_MESSAGE:
- return ClassName(field->message_type());
+ return ClassNameResolver().GetClassName(field->message_type(), true);
default:
- return BoxedPrimitiveTypeName(javaType);
+ return TProtoStringType(BoxedPrimitiveTypeName(javaType));
}
}
-const char* FieldTypeName(FieldDescriptor::Type field_type) {
+y_absl::string_view FieldTypeName(FieldDescriptor::Type field_type) {
switch (field_type) {
case FieldDescriptor::TYPE_INT32:
return "INT32";
@@ -568,11 +441,11 @@ const char* FieldTypeName(FieldDescriptor::Type field_type) {
// types are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return NULL;
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
+ return {};
}
-bool AllAscii(const TProtoStringType& text) {
+bool AllAscii(y_absl::string_view text) {
for (int i = 0; i < text.size(); i++) {
if ((text[i] & 0x80) != 0) {
return false;
@@ -582,19 +455,19 @@ bool AllAscii(const TProtoStringType& text) {
}
TProtoStringType DefaultValue(const FieldDescriptor* field, bool immutable,
- ClassNameResolver* name_resolver) {
+ ClassNameResolver* name_resolver, Options options) {
// Switch on CppType since we need to know which default_value_* method
// of FieldDescriptor to call.
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
- return StrCat(field->default_value_int32());
+ return y_absl::StrCat(field->default_value_int32());
case FieldDescriptor::CPPTYPE_UINT32:
// Need to print as a signed int since Java has no unsigned.
- return StrCat(static_cast<arc_i32>(field->default_value_uint32()));
+ return y_absl::StrCat(static_cast<arc_i32>(field->default_value_uint32()));
case FieldDescriptor::CPPTYPE_INT64:
- return StrCat(field->default_value_int64()) + "L";
+ return y_absl::StrCat(field->default_value_int64(), "L");
case FieldDescriptor::CPPTYPE_UINT64:
- return StrCat(static_cast<arc_i64>(field->default_value_uint64())) +
+ return y_absl::StrCat(static_cast<arc_i64>(field->default_value_uint64())) +
"L";
case FieldDescriptor::CPPTYPE_DOUBLE: {
double value = field->default_value_double();
@@ -605,7 +478,7 @@ TProtoStringType DefaultValue(const FieldDescriptor* field, bool immutable,
} else if (value != value) {
return "Double.NaN";
} else {
- return SimpleDtoa(value) + "D";
+ return y_absl::StrCat(io::SimpleDtoa(value), "D");
}
}
case FieldDescriptor::CPPTYPE_FLOAT: {
@@ -617,7 +490,7 @@ TProtoStringType DefaultValue(const FieldDescriptor* field, bool immutable,
} else if (value != value) {
return "Float.NaN";
} else {
- return SimpleFtoa(value) + "F";
+ return y_absl::StrCat(io::SimpleFtoa(value), "F");
}
}
case FieldDescriptor::CPPTYPE_BOOL:
@@ -626,37 +499,40 @@ TProtoStringType DefaultValue(const FieldDescriptor* field, bool immutable,
if (GetType(field) == FieldDescriptor::TYPE_BYTES) {
if (field->has_default_value()) {
// See comments in Internal.java for gory details.
- return strings::Substitute(
+ return y_absl::Substitute(
"com.google.protobuf.Internal.bytesDefaultValue(\"$0\")",
- CEscape(field->default_value_string()));
+ y_absl::CEscape(field->default_value_string()));
} else {
return "com.google.protobuf.ByteString.EMPTY";
}
} else {
if (AllAscii(field->default_value_string())) {
// All chars are ASCII. In this case CEscape() works fine.
- return "\"" + CEscape(field->default_value_string()) + "\"";
+ return y_absl::StrCat(
+ "\"", y_absl::CEscape(field->default_value_string()), "\"");
} else {
// See comments in Internal.java for gory details.
- return strings::Substitute(
+ return y_absl::Substitute(
"com.google.protobuf.Internal.stringDefaultValue(\"$0\")",
- CEscape(field->default_value_string()));
+ y_absl::CEscape(field->default_value_string()));
}
}
case FieldDescriptor::CPPTYPE_ENUM:
- return name_resolver->GetClassName(field->enum_type(), immutable) + "." +
- field->default_value_enum()->name();
+ return y_absl::StrCat(
+ name_resolver->GetClassName(field->enum_type(), immutable), ".",
+ field->default_value_enum()->name());
case FieldDescriptor::CPPTYPE_MESSAGE:
- return name_resolver->GetClassName(field->message_type(), immutable) +
- ".getDefaultInstance()";
+ return y_absl::StrCat(
+ name_resolver->GetClassName(field->message_type(), immutable),
+ ".getDefaultInstance()");
// No default because we want the compiler to complain if any new
// types are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
return "";
}
@@ -688,7 +564,7 @@ bool IsDefaultValueJavaDefault(const FieldDescriptor* field) {
// types are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
return false;
}
@@ -697,7 +573,7 @@ bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field) {
field->default_value_string() != "";
}
-const char* bit_masks[] = {
+constexpr y_absl::string_view bit_masks[] = {
"0x00000001", "0x00000002", "0x00000004", "0x00000008",
"0x00000010", "0x00000020", "0x00000040", "0x00000080",
@@ -712,10 +588,7 @@ const char* bit_masks[] = {
};
TProtoStringType GetBitFieldName(int index) {
- TProtoStringType varName = "bitField";
- varName += StrCat(index);
- varName += "_";
- return varName;
+ return y_absl::StrCat("bitField", index, "_");
}
TProtoStringType GetBitFieldNameForBit(int bitIndex) {
@@ -724,22 +597,19 @@ TProtoStringType GetBitFieldNameForBit(int bitIndex) {
namespace {
-TProtoStringType GenerateGetBitInternal(const TProtoStringType& prefix, int bitIndex) {
- TProtoStringType varName = prefix + GetBitFieldNameForBit(bitIndex);
+TProtoStringType GenerateGetBitInternal(y_absl::string_view prefix, int bitIndex) {
+ TProtoStringType varName = y_absl::StrCat(prefix, GetBitFieldNameForBit(bitIndex));
int bitInVarIndex = bitIndex % 32;
- TProtoStringType mask = bit_masks[bitInVarIndex];
- TProtoStringType result = "((" + varName + " & " + mask + ") != 0)";
- return result;
+ return y_absl::StrCat("((", varName, " & ", bit_masks[bitInVarIndex],
+ ") != 0)");
}
-TProtoStringType GenerateSetBitInternal(const TProtoStringType& prefix, int bitIndex) {
- TProtoStringType varName = prefix + GetBitFieldNameForBit(bitIndex);
+TProtoStringType GenerateSetBitInternal(y_absl::string_view prefix, int bitIndex) {
+ TProtoStringType varName = y_absl::StrCat(prefix, GetBitFieldNameForBit(bitIndex));
int bitInVarIndex = bitIndex % 32;
- TProtoStringType mask = bit_masks[bitInVarIndex];
- TProtoStringType result = varName + " |= " + mask;
- return result;
+ return y_absl::StrCat(varName, " |= ", bit_masks[bitInVarIndex]);
}
} // namespace
@@ -756,9 +626,8 @@ TProtoStringType GenerateClearBit(int bitIndex) {
TProtoStringType varName = GetBitFieldNameForBit(bitIndex);
int bitInVarIndex = bitIndex % 32;
- TProtoStringType mask = bit_masks[bitInVarIndex];
- TProtoStringType result = varName + " = (" + varName + " & ~" + mask + ")";
- return result;
+ return y_absl::StrCat(varName, " = (", varName, " & ~",
+ bit_masks[bitInVarIndex], ")");
}
TProtoStringType GenerateGetBitFromLocal(int bitIndex) {
@@ -802,11 +671,12 @@ bool IsReferenceType(JavaType type) {
// JavaTypes are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
return false;
}
-const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) {
+y_absl::string_view GetCapitalizedType(const FieldDescriptor* field,
+ bool immutable, Options options) {
switch (GetType(field)) {
case FieldDescriptor::TYPE_INT32:
return "Int32";
@@ -850,8 +720,8 @@ const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) {
// types are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return NULL;
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
+ return {};
}
// For encodings with fixed sizes, returns that size in bytes. Otherwise
@@ -900,7 +770,7 @@ int FixedSize(FieldDescriptor::Type type) {
// No default because we want the compiler to complain if any new
// types are added.
}
- GOOGLE_LOG(FATAL) << "Can't get here.";
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
return -1;
}
@@ -923,7 +793,7 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) {
// already_seen is used to avoid checking the same type multiple times
// (and also to protect against recursion).
bool HasRequiredFields(const Descriptor* type,
- std::unordered_set<const Descriptor*>* already_seen) {
+ y_absl::flat_hash_set<const Descriptor*>* already_seen) {
if (already_seen->count(type) > 0) {
// The type is already in cache. This means that either:
// a. The type has no required fields.
@@ -958,7 +828,7 @@ bool HasRequiredFields(const Descriptor* type,
}
bool HasRequiredFields(const Descriptor* type) {
- std::unordered_set<const Descriptor*> already_seen;
+ y_absl::flat_hash_set<const Descriptor*> already_seen;
return HasRequiredFields(type, &already_seen);
}
@@ -1036,7 +906,7 @@ int GetExperimentalJavaFieldTypeForPacked(const FieldDescriptor* field) {
} else if (result > FieldDescriptor::TYPE_BYTES) {
return result + 30;
} else {
- GOOGLE_LOG(FATAL) << field->full_name() << " can't be packed.";
+ Y_ABSL_LOG(FATAL) << field->full_name() << " can't be packed.";
return 0;
}
}
@@ -1103,7 +973,7 @@ void EscapeUtf16ToString(uint16_t code, TProtoStringType* output) {
} else if (code >= 0x20 && code <= 0x7f) {
output->push_back(static_cast<char>(code));
} else {
- output->append(StringPrintf("\\u%04x", code));
+ output->append(y_absl::StrFormat("\\u%04x", code));
}
}
@@ -1112,4 +982,4 @@ void EscapeUtf16ToString(uint16_t code, TProtoStringType* output) {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.h
index 7f4c4aad14..e4fac63426 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/helpers.h
@@ -38,10 +38,15 @@
#include <cstdint>
#include <string>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/compiler/java/context.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/strings/string_view.h"
+#include "google/protobuf/compiler/java/names.h"
+#include "google/protobuf/compiler/java/options.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/descriptor.pb.h"
+#include "google/protobuf/io/printer.h"
+
+// Must be last.
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -53,7 +58,7 @@ namespace java {
extern const char kThickSeparator[];
extern const char kThinSeparator[];
-bool IsForbiddenKotlin(const TProtoStringType& field_name);
+bool IsForbiddenKotlin(y_absl::string_view field_name);
// If annotation_file is non-empty, prints a javax.annotation.Generated
// annotation to the given Printer. annotation_file will be referenced in the
@@ -64,38 +69,20 @@ bool IsForbiddenKotlin(const TProtoStringType& field_name);
// annotation_file should be generated from the filename of the source file
// being annotated (which in turn must be a Java identifier plus ".java").
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$',
- const TProtoStringType& annotation_file = "");
+ y_absl::string_view annotation_file = "",
+ Options options = {});
// If a GeneratedMessageLite contains non-lite enums, then its verifier
// must be instantiated inline, rather than retrieved from the enum class.
-void PrintEnumVerifierLogic(io::Printer* printer,
- const FieldDescriptor* descriptor,
- const std::map<TProtoStringType, TProtoStringType>& variables,
- const char* var_name,
- const char* terminating_string, bool enforce_lite);
-
-// Converts a name to camel-case. If cap_first_letter is true, capitalize the
-// first letter.
-TProtoStringType ToCamelCase(const TProtoStringType& input, bool lower_first);
-
-char ToUpperCh(char ch);
-char ToLowerCh(char ch);
+void PrintEnumVerifierLogic(
+ io::Printer* printer, const FieldDescriptor* descriptor,
+ const y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>& variables,
+ y_absl::string_view var_name, y_absl::string_view terminating_string,
+ bool enforce_lite);
// Converts a name to camel-case. If cap_first_letter is true, capitalize the
// first letter.
-TProtoStringType UnderscoresToCamelCase(const TProtoStringType& name,
- bool cap_first_letter);
-// Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes
-// "fooBarBaz" or "FooBarBaz", respectively.
-TProtoStringType UnderscoresToCamelCase(const FieldDescriptor* field);
-TProtoStringType UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field);
-
-// Similar, but for method names. (Typically, this merely has the effect
-// of lower-casing the first letter of the name.)
-TProtoStringType UnderscoresToCamelCase(const MethodDescriptor* method);
-
-// Same as UnderscoresToCamelCase, but checks for reserved keywords
-TProtoStringType UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field);
+TProtoStringType ToCamelCase(y_absl::string_view input, bool lower_first);
// Similar to UnderscoresToCamelCase, but guarantees that the result is a
// complete Java identifier by adding a _ if needed.
@@ -113,11 +100,15 @@ TProtoStringType UniqueFileScopeIdentifier(const Descriptor* descriptor);
TProtoStringType FileClassName(const FileDescriptor* file, bool immutable = true);
// Returns the file's Java package name.
-TProtoStringType FileJavaPackage(const FileDescriptor* file, bool immutable);
+TProtoStringType FileJavaPackage(const FileDescriptor* file, bool immutable,
+ Options options = {});
// Returns output directory for the given package name.
TProtoStringType JavaPackageToDir(TProtoStringType package_name);
+// Returns the name with Kotlin keywords enclosed in backticks
+TProtoStringType EscapeKotlinKeywords(TProtoStringType name);
+
// Comma-separate list of option-specified interfaces implemented by the
// Message, to follow the "implements" declaration of the Message definition.
TProtoStringType ExtraMessageInterfaces(const Descriptor* descriptor);
@@ -194,20 +185,8 @@ inline bool IsOwnFile(const ServiceDescriptor* descriptor, bool immutable) {
// (e.g.) be "OrBuilder" for some generated interfaces.
template <typename Descriptor>
TProtoStringType AnnotationFileName(const Descriptor* descriptor,
- const TProtoStringType& suffix) {
- return descriptor->name() + suffix + ".java.pb.meta";
-}
-
-template <typename Descriptor>
-void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer,
- Descriptor* descriptor, bool immutable,
- const TProtoStringType& suffix = "") {
- if (IsOwnFile(descriptor, immutable)) {
- PrintGeneratedAnnotation(printer, '$',
- context->options().annotate_code
- ? AnnotationFileName(descriptor, suffix)
- : "");
- }
+ y_absl::string_view suffix) {
+ return y_absl::StrCat(descriptor->name(), suffix, ".java.pb.meta");
}
// Get the unqualified name that should be used for a field's field
@@ -233,28 +212,30 @@ enum JavaType {
JavaType GetJavaType(const FieldDescriptor* field);
-const char* PrimitiveTypeName(JavaType type);
+y_absl::string_view PrimitiveTypeName(JavaType type);
// Get the fully-qualified class name for a boxed primitive type, e.g.
// "java.lang.Integer" for JAVATYPE_INT. Returns NULL for enum and message
// types.
-const char* BoxedPrimitiveTypeName(JavaType type);
+y_absl::string_view BoxedPrimitiveTypeName(JavaType type);
// Kotlin source does not distinguish between primitives and non-primitives,
// but does use Kotlin-specific qualified types for them.
-const char* KotlinTypeName(JavaType type);
+y_absl::string_view KotlinTypeName(JavaType type);
// Get the name of the java enum constant representing this type. E.g.,
// "INT32" for FieldDescriptor::TYPE_INT32. The enum constant's full
// name is "com.google.protobuf.WireFormat.FieldType.INT32".
-const char* FieldTypeName(const FieldDescriptor::Type field_type);
+y_absl::string_view FieldTypeName(const FieldDescriptor::Type field_type);
class ClassNameResolver;
TProtoStringType DefaultValue(const FieldDescriptor* field, bool immutable,
- ClassNameResolver* name_resolver);
+ ClassNameResolver* name_resolver,
+ Options options = {});
inline TProtoStringType ImmutableDefaultValue(const FieldDescriptor* field,
- ClassNameResolver* name_resolver) {
- return DefaultValue(field, true, name_resolver);
+ ClassNameResolver* name_resolver,
+ Options options = {}) {
+ return DefaultValue(field, true, name_resolver, options);
}
bool IsDefaultValueJavaDefault(const FieldDescriptor* field);
bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field);
@@ -333,7 +314,8 @@ bool IsReferenceType(JavaType type);
// Returns the capitalized name for calling relative functions in
// CodedInputStream
-const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable);
+y_absl::string_view GetCapitalizedType(const FieldDescriptor* field,
+ bool immutable, Options options);
// For encodings with fixed sizes, returns that size in bytes. Otherwise
// returns -1.
@@ -471,4 +453,5 @@ std::pair<int, int> GetTableDrivenNumberOfEntriesAndLookUpStartFieldNumber(
} // namespace protobuf
} // namespace google
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.cc
index 570840cfc1..90235f6cb8 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.cc
@@ -28,13 +28,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <google/protobuf/compiler/java/kotlin_generator.h>
+#include "google/protobuf/compiler/java/kotlin_generator.h"
-#include <google/protobuf/compiler/code_generator.h>
-#include <google/protobuf/compiler/java/file.h>
-#include <google/protobuf/compiler/java/generator.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/options.h>
+#include "google/protobuf/compiler/code_generator.h"
+#include "google/protobuf/compiler/java/file.h"
+#include "google/protobuf/compiler/java/generator.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/options.h"
namespace google {
namespace protobuf {
@@ -78,7 +78,7 @@ bool KotlinGenerator::Generate(const FileDescriptor* file,
} else if (option.first == "annotation_list_file") {
file_options.annotation_list_file = option.second;
} else {
- *error = "Unknown generator option: " + option.first;
+ *error = y_absl::StrCat("Unknown generator option: ", option.first);
return false;
}
}
@@ -101,11 +101,10 @@ bool KotlinGenerator::Generate(const FileDescriptor* file,
return std::unique_ptr<io::ZeroCopyOutputStream>(context->Open(filename));
};
TProtoStringType package_dir = JavaPackageToDir(file_generator->java_package());
- TProtoStringType kotlin_filename = package_dir;
- kotlin_filename += file_generator->GetKotlinClassname();
- kotlin_filename += ".kt";
+ TProtoStringType kotlin_filename =
+ y_absl::StrCat(package_dir, file_generator->GetKotlinClassname(), ".kt");
all_files.push_back(kotlin_filename);
- TProtoStringType info_full_path = kotlin_filename + ".pb.meta";
+ TProtoStringType info_full_path = y_absl::StrCat(kotlin_filename, ".pb.meta");
if (file_options.annotate_code) {
all_annotations.push_back(info_full_path);
}
@@ -119,6 +118,8 @@ bool KotlinGenerator::Generate(const FileDescriptor* file,
output.get(), '$',
file_options.annotate_code ? &annotation_collector : nullptr);
+ file_generator->GenerateKotlin(&printer);
+
file_generator->GenerateKotlinSiblings(package_dir, context, &all_files,
&all_annotations);
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.h
index 195acb6537..91c4b836c5 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/kotlin_generator.h
@@ -35,10 +35,10 @@
#include <string>
-#include <google/protobuf/compiler/code_generator.h>
+#include "google/protobuf/compiler/code_generator.h"
// Must be included last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -52,6 +52,8 @@ namespace java {
class PROTOC_EXPORT KotlinGenerator : public CodeGenerator {
public:
KotlinGenerator();
+ KotlinGenerator(const KotlinGenerator&) = delete;
+ KotlinGenerator& operator=(const KotlinGenerator&) = delete;
~KotlinGenerator() override;
// implements CodeGenerator ----------------------------------------
@@ -59,9 +61,6 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator {
GeneratorContext* context, TProtoStringType* error) const override;
uint64_t GetSupportedFeatures() const override;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(KotlinGenerator);
};
} // namespace java
@@ -69,6 +68,6 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.cc
index 37bad491c0..8c3be3c096 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.cc
@@ -28,16 +28,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <google/protobuf/compiler/java/map_field.h>
+#include "google/protobuf/compiler/java/map_field.h"
-#include <google/protobuf/io/printer.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 "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/io/printer.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -47,16 +48,16 @@ namespace java {
namespace {
const FieldDescriptor* KeyField(const FieldDescriptor* descriptor) {
- GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
+ Y_ABSL_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
const Descriptor* message = descriptor->message_type();
- GOOGLE_CHECK(message->options().map_entry());
+ Y_ABSL_CHECK(message->options().map_entry());
return message->map_key();
}
const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) {
- GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
+ Y_ABSL_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
const Descriptor* message = descriptor->message_type();
- GOOGLE_CHECK(message->options().map_entry());
+ Y_ABSL_CHECK(message->options().map_entry());
return message->map_value();
}
@@ -67,8 +68,8 @@ TProtoStringType TypeName(const FieldDescriptor* field,
} else if (GetJavaType(field) == JAVATYPE_ENUM) {
return name_resolver->GetImmutableClassName(field->enum_type());
} else {
- return boxed ? BoxedPrimitiveTypeName(GetJavaType(field))
- : PrimitiveTypeName(GetJavaType(field));
+ return TProtoStringType(boxed ? BoxedPrimitiveTypeName(GetJavaType(field))
+ : PrimitiveTypeName(GetJavaType(field)));
}
}
@@ -79,19 +80,19 @@ TProtoStringType KotlinTypeName(const FieldDescriptor* field,
} else if (GetJavaType(field) == JAVATYPE_ENUM) {
return name_resolver->GetImmutableClassName(field->enum_type());
} else {
- return KotlinTypeName(GetJavaType(field));
+ return TProtoStringType(KotlinTypeName(GetJavaType(field)));
}
}
TProtoStringType WireType(const FieldDescriptor* field) {
- return "com.google.protobuf.WireFormat.FieldType." +
- TProtoStringType(FieldTypeName(field->type()));
+ return y_absl::StrCat("com.google.protobuf.WireFormat.FieldType.",
+ FieldTypeName(field->type()));
}
-void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
- int builderBitIndex, const FieldGeneratorInfo* info,
- Context* context,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetMessageVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, Context* context,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
ClassNameResolver* name_resolver = context->GetNameResolver();
@@ -102,7 +103,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const JavaType keyJavaType = GetJavaType(key);
const JavaType valueJavaType = GetJavaType(value);
- TProtoStringType pass_through_nullness = "/* nullable */\n";
+ // The code that generates the open-source version appears not to understand
+ // #else, so we have an #ifndef instead.
+ TProtoStringType pass_through_nullness =
+ context->options().opensource_runtime
+ ? "/* nullable */\n"
+ : "@com.google.protobuf.Internal.ProtoPassThroughNullness ";
(*variables)["key_type"] = TypeName(key, name_resolver, false);
TProtoStringType boxed_key_type = TypeName(key, name_resolver, true);
@@ -113,78 +119,89 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["short_key_type"] =
boxed_key_type.substr(boxed_key_type.rfind('.') + 1);
(*variables)["key_wire_type"] = WireType(key);
- (*variables)["key_default_value"] = DefaultValue(key, true, name_resolver);
+ (*variables)["key_default_value"] =
+ DefaultValue(key, true, name_resolver, context->options());
(*variables)["key_null_check"] =
IsReferenceType(keyJavaType)
? "if (key == null) { throw new NullPointerException(\"map key\"); }"
: "";
(*variables)["value_null_check"] =
valueJavaType != JAVATYPE_ENUM && IsReferenceType(valueJavaType)
- ? "if (value == null) {\n"
- " throw new NullPointerException(\"map value\");\n"
- "}\n"
+ ? "if (value == null) { "
+ "throw new NullPointerException(\"map value\"); }"
: "";
if (valueJavaType == JAVATYPE_ENUM) {
// We store enums as Integers internally.
(*variables)["value_type"] = "int";
+ variables->insert(
+ {"value_type_pass_through_nullness", (*variables)["value_type"]});
(*variables)["boxed_value_type"] = "java.lang.Integer";
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
- DefaultValue(value, true, name_resolver) + ".getNumber()";
+ DefaultValue(value, true, name_resolver, context->options()) +
+ ".getNumber()";
(*variables)["value_enum_type"] = TypeName(value, name_resolver, false);
- (*variables)["value_enum_type_pass_through_nullness"] =
- pass_through_nullness + (*variables)["value_enum_type"];
+ variables->insert(
+ {"value_enum_type_pass_through_nullness",
+ y_absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"])});
if (SupportUnknownEnumValue(descriptor->file())) {
// Map unknown values to a special UNRECOGNIZED value if supported.
- (*variables)["unrecognized_value"] =
- (*variables)["value_enum_type"] + ".UNRECOGNIZED";
+ variables->insert(
+ {"unrecognized_value",
+ y_absl::StrCat((*variables)["value_enum_type"], ".UNRECOGNIZED")});
} else {
// Map unknown values to the default value if we don't have UNRECOGNIZED.
(*variables)["unrecognized_value"] =
- DefaultValue(value, true, name_resolver);
+ DefaultValue(value, true, name_resolver, context->options());
}
} else {
(*variables)["value_type"] = TypeName(value, name_resolver, false);
- (*variables)["value_type_pass_through_nullness"] =
- (IsReferenceType(valueJavaType) ? pass_through_nullness : "") +
- (*variables)["value_type"];
+ variables->insert(
+ {"value_type_pass_through_nullness",
+ y_absl::StrCat(
+ (IsReferenceType(valueJavaType) ? pass_through_nullness : ""),
+ (*variables)["value_type"])});
(*variables)["boxed_value_type"] = TypeName(value, name_resolver, true);
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
- DefaultValue(value, true, name_resolver);
+ DefaultValue(value, true, name_resolver, context->options());
}
- (*variables)["type_parameters"] =
- (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"];
+ variables->insert(
+ {"type_parameters", y_absl::StrCat((*variables)["boxed_key_type"], ", ",
+ (*variables)["boxed_value_type"])});
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
(*variables)["on_changed"] = "onChanged();";
- // For repeated fields, one bit is used for whether the array is immutable
- // in the parsing constructor.
- (*variables)["get_mutable_bit_parser"] =
- GenerateGetBitMutableLocal(builderBitIndex);
- (*variables)["set_mutable_bit_parser"] =
- GenerateSetBitMutableLocal(builderBitIndex);
-
- (*variables)["default_entry"] =
- (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry";
- (*variables)["map_field_parameter"] = (*variables)["default_entry"];
- (*variables)["descriptor"] =
- name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" +
- UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, ";
+ variables->insert(
+ {"default_entry", y_absl::StrCat((*variables)["capitalized_name"],
+ "DefaultEntryHolder.defaultEntry")});
+ variables->insert({"map_field_parameter", (*variables)["default_entry"]});
+ (*variables)["descriptor"] = y_absl::StrCat(
+ name_resolver->GetImmutableClassName(descriptor->file()), ".internal_",
+ UniqueFileScopeIdentifier(descriptor->message_type()), "_descriptor, ");
(*variables)["ver"] = GeneratedCodeVersionSuffix();
+
+ (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
+ (*variables)["get_has_field_bit_from_local"] =
+ GenerateGetBitFromLocal(builderBitIndex);
+ (*variables)["set_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateSetBit(builderBitIndex), ";");
+ (*variables)["clear_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateClearBit(builderBitIndex), ";");
}
} // namespace
@@ -192,7 +209,11 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMapFieldGenerator::ImmutableMapFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ message_bit_index_(messageBitIndex),
+ builder_bit_index_(builderBitIndex),
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), context,
&variables_);
@@ -200,6 +221,14 @@ ImmutableMapFieldGenerator::ImmutableMapFieldGenerator(
ImmutableMapFieldGenerator::~ImmutableMapFieldGenerator() {}
+int ImmutableMapFieldGenerator::GetMessageBitIndex() const {
+ return message_bit_index_;
+}
+
+int ImmutableMapFieldGenerator::GetBuilderBitIndex() const {
+ return builder_bit_index_;
+}
+
int ImmutableMapFieldGenerator::GetNumBitsForMessage() const { return 0; }
int ImmutableMapFieldGenerator::GetNumBitsForBuilder() const { return 1; }
@@ -216,14 +245,16 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
" $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "${$get$capitalized_name$$}$();\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -261,27 +292,29 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$\n"
- "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
+ "$deprecation$$value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue);\n");
+ " $value_type_pass_through_nullness$ defaultValue);\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$\n"
- "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
- " $key_type$ key);\n");
+ printer->Print(
+ variables_,
+ "$deprecation$$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
+ " $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
}
} else {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "java.util.Map<$type_parameters$>\n"
- "${$get$capitalized_name$$}$();\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "java.util.Map<$type_parameters$>\n"
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
@@ -289,17 +322,16 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$\n"
- "$value_type_pass_through_nullness$ "
+ "$deprecation$$value_type_pass_through_nullness$ "
"${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type_pass_through_nullness$ defaultValue);\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$\n"
- "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
- " $key_type$ key);\n");
+ printer->Print(
+ variables_,
+ "$deprecation$$value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
+ " $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
}
}
@@ -319,6 +351,7 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const {
" $value_default_value$);\n"
"}\n");
printer->Print(variables_,
+ "@SuppressWarnings(\"serial\")\n"
"private com.google.protobuf.MapField<\n"
" $type_parameters$> $name$_;\n"
"private com.google.protobuf.MapField<$type_parameters$>\n"
@@ -354,42 +387,45 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const {
void ImmutableMapFieldGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
- printer->Print(variables_,
- "private com.google.protobuf.MapField<\n"
- " $type_parameters$> $name$_;\n"
- "private com.google.protobuf.MapField<$type_parameters$>\n"
- "internalGet$capitalized_name$() {\n"
- " if ($name$_ == null) {\n"
- " return com.google.protobuf.MapField.emptyMapField(\n"
- " $map_field_parameter$);\n"
- " }\n"
- " return $name$_;\n"
- "}\n"
- "private com.google.protobuf.MapField<$type_parameters$>\n"
- "internalGetMutable$capitalized_name$() {\n"
- " $on_changed$;\n"
- " if ($name$_ == null) {\n"
- " $name$_ = com.google.protobuf.MapField.newMapField(\n"
- " $map_field_parameter$);\n"
- " }\n"
- " if (!$name$_.isMutable()) {\n"
- " $name$_ = $name$_.copy();\n"
- " }\n"
- " return $name$_;\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "private com.google.protobuf.MapField<\n"
+ " $type_parameters$> $name$_;\n"
+ "$deprecation$private com.google.protobuf.MapField<$type_parameters$>\n"
+ " internalGet$capitalized_name$() {\n"
+ " if ($name$_ == null) {\n"
+ " return com.google.protobuf.MapField.emptyMapField(\n"
+ " $map_field_parameter$);\n"
+ " }\n"
+ " return $name$_;\n"
+ "}\n"
+ "$deprecation$private com.google.protobuf.MapField<$type_parameters$>\n"
+ " internalGetMutable$capitalized_name$() {\n"
+ " if ($name$_ == null) {\n"
+ " $name$_ = com.google.protobuf.MapField.newMapField(\n"
+ " $map_field_parameter$);\n"
+ " }\n"
+ " if (!$name$_.isMutable()) {\n"
+ " $name$_ = $name$_.copy();\n"
+ " }\n"
+ " $set_has_field_bit_builder$\n"
+ " $on_changed$\n"
+ " return $name$_;\n"
+ "}\n");
GenerateMapGetters(printer);
- printer->Print(variables_,
- "$deprecation$\n"
- "public Builder ${$clear$capitalized_name$$}$() {\n"
- " internalGetMutable$capitalized_name$().getMutableMap()\n"
- " .clear();\n"
- " return this;\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
+ " $clear_has_field_bit_builder$\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .clear();\n"
+ " return this;\n"
+ "}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$\n"
- "public Builder ${$remove$capitalized_name$$}$(\n"
+ "$deprecation$public Builder ${$remove$capitalized_name$$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" internalGetMutable$capitalized_name$().getMutableMap()\n"
@@ -397,19 +433,24 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
- printer->Print(
- variables_,
- "/**\n"
- " * Use alternate mutation accessors instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "${$getMutable$capitalized_name$$}$() {\n"
- " return internalGetAdapted$capitalized_name$Map(\n"
- " internalGetMutable$capitalized_name$().getMutableMap());\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "/**\n"
+ " * Use alternate mutation accessors instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ " ${$getMutable$capitalized_name$$}$() {\n"
+ " $set_has_field_bit_builder$\n"
+ " return internalGetAdapted$capitalized_name$Map(\n"
+ " internalGetMutable$capitalized_name$().getMutableMap());\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public Builder ${$put$capitalized_name$$}$(\n"
@@ -419,9 +460,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $value_null_check$\n"
" internalGetMutable$capitalized_name$().getMutableMap()\n"
" .put(key, $name$ValueConverter.doBackward(value));\n"
+ " $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -430,21 +473,27 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" internalGetAdapted$capitalized_name$Map(\n"
" internalGetMutable$capitalized_name$().getMutableMap())\n"
" .putAll(values);\n"
+ " $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
if (SupportUnknownEnumValue(descriptor_->file())) {
- printer->Print(
- variables_,
- "/**\n"
- " * Use alternate mutation accessors instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "${$getMutable$capitalized_name$Value$}$() {\n"
- " return internalGetMutable$capitalized_name$().getMutableMap();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "/**\n"
+ " * Use alternate mutation accessors instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
+ "${$getMutable$capitalized_name$Value$}$() {\n"
+ " $set_has_field_bit_builder$\n"
+ " return internalGetMutable$capitalized_name$().getMutableMap();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -455,9 +504,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $value_null_check$\n"
" internalGetMutable$capitalized_name$().getMutableMap()\n"
" .put(key, value);\n"
+ " $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -465,95 +516,107 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n"
" internalGetMutable$capitalized_name$().getMutableMap()\n"
" .putAll(values);\n"
+ " $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
} else {
- printer->Print(
- variables_,
- "/**\n"
- " * Use alternate mutation accessors instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$type_parameters$>\n"
- "${$getMutable$capitalized_name$$}$() {\n"
- " return internalGetMutable$capitalized_name$().getMutableMap();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "/**\n"
+ " * Use alternate mutation accessors instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$type_parameters$>\n"
+ " ${$getMutable$capitalized_name$$}$() {\n"
+ " $set_has_field_bit_builder$\n"
+ " return internalGetMutable$capitalized_name$().getMutableMap();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$"
- "public Builder ${$put$capitalized_name$$}$(\n"
+ "$deprecation$public Builder ${$put$capitalized_name$$}$(\n"
" $key_type$ key,\n"
" $value_type$ value) {\n"
" $key_null_check$\n"
" $value_null_check$\n"
" internalGetMutable$capitalized_name$().getMutableMap()\n"
" .put(key, value);\n"
+ " $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$\n"
- "public Builder ${$putAll$capitalized_name$$}$(\n"
- " java.util.Map<$type_parameters$> values) {\n"
- " internalGetMutable$capitalized_name$().getMutableMap()\n"
- " .putAll(values);\n"
- " return this;\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n"
+ " java.util.Map<$type_parameters$> values) {\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .putAll(values);\n"
+ " $set_has_field_bit_builder$\n"
+ " return this;\n"
+ "}\n");
printer->Annotate("{", "}", descriptor_);
}
}
void ImmutableMapFieldGenerator::GenerateMapGetters(
io::Printer* printer) const {
- printer->Print(variables_,
- "$deprecation$\n"
- "public int ${$get$capitalized_name$Count$}$() {\n"
- " return internalGet$capitalized_name$().getMap().size();\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
+ " return internalGet$capitalized_name$().getMap().size();\n"
+ "}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$\n"
"@java.lang.Override\n"
- "public boolean ${$contains$capitalized_name$$}$(\n"
+ "$deprecation$public boolean ${$contains$capitalized_name$$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" return internalGet$capitalized_name$().getMap().containsKey(key);\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Override\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "${$get$capitalized_name$$}$() {\n"
- " return get$capitalized_name$Map();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Override\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "${$get$capitalized_name$$}$() {\n"
+ " return get$capitalized_name$Map();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
- "$deprecation$\n"
- "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "$deprecation$public java.util.Map<$boxed_key_type$, "
+ "$value_enum_type$>\n"
"${$get$capitalized_name$Map$}$() {\n"
" return internalGetAdapted$capitalized_name$Map(\n"
" internalGet$capitalized_name$().getMap());"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"@java.lang.Override\n"
- "$deprecation$\n"
- "public $value_enum_type_pass_through_nullness$ "
+ "$deprecation$public $value_enum_type_pass_through_nullness$ "
"${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_enum_type_pass_through_nullness$ defaultValue) {\n"
@@ -565,12 +628,12 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" : defaultValue;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"@java.lang.Override\n"
- "$deprecation$\n"
- "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n"
+ "$deprecation$public $value_enum_type$ get$capitalized_name$OrThrow(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
@@ -581,6 +644,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" return $name$ValueConverter.doForward(map.get(key));\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
@@ -595,23 +659,22 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(
- variables_,
- "@java.lang.Override\n"
- "$deprecation$\n"
- "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "${$get$capitalized_name$ValueMap$}$() {\n"
- " return internalGet$capitalized_name$().getMap();\n"
- "}\n");
+ printer->Print(variables_,
+ "@java.lang.Override\n"
+ "$deprecation$public java.util.Map<$boxed_key_type$, "
+ "$boxed_value_type$>\n"
+ "${$get$capitalized_name$ValueMap$}$() {\n"
+ " return internalGet$capitalized_name$().getMap();\n"
+ "}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"@java.lang.Override\n"
- "$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
+ "$deprecation$public $value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue) {\n"
+ " $value_type_pass_through_nullness$ defaultValue) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
" internalGet$capitalized_name$().getMap();\n"
@@ -622,8 +685,8 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer->Print(
variables_,
"@java.lang.Override\n"
- "$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
+ "$deprecation$public $value_type$ "
+ "${$get$capitalized_name$ValueOrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
@@ -636,22 +699,23 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer->Annotate("{", "}", descriptor_);
}
} else {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Override\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$type_parameters$> "
- "${$get$capitalized_name$$}$() {\n"
- " return get$capitalized_name$Map();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Override\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$$}$() {\n"
+ " return get$capitalized_name$Map();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
- "$deprecation$\n"
- "public java.util.Map<$type_parameters$> "
+ "$deprecation$public java.util.Map<$type_parameters$> "
"${$get$capitalized_name$Map$}$() {\n"
" return internalGet$capitalized_name$().getMap();\n"
"}\n");
@@ -660,10 +724,10 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer->Print(
variables_,
"@java.lang.Override\n"
- "$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
+ "$deprecation$public $value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue) {\n"
+ " $value_type_pass_through_nullness$ defaultValue) {\n"
" $key_null_check$\n"
" java.util.Map<$type_parameters$> map =\n"
" internalGet$capitalized_name$().getMap();\n"
@@ -671,19 +735,19 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "@java.lang.Override\n"
- "$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
- " $key_type$ key) {\n"
- " $key_null_check$\n"
- " java.util.Map<$type_parameters$> map =\n"
- " internalGet$capitalized_name$().getMap();\n"
- " if (!map.containsKey(key)) {\n"
- " throw new java.lang.IllegalArgumentException();\n"
- " }\n"
- " return map.get(key);\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "@java.lang.Override\n"
+ "$deprecation$public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
+ " $key_type$ key) {\n"
+ " $key_null_check$\n"
+ " java.util.Map<$type_parameters$> map =\n"
+ " internalGet$capitalized_name$().getMap();\n"
+ " if (!map.containsKey(key)) {\n"
+ " throw new java.lang.IllegalArgumentException();\n"
+ " }\n"
+ " return map.get(key);\n"
+ "}\n");
printer->Annotate("{", "}", descriptor_);
}
}
@@ -698,13 +762,13 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$ public val $kt_name$: "
"com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -713,57 +777,57 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers(
" $kt_dsl_builder$.${$get$capitalized_name$Map$}$()\n"
" )\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@JvmName(\"put$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .put(key: $kt_key_type$, value: $kt_value_type$) {\n"
" $kt_dsl_builder$.${$put$capitalized_name$$}$(key, value)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"set$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslMap"
+ "public inline operator fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .set(key: $kt_key_type$, value: $kt_value_type$) {\n"
" put(key, value)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"remove$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .remove(key: $kt_key_type$) {\n"
" $kt_dsl_builder$.${$remove$capitalized_name$$}$(key)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"putAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .putAll(map: kotlin.collections.Map<$kt_key_type$, $kt_value_type$>) "
"{\n"
" $kt_dsl_builder$.${$putAll$capitalized_name$$}$(map)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -782,6 +846,7 @@ void ImmutableMapFieldGenerator::GenerateInitializationCode(
void ImmutableMapFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
+ // No need to clear the has-bit since we clear the bitField ints all at once.
printer->Print(variables_,
"internalGetMutable$capitalized_name$().clear();\n");
}
@@ -790,38 +855,34 @@ void ImmutableMapFieldGenerator::GenerateMergingCode(
io::Printer* printer) const {
printer->Print(variables_,
"internalGetMutable$capitalized_name$().mergeFrom(\n"
- " other.internalGet$capitalized_name$());\n");
+ " other.internalGet$capitalized_name$());\n"
+ "$set_has_field_bit_builder$\n");
}
void ImmutableMapFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
printer->Print(variables_,
- "result.$name$_ = internalGet$capitalized_name$();\n"
- "result.$name$_.makeImmutable();\n");
+ "if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = internalGet$capitalized_name$();\n"
+ " result.$name$_.makeImmutable();\n"
+ "}\n");
}
-void ImmutableMapFieldGenerator::GenerateParsingCode(
+void ImmutableMapFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "if (!$get_mutable_bit_parser$) {\n"
- " $name$_ = com.google.protobuf.MapField.newMapField(\n"
- " $map_field_parameter$);\n"
- " $set_mutable_bit_parser$;\n"
- "}\n");
if (!SupportUnknownEnumValue(descriptor_->file()) &&
GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
"com.google.protobuf.ByteString bytes = input.readBytes();\n"
"com.google.protobuf.MapEntry<$type_parameters$>\n"
- "$name$__ = $default_entry$.getParserForType().parseFrom(bytes);\n");
- printer->Print(
- variables_,
+ "$name$__ = $default_entry$.getParserForType().parseFrom(bytes);\n"
"if ($value_enum_type$.forNumber($name$__.getValue()) == null) {\n"
- " unknownFields.mergeLengthDelimitedField($number$, bytes);\n"
+ " mergeUnknownLengthDelimitedField($number$, bytes);\n"
"} else {\n"
- " $name$_.getMutableMap().put(\n"
+ " internalGetMutable$capitalized_name$().getMutableMap().put(\n"
" $name$__.getKey(), $name$__.getValue());\n"
+ " $set_has_field_bit_builder$\n"
"}\n");
} else {
printer->Print(
@@ -829,16 +890,11 @@ void ImmutableMapFieldGenerator::GenerateParsingCode(
"com.google.protobuf.MapEntry<$type_parameters$>\n"
"$name$__ = input.readMessage(\n"
" $default_entry$.getParserForType(), extensionRegistry);\n"
- "$name$_.getMutableMap().put(\n"
- " $name$__.getKey(), $name$__.getValue());\n");
+ "internalGetMutable$capitalized_name$().getMutableMap().put(\n"
+ " $name$__.getKey(), $name$__.getValue());\n"
+ "$set_has_field_bit_builder$\n");
}
}
-
-void ImmutableMapFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- // Nothing to do here.
-}
-
void ImmutableMapFieldGenerator::GenerateSerializationCode(
io::Printer* printer) const {
printer->Print(variables_,
@@ -891,4 +947,4 @@ TProtoStringType ImmutableMapFieldGenerator::GetBoxedType() const {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.h
index fe0a4819a9..697deff15a 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field.h
@@ -31,7 +31,7 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -46,6 +46,8 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator {
~ImmutableMapFieldGenerator() override;
// implements ImmutableFieldGenerator ---------------------------------------
+ int GetMessageBitIndex() const override;
+ int GetBuilderBitIndex() const override;
int GetNumBitsForMessage() const override;
int GetNumBitsForBuilder() const override;
void GenerateInterfaceMembers(io::Printer* printer) const override;
@@ -55,8 +57,7 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -69,8 +70,11 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator {
private:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ int message_bit_index_;
+ int builder_bit_index_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
ClassNameResolver* name_resolver_;
+ Context* context_;
void GenerateMapGetters(io::Printer* printer) const;
};
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.cc
index 807743afcf..22f4f6daf2 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.cc
@@ -28,18 +28,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <google/protobuf/compiler/java/map_field_lite.h>
+#include "google/protobuf/compiler/java/map_field_lite.h"
#include <cstdint>
+#include <string>
-#include <google/protobuf/io/printer.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/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/io/printer.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -49,16 +50,16 @@ namespace java {
namespace {
const FieldDescriptor* KeyField(const FieldDescriptor* descriptor) {
- GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
+ Y_ABSL_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
const Descriptor* message = descriptor->message_type();
- GOOGLE_CHECK(message->options().map_entry());
+ Y_ABSL_CHECK(message->options().map_entry());
return message->map_key();
}
const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) {
- GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
+ Y_ABSL_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type());
const Descriptor* message = descriptor->message_type();
- GOOGLE_CHECK(message->options().map_entry());
+ Y_ABSL_CHECK(message->options().map_entry());
return message->map_value();
}
@@ -69,8 +70,8 @@ TProtoStringType TypeName(const FieldDescriptor* field,
} else if (GetJavaType(field) == JAVATYPE_ENUM) {
return name_resolver->GetImmutableClassName(field->enum_type());
} else {
- return boxed ? BoxedPrimitiveTypeName(GetJavaType(field))
- : PrimitiveTypeName(GetJavaType(field));
+ return TProtoStringType(boxed ? BoxedPrimitiveTypeName(GetJavaType(field))
+ : PrimitiveTypeName(GetJavaType(field)));
}
}
@@ -81,19 +82,19 @@ TProtoStringType KotlinTypeName(const FieldDescriptor* field,
} else if (GetJavaType(field) == JAVATYPE_ENUM) {
return name_resolver->GetImmutableClassName(field->enum_type());
} else {
- return KotlinTypeName(GetJavaType(field));
+ return TProtoStringType(KotlinTypeName(GetJavaType(field)));
}
}
TProtoStringType WireType(const FieldDescriptor* field) {
- return "com.google.protobuf.WireFormat.FieldType." +
- TProtoStringType(FieldTypeName(field->type()));
+ return y_absl::StrCat("com.google.protobuf.WireFormat.FieldType.",
+ FieldTypeName(field->type()));
}
-void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
- int builderBitIndex, const FieldGeneratorInfo* info,
- Context* context,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetMessageVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, Context* context,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
ClassNameResolver* name_resolver = context->GetNameResolver();
@@ -104,14 +105,18 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const JavaType keyJavaType = GetJavaType(key);
const JavaType valueJavaType = GetJavaType(value);
- TProtoStringType pass_through_nullness = "/* nullable */\n";
+ TProtoStringType pass_through_nullness =
+ context->options().opensource_runtime
+ ? "/* nullable */\n"
+ : "@com.google.protobuf.Internal.ProtoPassThroughNullness ";
(*variables)["key_type"] = TypeName(key, name_resolver, false);
(*variables)["boxed_key_type"] = TypeName(key, name_resolver, true);
(*variables)["kt_key_type"] = KotlinTypeName(key, name_resolver);
(*variables)["kt_value_type"] = KotlinTypeName(value, name_resolver);
(*variables)["key_wire_type"] = WireType(key);
- (*variables)["key_default_value"] = DefaultValue(key, true, name_resolver);
+ (*variables)["key_default_value"] =
+ DefaultValue(key, true, name_resolver, context->options());
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
(*variables)["key_null_check"] =
@@ -126,51 +131,63 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
if (GetJavaType(value) == JAVATYPE_ENUM) {
// We store enums as Integers internally.
(*variables)["value_type"] = "int";
+ (*variables)["value_type_pass_through_nullness"] = "int";
(*variables)["boxed_value_type"] = "java.lang.Integer";
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
- DefaultValue(value, true, name_resolver) + ".getNumber()";
+ DefaultValue(value, true, name_resolver, context->options()) +
+ ".getNumber()";
(*variables)["value_enum_type"] = TypeName(value, name_resolver, false);
- (*variables)["value_enum_type_pass_through_nullness"] =
- pass_through_nullness + (*variables)["value_enum_type"];
+ variables->insert(
+ {"value_enum_type_pass_through_nullness",
+ y_absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"])});
if (SupportUnknownEnumValue(descriptor->file())) {
// Map unknown values to a special UNRECOGNIZED value if supported.
- (*variables)["unrecognized_value"] =
- (*variables)["value_enum_type"] + ".UNRECOGNIZED";
+ variables->insert(
+ {"unrecognized_value",
+ y_absl::StrCat((*variables)["value_enum_type"], ".UNRECOGNIZED")});
} else {
// Map unknown values to the default value if we don't have UNRECOGNIZED.
(*variables)["unrecognized_value"] =
- DefaultValue(value, true, name_resolver);
+ DefaultValue(value, true, name_resolver, context->options());
}
} else {
(*variables)["value_type"] = TypeName(value, name_resolver, false);
- (*variables)["value_type_pass_through_nullness"] =
- (IsReferenceType(valueJavaType) ? pass_through_nullness : "") +
- (*variables)["value_type"];
+ variables->insert(
+ {"value_type_pass_through_nullness",
+ y_absl::StrCat(
+ (IsReferenceType(valueJavaType) ? pass_through_nullness : ""),
+ (*variables)["value_type"])});
(*variables)["boxed_value_type"] = TypeName(value, name_resolver, true);
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
- DefaultValue(value, true, name_resolver);
+ DefaultValue(value, true, name_resolver, context->options());
}
- (*variables)["type_parameters"] =
- (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"];
+ variables->insert(
+ {"type_parameters", y_absl::StrCat((*variables)["boxed_key_type"], ", ",
+ (*variables)["boxed_value_type"])});
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
-
- (*variables)["default_entry"] =
- (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry";
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
+
+ variables->insert(
+ {"default_entry", y_absl::StrCat((*variables)["capitalized_name"],
+ "DefaultEntryHolder.defaultEntry")});
+ // { and } variables are used as delimiters when emitting annotations.
+ (*variables)["{"] = "";
+ (*variables)["}"] = "";
}
} // namespace
@@ -201,14 +218,16 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
" $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "${$get$capitalized_name$$}$();\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -247,9 +266,10 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$\n"
- "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
+ "$value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue);\n");
+ " $value_type_pass_through_nullness$ defaultValue);\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@@ -259,14 +279,16 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "java.util.Map<$type_parameters$>\n"
- "${$get$capitalized_name$$}$();\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "java.util.Map<$type_parameters$>\n"
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
@@ -303,6 +325,12 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" $value_wire_type$,\n"
" $value_default_value$);\n"
"}\n");
+ if (!context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "@com.google.protobuf.ProtoField(\n"
+ " fieldNumber=$number$,\n"
+ " type=com.google.protobuf.FieldType.MAP)\n");
+ }
printer->Print(variables_,
"private com.google.protobuf.MapFieldLite<\n"
" $type_parameters$> $name$_ =\n"
@@ -344,16 +372,19 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n"
" $value_enum_type$.internalGetValueMap(),\n"
" $unrecognized_value$);\n");
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "${$get$capitalized_name$$}$() {\n"
- " return get$capitalized_name$Map();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "${$get$capitalized_name$$}$() {\n"
+ " return get$capitalized_name$Map();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -373,9 +404,10 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$\n"
- "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n"
+ "public $value_enum_type_pass_through_nullness$ "
+ "${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_enum_type$ defaultValue) {\n"
+ " $value_enum_type_pass_through_nullness$ defaultValue) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
" internalGet$capitalized_name$();\n"
@@ -429,9 +461,10 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
+ "public $value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue) {\n"
+ " $value_type_pass_through_nullness$ defaultValue) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
" internalGet$capitalized_name$();\n"
@@ -456,17 +489,19 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Override\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$type_parameters$> "
- "${$get$capitalized_name$$}$() {\n"
- " return get$capitalized_name$Map();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Override\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$$}$() {\n"
+ " return get$capitalized_name$Map();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -482,9 +517,10 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
+ "public $value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue) {\n"
+ " $value_type_pass_through_nullness$ defaultValue) {\n"
" $key_null_check$\n"
" java.util.Map<$type_parameters$> map =\n"
" internalGet$capitalized_name$();\n"
@@ -596,16 +632,19 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "${$get$capitalized_name$$}$() {\n"
- " return get$capitalized_name$Map();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "${$get$capitalized_name$$}$() {\n"
+ " return get$capitalized_name$Map();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -701,9 +740,10 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
+ "public $value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue) {\n"
+ " $value_type_pass_through_nullness$ defaultValue) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
" instance.get$capitalized_name$ValueMap();\n"
@@ -750,17 +790,19 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
- printer->Print(variables_,
- "/**\n"
- " * Use {@link #get$capitalized_name$Map()} instead.\n"
- " */\n"
- "@java.lang.Override\n"
- "@java.lang.Deprecated\n"
- "public java.util.Map<$type_parameters$> "
- "${$get$capitalized_name$$}$() {\n"
- " return get$capitalized_name$Map();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
+ if (context_->options().opensource_runtime) {
+ printer->Print(variables_,
+ "/**\n"
+ " * Use {@link #get$capitalized_name$Map()} instead.\n"
+ " */\n"
+ "@java.lang.Override\n"
+ "@java.lang.Deprecated\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$$}$() {\n"
+ " return get$capitalized_name$Map();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -776,9 +818,10 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$\n"
- "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
+ "public $value_type_pass_through_nullness$ "
+ "${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
- " $value_type$ defaultValue) {\n"
+ " $value_type_pass_through_nullness$ defaultValue) {\n"
" $key_null_check$\n"
" java.util.Map<$type_parameters$> map =\n"
" instance.get$capitalized_name$Map();\n"
@@ -838,13 +881,13 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$ public val $kt_name$: "
"com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -853,57 +896,57 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers(
" $kt_dsl_builder$.${$get$capitalized_name$Map$}$()\n"
" )\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@JvmName(\"put$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .put(key: $kt_key_type$, value: $kt_value_type$) {\n"
" $kt_dsl_builder$.${$put$capitalized_name$$}$(key, value)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"set$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslMap"
+ "public inline operator fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .set(key: $kt_key_type$, value: $kt_value_type$) {\n"
" put(key, value)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"remove$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .remove(key: $kt_key_type$) {\n"
" $kt_dsl_builder$.${$remove$capitalized_name$$}$(key)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"putAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .putAll(map: kotlin.collections.Map<$kt_key_type$, $kt_value_type$>) "
"{\n"
" $kt_dsl_builder$.${$putAll$capitalized_name$$}$(map)\n"
" }\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslMap"
+ "public fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -924,4 +967,4 @@ TProtoStringType ImmutableMapFieldLiteGenerator::GetBoxedType() const {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.h
index de2cc51057..4f5fb4d4ac 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/map_field_lite.h
@@ -33,7 +33,7 @@
#include <cstdint>
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -61,7 +61,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator {
private:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
Context* context_;
ClassNameResolver* name_resolver_;
};
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/message.cc
index bcd437821f..e3a5e5e03d 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message.cc
@@ -32,32 +32,34 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/message.h>
+#include "google/protobuf/compiler/java/message.h"
#include <algorithm>
#include <cstdint>
-#include <map>
#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/context.h>
-#include <google/protobuf/compiler/java/doc_comment.h>
-#include <google/protobuf/compiler/java/enum.h>
-#include <google/protobuf/compiler/java/extension.h>
-#include <google/protobuf/compiler/java/generator_factory.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/message_builder.h>
-#include <google/protobuf/compiler/java/message_builder_lite.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/strings/ascii.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/substitute.h"
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/doc_comment.h"
+#include "google/protobuf/compiler/java/enum.h"
+#include "google/protobuf/compiler/java/extension.h"
+#include "google/protobuf/compiler/java/generator_factory.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/message_builder.h"
+#include "google/protobuf/compiler/java/message_builder_lite.h"
+#include "google/protobuf/compiler/java/message_serialization.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/descriptor.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"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -71,7 +73,7 @@ namespace {
TProtoStringType MapValueImmutableClassdName(const Descriptor* descriptor,
ClassNameResolver* name_resolver) {
const FieldDescriptor* value_field = descriptor->map_value();
- GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type());
+ Y_ABSL_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type());
return name_resolver->GetImmutableClassName(value_field->message_type());
}
} // namespace
@@ -82,7 +84,8 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor)
: descriptor_(descriptor) {
for (int i = 0; i < descriptor_->field_count(); i++) {
if (IsRealOneof(descriptor_->field(i))) {
- oneofs_.insert(descriptor_->field(i)->containing_oneof());
+ const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof();
+ Y_ABSL_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof);
}
}
}
@@ -96,7 +99,7 @@ ImmutableMessageGenerator::ImmutableMessageGenerator(
context_(context),
name_resolver_(context->GetNameResolver()),
field_generators_(descriptor, context_) {
- GOOGLE_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
+ Y_ABSL_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
<< "Generator factory error: A non-lite message generator is used to "
"generate lite messages.";
}
@@ -112,9 +115,9 @@ void ImmutableMessageGenerator::GenerateStaticVariables(
// the outermost class in the file. This way, they will be initialized in
// a deterministic order.
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
- vars["index"] = StrCat(descriptor_->index());
+ vars["index"] = y_absl::StrCat(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
if (descriptor_->containing_type() != NULL) {
vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type());
@@ -156,9 +159,9 @@ void ImmutableMessageGenerator::GenerateStaticVariables(
int ImmutableMessageGenerator::GenerateStaticVariableInitializers(
io::Printer* printer) {
int bytecode_estimate = 0;
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
- vars["index"] = StrCat(descriptor_->index());
+ vars["index"] = y_absl::StrCat(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
if (descriptor_->containing_type() != NULL) {
vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type());
@@ -193,7 +196,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers(
void ImmutableMessageGenerator::GenerateFieldAccessorTable(
io::Printer* printer, int* bytecode_estimate) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) {
// We can only make these package-private since the classes that use them
@@ -260,6 +263,9 @@ int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer(
void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true, "OrBuilder");
+ if (!context_->options().opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
+ }
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
@@ -289,13 +295,14 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
field_generators_.get(descriptor_->field(i))
.GenerateInterfaceMembers(printer);
}
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
printer->Print(
"\n"
- "public $classname$.$oneof_capitalized_name$Case "
+ "$classname$.$oneof_capitalized_name$Case "
"get$oneof_capitalized_name$Case();\n",
"oneof_capitalized_name",
- context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname",
+ context_->GetOneofGeneratorInfo(kv.second)->capitalized_name,
+ "classname",
context_->GetNameResolver()->GetImmutableClassName(descriptor_));
}
printer->Outdent();
@@ -308,7 +315,7 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
void ImmutableMessageGenerator::Generate(io::Printer* printer) {
bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
- std::map<TProtoStringType, TProtoStringType> variables;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables;
variables["static"] = is_own_file ? "" : "static ";
variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
@@ -319,6 +326,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true);
+ if (!context_->options().opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
+ }
+
// The builder_type stores the super type name of the nested Builder class.
TProtoStringType builder_type;
if (descriptor_->extension_range_count() > 0) {
@@ -332,7 +343,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
" $classname$> implements\n"
" $extra_interfaces$\n"
" $classname$OrBuilder {\n");
- builder_type = strings::Substitute(
+ builder_type = y_absl::Substitute(
"com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>",
name_resolver_->GetImmutableClassName(descriptor_),
GeneratedCodeVersionSuffix());
@@ -346,7 +357,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
" $extra_interfaces$\n"
" $classname$OrBuilder {\n");
builder_type =
- strings::Substitute("com.google.protobuf.GeneratedMessage$0.Builder<?>",
+ y_absl::Substitute("com.google.protobuf.GeneratedMessage$0.Builder<?>",
GeneratedCodeVersionSuffix());
}
printer->Print("private static final long serialVersionUID = 0L;\n");
@@ -379,17 +390,6 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"}\n"
"\n");
- printer->Print(
- "@java.lang.Override\n"
- "public final com.google.protobuf.UnknownFieldSet\n"
- "getUnknownFields() {\n"
- " return this.unknownFields;\n"
- "}\n");
-
- if (context_->HasGeneratedMethods(descriptor_)) {
- GenerateParsingConstructor(printer);
- }
-
GenerateDescriptorMethods(printer);
// Nested types
@@ -419,59 +419,69 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
}
// oneof
- std::map<TProtoStringType, TProtoStringType> vars;
- for (auto oneof : oneofs_) {
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
- vars["oneof_index"] = StrCat((oneof)->index());
+ vars["oneof_index"] = y_absl::StrCat((oneof)->index());
+ vars["{"] = "";
+ vars["}"] = "";
// oneofCase_ and oneof_
printer->Print(vars,
"private int $oneof_name$Case_ = 0;\n"
+ "@SuppressWarnings(\"serial\")\n"
"private java.lang.Object $oneof_name$_;\n");
// OneofCase enum
printer->Print(
vars,
- "public enum $oneof_capitalized_name$Case\n"
+ "public enum ${$$oneof_capitalized_name$Case$}$\n"
// TODO(dweis): Remove EnumLite when we want to break compatibility with
// 3.x users
" implements com.google.protobuf.Internal.EnumLite,\n"
" com.google.protobuf.AbstractMessage.InternalOneOfEnum {\n");
+ printer->Annotate("{", "}", oneof);
printer->Indent();
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print(
"$deprecation$$field_name$($field_number$),\n", "deprecation",
field->options().deprecated() ? "@java.lang.Deprecated " : "",
- "field_name", ToUpper(field->name()), "field_number",
- StrCat(field->number()));
+ "field_name", y_absl::AsciiStrToUpper(field->name()), "field_number",
+ y_absl::StrCat(field->number()));
+ printer->Annotate("field_name", field);
}
printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name",
- ToUpper(vars["oneof_name"]));
+ y_absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Print(vars,
"private final int value;\n"
"private $oneof_capitalized_name$Case(int value) {\n"
" this.value = value;\n"
"}\n");
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ vars,
+ "/**\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 $oneof_capitalized_name$Case valueOf(int value) {\n"
+ " return forNumber(value);\n"
+ "}\n"
+ "\n");
+ }
printer->Print(
vars,
- "/**\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 $oneof_capitalized_name$Case valueOf(int value) {\n"
- " return forNumber(value);\n"
- "}\n"
- "\n"
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n");
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print(" case $field_number$: return $field_name$;\n",
- "field_number", StrCat(field->number()),
- "field_name", ToUpper(field->name()));
+ "field_number", y_absl::StrCat(field->number()),
+ "field_name", y_absl::AsciiStrToUpper(field->name()));
}
printer->Print(
" case 0: return $cap_oneof_name$_NOT_SET;\n"
@@ -481,17 +491,18 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"public int getNumber() {\n"
" return this.value;\n"
"}\n",
- "cap_oneof_name", ToUpper(vars["oneof_name"]));
+ "cap_oneof_name", y_absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Outdent();
printer->Print("};\n\n");
// oneofCase()
printer->Print(vars,
"public $oneof_capitalized_name$Case\n"
- "get$oneof_capitalized_name$Case() {\n"
+ "${$get$oneof_capitalized_name$Case$}$() {\n"
" return $oneof_capitalized_name$Case.forNumber(\n"
" $oneof_name$Case_);\n"
"}\n"
"\n");
+ printer->Annotate("{", "}", oneof);
}
if (IsAnyMessage(descriptor_)) {
@@ -502,7 +513,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->field_count(); i++) {
printer->Print("public static final int $constant_name$ = $number$;\n",
"constant_name", FieldConstantName(descriptor_->field(i)),
- "number", StrCat(descriptor_->field(i)->number()));
+ "number", y_absl::StrCat(descriptor_->field(i)->number()));
printer->Annotate("constant_name", descriptor_->field(i));
field_generators_.get(descriptor_->field(i)).GenerateMembers(printer);
printer->Print("\n");
@@ -582,13 +593,6 @@ void ImmutableMessageGenerator::GenerateMessageSerializationMethods(
std::unique_ptr<const FieldDescriptor*[]> sorted_fields(
SortFieldsByNumber(descriptor_));
- std::vector<const Descriptor::ExtensionRange*> sorted_extensions;
- sorted_extensions.reserve(descriptor_->extension_range_count());
- for (int i = 0; i < descriptor_->extension_range_count(); ++i) {
- sorted_extensions.push_back(descriptor_->extension_range(i));
- }
- std::sort(sorted_extensions.begin(), sorted_extensions.end(),
- ExtensionRangeOrdering());
printer->Print(
"@java.lang.Override\n"
"public void writeTo(com.google.protobuf.CodedOutputStream output)\n"
@@ -623,24 +627,13 @@ void ImmutableMessageGenerator::GenerateMessageSerializationMethods(
}
}
- // Merge the fields and the extension ranges, both sorted by field number.
- for (int i = 0, j = 0;
- i < descriptor_->field_count() || j < sorted_extensions.size();) {
- if (i == descriptor_->field_count()) {
- GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]);
- } else if (j == sorted_extensions.size()) {
- GenerateSerializeOneField(printer, sorted_fields[i++]);
- } else if (sorted_fields[i]->number() < sorted_extensions[j]->start) {
- GenerateSerializeOneField(printer, sorted_fields[i++]);
- } else {
- GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]);
- }
- }
+ GenerateSerializeFieldsAndExtensions(printer, field_generators_, descriptor_,
+ sorted_fields.get());
if (descriptor_->options().message_set_wire_format()) {
- printer->Print("unknownFields.writeAsMessageSetTo(output);\n");
+ printer->Print("getUnknownFields().writeAsMessageSetTo(output);\n");
} else {
- printer->Print("unknownFields.writeTo(output);\n");
+ printer->Print("getUnknownFields().writeTo(output);\n");
}
printer->Outdent();
@@ -669,9 +662,10 @@ void ImmutableMessageGenerator::GenerateMessageSerializationMethods(
}
if (descriptor_->options().message_set_wire_format()) {
- printer->Print("size += unknownFields.getSerializedSizeAsMessageSet();\n");
+ printer->Print(
+ "size += getUnknownFields().getSerializedSizeAsMessageSet();\n");
} else {
- printer->Print("size += unknownFields.getSerializedSize();\n");
+ printer->Print("size += getUnknownFields().getSerializedSize();\n");
}
printer->Print(
@@ -765,17 +759,6 @@ void ImmutableMessageGenerator::GenerateParseFromMethods(io::Printer* printer) {
GeneratedCodeVersionSuffix());
}
-void ImmutableMessageGenerator::GenerateSerializeOneField(
- io::Printer* printer, const FieldDescriptor* field) {
- field_generators_.get(field).GenerateSerializationCode(printer);
-}
-
-void ImmutableMessageGenerator::GenerateSerializeOneExtensionRange(
- io::Printer* printer, const Descriptor::ExtensionRange* range) {
- printer->Print("extensionWriter.writeUntil($end$, output);\n", "end",
- StrCat(range->end));
-}
-
// ===================================================================
void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) {
@@ -847,7 +830,7 @@ void ImmutableMessageGenerator::GenerateDescriptorMethods(
printer->Print(
"case $number$:\n"
" return internalGet$capitalized_name$();\n",
- "number", StrCat(field->number()), "capitalized_name",
+ "number", y_absl::StrCat(field->number()), "capitalized_name",
info->capitalized_name);
}
printer->Print(
@@ -1005,6 +988,10 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
printer->Print(
"@java.lang.Override\n"
"public boolean equals(");
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ "@com.google.protobuf.Internal.ProtoMethodAcceptsNullParameter\n");
+ }
printer->Print("final java.lang.Object obj) {\n");
printer->Indent();
printer->Print(
@@ -1012,6 +999,8 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
" return true;\n"
"}\n"
"if (!(obj instanceof $classname$)) {\n"
+ // don't simply return false because mutable and immutable types
+ // can be equal
" return super.equals(obj);\n"
"}\n"
"$classname$ other = ($classname$) obj;\n"
@@ -1039,7 +1028,8 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
}
// Compare oneofs.
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
printer->Print(
"if (!get$oneof_capitalized_name$Case().equals("
"other.get$oneof_capitalized_name$Case())) return false;\n",
@@ -1051,7 +1041,7 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print("case $field_number$:\n", "field_number",
- StrCat(field->number()));
+ y_absl::StrCat(field->number()));
printer->Indent();
field_generators_.get(field).GenerateEqualsCode(printer);
printer->Print("break;\n");
@@ -1068,7 +1058,8 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
// false for non-canonical ordering when running in LITE_RUNTIME but it's
// the best we can do.
printer->Print(
- "if (!unknownFields.equals(other.unknownFields)) return false;\n");
+ "if (!getUnknownFields().equals(other.getUnknownFields())) return "
+ "false;\n");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"if (!getExtensionFields().equals(other.getExtensionFields()))\n"
@@ -1118,14 +1109,15 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
}
// hashCode oneofs.
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
printer->Print("switch ($oneof_name$Case_) {\n", "oneof_name",
context_->GetOneofGeneratorInfo(oneof)->name);
printer->Indent();
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print("case $field_number$:\n", "field_number",
- StrCat(field->number()));
+ y_absl::StrCat(field->number()));
printer->Indent();
field_generators_.get(field).GenerateHashCode(printer);
printer->Print("break;\n");
@@ -1142,7 +1134,7 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
printer->Print("hash = hashFields(hash, getExtensionFields());\n");
}
- printer->Print("hash = (29 * hash) + unknownFields.hashCode();\n");
+ printer->Print("hash = (29 * hash) + getUnknownFields().hashCode();\n");
printer->Print(
"memoizedHashCode = hash;\n"
"return hash;\n");
@@ -1168,188 +1160,32 @@ void ImmutableMessageGenerator::GenerateExtensionRegistrationCode(
}
// ===================================================================
-void ImmutableMessageGenerator::GenerateParsingConstructor(
- io::Printer* printer) {
- std::unique_ptr<const FieldDescriptor*[]> sorted_fields(
- SortFieldsByNumber(descriptor_));
-
- printer->Print(
- "private $classname$(\n"
- " com.google.protobuf.CodedInputStream input,\n"
- " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
- " throws com.google.protobuf.InvalidProtocolBufferException {\n",
- "classname", descriptor_->name());
- printer->Indent();
-
- // Initialize all fields to default.
- printer->Print(
- "this();\n"
- "if (extensionRegistry == null) {\n"
- " throw new java.lang.NullPointerException();\n"
- "}\n");
-
- // Use builder bits to track mutable repeated fields.
- int totalBuilderBits = 0;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const ImmutableFieldGenerator& field =
- field_generators_.get(descriptor_->field(i));
- totalBuilderBits += field.GetNumBitsForBuilder();
- }
- int totalBuilderInts = (totalBuilderBits + 31) / 32;
- for (int i = 0; i < totalBuilderInts; i++) {
- printer->Print("int mutable_$bit_field_name$ = 0;\n", "bit_field_name",
- GetBitFieldName(i));
- }
-
- printer->Print(
- "com.google.protobuf.UnknownFieldSet.Builder unknownFields =\n"
- " com.google.protobuf.UnknownFieldSet.newBuilder();\n");
-
- printer->Print("try {\n");
- printer->Indent();
-
- printer->Print(
- "boolean done = false;\n"
- "while (!done) {\n");
- printer->Indent();
-
- printer->Print(
- "int tag = input.readTag();\n"
- "switch (tag) {\n");
- printer->Indent();
-
- printer->Print(
- "case 0:\n" // zero signals EOF / limit reached
- " done = true;\n"
- " break;\n");
-
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = sorted_fields[i];
- arc_ui32 tag = WireFormatLite::MakeTag(
- field->number(), WireFormat::WireTypeForFieldType(field->type()));
-
- printer->Print("case $tag$: {\n", "tag",
- StrCat(static_cast<arc_i32>(tag)));
- printer->Indent();
-
- field_generators_.get(field).GenerateParsingCode(printer);
-
- printer->Outdent();
- printer->Print(
- " break;\n"
- "}\n");
-
- if (field->is_packable()) {
- // To make packed = true wire compatible, we generate parsing code from a
- // packed version of this field regardless of field->options().packed().
- arc_ui32 packed_tag = WireFormatLite::MakeTag(
- field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
- printer->Print("case $tag$: {\n", "tag",
- StrCat(static_cast<arc_i32>(packed_tag)));
- printer->Indent();
-
- field_generators_.get(field).GenerateParsingCodeFromPacked(printer);
-
- printer->Outdent();
- printer->Print(
- " break;\n"
- "}\n");
- }
- }
-
- printer->Print(
- "default: {\n"
- " if (!parseUnknownField(\n"
- " input, unknownFields, extensionRegistry, tag)) {\n"
- " done = true;\n" // it's an endgroup tag
- " }\n"
- " break;\n"
- "}\n");
-
- printer->Outdent();
- printer->Outdent();
- printer->Print(
- " }\n" // switch (tag)
- "}\n"); // while (!done)
-
- printer->Outdent();
- 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"
- "} finally {\n");
- printer->Indent();
-
- // Make repeated field list immutable.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = sorted_fields[i];
- field_generators_.get(field).GenerateParsingDoneCode(printer);
- }
-
- // Make unknown fields immutable.
- printer->Print("this.unknownFields = unknownFields.build();\n");
-
- // Make extensions immutable.
- printer->Print("makeExtensionsImmutable();\n");
-
- printer->Outdent();
- printer->Outdent();
- printer->Print(
- " }\n" // finally
- "}\n");
-}
-
-// ===================================================================
void ImmutableMessageGenerator::GenerateParser(io::Printer* printer) {
printer->Print(
"$visibility$ static final com.google.protobuf.Parser<$classname$>\n"
- " PARSER = new com.google.protobuf.AbstractParser<$classname$>() {\n",
- "visibility",
- ExposePublicParser(descriptor_->file()) ? "@java.lang.Deprecated public"
- : "private",
- "classname", descriptor_->name());
- printer->Indent();
- printer->Print(
- "@java.lang.Override\n"
- "public $classname$ parsePartialFrom(\n"
- " com.google.protobuf.CodedInputStream input,\n"
- " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
- " throws com.google.protobuf.InvalidProtocolBufferException {\n",
- "classname", descriptor_->name());
- if (context_->HasGeneratedMethods(descriptor_)) {
- printer->Print(" return new $classname$(input, extensionRegistry);\n",
- "classname", descriptor_->name());
- } else {
- // When parsing constructor isn't generated, use builder to parse
- // messages. Note, will fallback to use reflection based mergeFieldFrom()
- // in AbstractMessage.Builder.
- printer->Indent();
- printer->Print(
- "Builder builder = newBuilder();\n"
- "try {\n"
- " builder.mergeFrom(input, extensionRegistry);\n"
- "} catch (com.google.protobuf.InvalidProtocolBufferException e) {\n"
- " throw e.setUnfinishedMessage(builder.buildPartial());\n"
- "} catch (java.io.IOException e) {\n"
- " throw new com.google.protobuf.InvalidProtocolBufferException(\n"
- " e.getMessage()).setUnfinishedMessage(\n"
- " builder.buildPartial());\n"
- "}\n"
- "return builder.buildPartial();\n");
- printer->Outdent();
- }
- printer->Print("}\n");
- printer->Outdent();
- printer->Print(
+ " PARSER = new com.google.protobuf.AbstractParser<$classname$>() {\n"
+ " @java.lang.Override\n"
+ " public $classname$ parsePartialFrom(\n"
+ " com.google.protobuf.CodedInputStream input,\n"
+ " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
+ " throws com.google.protobuf.InvalidProtocolBufferException {\n"
+ " Builder builder = newBuilder();\n"
+ " try {\n"
+ " builder.mergeFrom(input, extensionRegistry);\n"
+ " } catch (com.google.protobuf.InvalidProtocolBufferException e) {\n"
+ " throw e.setUnfinishedMessage(builder.buildPartial());\n"
+ " } catch (com.google.protobuf.UninitializedMessageException e) {\n"
+ " throw "
+ "e.asInvalidProtocolBufferException().setUnfinishedMessage(builder."
+ "buildPartial());\n"
+ " } catch (java.io.IOException e) {\n"
+ " throw new com.google.protobuf.InvalidProtocolBufferException(e)\n"
+ " .setUnfinishedMessage(builder.buildPartial());\n"
+ " }\n"
+ " return builder.buildPartial();\n"
+ " }\n"
"};\n"
- "\n");
-
- printer->Print(
+ "\n"
"public static com.google.protobuf.Parser<$classname$> parser() {\n"
" return PARSER;\n"
"}\n"
@@ -1359,6 +1195,9 @@ void ImmutableMessageGenerator::GenerateParser(io::Printer* printer) {
" return PARSER;\n"
"}\n"
"\n",
+ "visibility",
+ ExposePublicParser(descriptor_->file()) ? "@java.lang.Deprecated public"
+ : "private",
"classname", descriptor_->name());
}
@@ -1413,10 +1252,10 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const {
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
"@com.google.protobuf.kotlin.ProtoDslMarker\n");
printer->Print(
- "class Dsl private constructor(\n"
+ "public class Dsl private constructor(\n"
" private val _builder: $message$.Builder\n"
") {\n"
- " companion object {\n"
+ " public companion object {\n"
" @kotlin.jvm.JvmSynthetic\n"
" @kotlin.PublishedApi\n"
" internal fun _create(builder: $message$.Builder): Dsl = "
@@ -1426,7 +1265,8 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const {
" @kotlin.jvm.JvmSynthetic\n"
" @kotlin.PublishedApi\n"
" internal fun _build(): $message$ = _builder.build()\n",
- "message", name_resolver_->GetClassName(descriptor_, true));
+ "message",
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)));
printer->Indent();
@@ -1436,18 +1276,19 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const {
.GenerateKotlinDslMembers(printer);
}
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
printer->Print(
- "val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n"
+ "public val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n"
" @JvmName(\"get$oneof_capitalized_name$Case\")\n"
" get() = _builder.get$oneof_capitalized_name$Case()\n\n"
- "fun clear$oneof_capitalized_name$() {\n"
+ "public fun clear$oneof_capitalized_name$() {\n"
" _builder.clear$oneof_capitalized_name$()\n"
"}\n",
"oneof_name", context_->GetOneofGeneratorInfo(oneof)->name,
"oneof_capitalized_name",
context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "message",
- name_resolver_->GetClassName(descriptor_, true));
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)));
}
if (descriptor_->extension_range_count() > 0) {
@@ -1460,19 +1301,27 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const {
void ImmutableMessageGenerator::GenerateKotlinMembers(
io::Printer* printer) const {
+ printer->Print("@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n",
+ "camelcase_name",
+ name_resolver_->GetKotlinFactoryName(descriptor_));
+
+
printer->Print(
- "@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n"
- "inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
+ "public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): "
"$message$ "
"=\n"
" $message_kt$.Dsl._create($message$.newBuilder()).apply { block() "
"}._build()\n",
"camelcase_name", name_resolver_->GetKotlinFactoryName(descriptor_),
- "message_kt", name_resolver_->GetKotlinExtensionsClassName(descriptor_),
- "message", name_resolver_->GetClassName(descriptor_, true));
-
- printer->Print("object $name$Kt {\n", "name", descriptor_->name());
+ "message_kt",
+ EscapeKotlinKeywords(
+ name_resolver_->GetKotlinExtensionsClassName(descriptor_)),
+ "message",
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)));
+
+ WriteMessageDocComment(printer, descriptor_, /* kdoc */ true);
+ printer->Print("public object $name$Kt {\n", "name", descriptor_->name());
printer->Indent();
GenerateKotlinDsl(printer);
for (int i = 0; i < descriptor_->nested_type_count(); i++) {
@@ -1486,15 +1335,19 @@ void ImmutableMessageGenerator::GenerateKotlinMembers(
void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers(
io::Printer* printer) const {
+ printer->Print("@kotlin.jvm.JvmSynthetic\n");
+
+
printer->Print(
- "@kotlin.jvm.JvmSynthetic\n"
- "inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
- "kotlin.Unit): "
- "$message$ =\n"
+ "public inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
+ "kotlin.Unit): $message$ =\n"
" $message_kt$.Dsl._create(this.toBuilder()).apply { block() "
"}._build()\n\n",
- "message", name_resolver_->GetClassName(descriptor_, true), "message_kt",
- name_resolver_->GetKotlinExtensionsClassName(descriptor_));
+ "message",
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)),
+ "message_kt",
+ EscapeKotlinKeywords(
+ name_resolver_->GetKotlinExtensionsClassName(descriptor_)));
for (int i = 0; i < descriptor_->nested_type_count(); i++) {
if (IsMapEntry(descriptor_->nested_type(i))) continue;
@@ -1505,34 +1358,39 @@ void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers(
GenerateKotlinOrNull(printer);
}
-void ImmutableMessageGenerator::GenerateKotlinOrNull(io::Printer* printer) const {
+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"
+ "public 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),
+ "full_classname",
+ EscapeKotlinKeywords(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);
+ EscapeKotlinKeywords(
+ name_resolver_->GetImmutableClassName(field->message_type())),
+ "name", context_->GetFieldGeneratorInfo(field)->capitalized_name);
}
}
}
void ImmutableMessageGenerator::GenerateKotlinExtensions(
io::Printer* printer) const {
- TProtoStringType message_name = name_resolver_->GetClassName(descriptor_, true);
+ TProtoStringType message_name =
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true));
printer->Print(
"@Suppress(\"UNCHECKED_CAST\")\n"
"@kotlin.jvm.JvmSynthetic\n"
- "operator fun <T : kotlin.Any> 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$, "
- "List<*>>) as T\n"
+ "kotlin.collections.List<*>>) as T\n"
" } else {\n"
" _builder.getExtension(extension)\n"
" }\n"
@@ -1544,8 +1402,9 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
"@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n"
- "operator fun <E : kotlin.Any> get(\n"
- " extension: com.google.protobuf.ExtensionLite<$message$, List<E>>\n"
+ "public operator fun <E : kotlin.Any> get(\n"
+ " extension: com.google.protobuf.ExtensionLite<$message$, "
+ "kotlin.collections.List<E>>\n"
"): com.google.protobuf.kotlin.ExtensionList<E, $message$> {\n"
" return com.google.protobuf.kotlin.ExtensionList(extension, "
"_builder.getExtension(extension))\n"
@@ -1554,7 +1413,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "operator fun contains(extension: "
+ "public operator fun contains(extension: "
"com.google.protobuf.ExtensionLite<$message$, *>): "
"Boolean {\n"
" return _builder.hasExtension(extension)\n"
@@ -1563,7 +1422,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "fun clear(extension: "
+ "public fun clear(extension: "
"com.google.protobuf.ExtensionLite<$message$, *>) "
"{\n"
" _builder.clearExtension(extension)\n"
@@ -1572,8 +1431,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "@kotlin.PublishedApi\n"
- "internal fun <T : kotlin.Any> setExtension(extension: "
+ "public fun <T : kotlin.Any> setExtension(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>, "
"value: T) {\n"
" _builder.setExtension(extension, value)\n"
@@ -1583,7 +1441,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <T : Comparable<T>> set(\n"
+ "public inline operator fun <T : Comparable<T>> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
") {\n"
@@ -1594,7 +1452,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun set(\n"
+ "public inline operator fun set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, "
"com.google.protobuf.ByteString>,\n"
" value: com.google.protobuf.ByteString\n"
@@ -1606,7 +1464,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <T : com.google.protobuf.MessageLite> set(\n"
+ "public inline operator fun <T : com.google.protobuf.MessageLite> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
") {\n"
@@ -1616,7 +1474,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "fun <E : kotlin.Any> 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",
@@ -1625,7 +1483,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <E : kotlin.Any> "
+ "public inline operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign"
"(value: E) {\n"
@@ -1635,7 +1493,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "fun <E : kotlin.Any> 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"
@@ -1646,7 +1504,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <E : kotlin.Any> "
+ "public inline operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign(values: "
"Iterable<E>) {\n"
@@ -1656,7 +1514,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "operator fun <E : kotlin.Any> "
+ "public operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.set(index: Int, value: "
"E) {\n"
@@ -1667,7 +1525,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline fun com.google.protobuf.kotlin.ExtensionList<*, "
+ "public inline fun com.google.protobuf.kotlin.ExtensionList<*, "
"$message$>.clear() {\n"
" clear(extension)\n"
"}\n\n",
@@ -1722,12 +1580,19 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
" defaultInstance.getDescriptorForType().getFullName());\n"
"}\n"
"\n"
+ "public boolean isSameTypeAs(com.google.protobuf.Message message) {\n"
+ " return getTypeNameFromTypeUrl(getTypeUrl()).equals(\n"
+ " message.getDescriptorForType().getFullName());\n"
+ "}\n"
+ "\n"
+ "@SuppressWarnings(\"serial\")\n"
"private volatile com.google.protobuf.Message cachedUnpackValue;\n"
"\n"
"@java.lang.SuppressWarnings(\"unchecked\")\n"
"public <T extends com.google.protobuf.Message> T unpack(\n"
" java.lang.Class<T> clazz)\n"
- " throws com.google.protobuf.InvalidProtocolBufferException {\n"
+ " throws com.google.protobuf.InvalidProtocolBufferException {\n");
+ printer->Print(
" boolean invalidClazz = false;\n"
" if (cachedUnpackValue != null) {\n"
" if (cachedUnpackValue.getClass() == clazz) {\n"
@@ -1745,7 +1610,30 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
" .parseFrom(getValue());\n"
" cachedUnpackValue = result;\n"
" return result;\n"
- "}\n");
+ "}\n"
+ "\n"
+ "@java.lang.SuppressWarnings(\"unchecked\")\n"
+ "public <T extends com.google.protobuf.Message> T unpackSameTypeAs("
+ "T message)\n"
+ " throws com.google.protobuf.InvalidProtocolBufferException {\n");
+ printer->Print(
+ " boolean invalidValue = false;\n"
+ " if (cachedUnpackValue != null) {\n"
+ " if (cachedUnpackValue.getClass() == message.getClass()) {\n"
+ " return (T) cachedUnpackValue;\n"
+ " }\n"
+ " invalidValue = true;\n"
+ " }\n"
+ " if (invalidValue || !isSameTypeAs(message)) {\n"
+ " throw new com.google.protobuf.InvalidProtocolBufferException(\n"
+ " \"Type of the Any message does not match the given "
+ "exemplar.\");\n"
+ " }\n"
+ " T result = (T) message.getParserForType().parseFrom(getValue());\n"
+ " cachedUnpackValue = result;\n"
+ " return result;\n"
+ "}\n"
+ "\n");
}
} // namespace java
@@ -1753,4 +1641,4 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/message.h
index 2dbd0dd9bc..37263fa628 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message.h
@@ -35,10 +35,10 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "y_absl/container/btree_map.h"
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -64,6 +64,8 @@ static const int kMaxStaticSize = 1 << 15; // aka 32k
class MessageGenerator {
public:
explicit MessageGenerator(const Descriptor* descriptor);
+ MessageGenerator(const MessageGenerator&) = delete;
+ MessageGenerator& operator=(const MessageGenerator&) = delete;
virtual ~MessageGenerator();
// All static variables have to be declared at the top-level of the file
@@ -92,15 +94,15 @@ class MessageGenerator {
protected:
const Descriptor* descriptor_;
- std::set<const OneofDescriptor*> oneofs_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
+ y_absl::btree_map<int, const OneofDescriptor*> oneofs_;
};
class ImmutableMessageGenerator : public MessageGenerator {
public:
ImmutableMessageGenerator(const Descriptor* descriptor, Context* context);
+ ImmutableMessageGenerator(const ImmutableMessageGenerator&) = delete;
+ ImmutableMessageGenerator& operator=(const ImmutableMessageGenerator&) =
+ delete;
~ImmutableMessageGenerator() override;
void Generate(io::Printer* printer) override;
@@ -123,10 +125,6 @@ class ImmutableMessageGenerator : public MessageGenerator {
void GenerateMessageSerializationMethods(io::Printer* printer);
void GenerateParseFromMethods(io::Printer* printer);
- void GenerateSerializeOneField(io::Printer* printer,
- const FieldDescriptor* field);
- void GenerateSerializeOneExtensionRange(
- io::Printer* printer, const Descriptor::ExtensionRange* range);
void GenerateBuilder(io::Printer* printer);
void GenerateIsInitialized(io::Printer* printer);
@@ -143,8 +141,6 @@ class ImmutableMessageGenerator : public MessageGenerator {
Context* context_;
ClassNameResolver* name_resolver_;
FieldGeneratorMap<ImmutableFieldGenerator> field_generators_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.cc
index 3bbb7ae382..80064a9bf7 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.cc
@@ -32,42 +32,64 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/message_builder.h>
+#include "google/protobuf/compiler/java/message_builder.h"
#include <algorithm>
-#include <map>
#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/context.h>
-#include <google/protobuf/compiler/java/doc_comment.h>
-#include <google/protobuf/compiler/java/enum.h>
-#include <google/protobuf/compiler/java/extension.h>
-#include <google/protobuf/compiler/java/generator_factory.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/container/btree_set.h"
+#include "y_absl/container/flat_hash_map.h"
+#include "y_absl/strings/ascii.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/substitute.h"
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/doc_comment.h"
+#include "google/protobuf/compiler/java/enum.h"
+#include "google/protobuf/compiler/java/extension.h"
+#include "google/protobuf/compiler/java/generator_factory.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/coded_stream.h"
+#include "google/protobuf/io/printer.h"
+#include "google/protobuf/wire_format.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
namespace compiler {
namespace java {
+using internal::WireFormat;
+using internal::WireFormatLite;
+
namespace {
TProtoStringType MapValueImmutableClassdName(const Descriptor* descriptor,
ClassNameResolver* name_resolver) {
const FieldDescriptor* value_field = descriptor->map_value();
- GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type());
+ Y_ABSL_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type());
return name_resolver->GetImmutableClassName(value_field->message_type());
}
+
+bool BitfieldTracksMutability(const FieldDescriptor* const descriptor) {
+ if (!descriptor->is_repeated() || IsMapField(descriptor)) {
+ return false;
+ }
+ // TODO(b/255468704): update this to migrate repeated fields to use
+ // ProtobufList (which tracks immutability internally). That allows us to use
+ // the presence bit to skip work on the repeated field if it is not populated.
+ // Once all repeated fields are held in ProtobufLists, this method shouldn't
+ // be needed.
+ switch (descriptor->type()) {
+ case FieldDescriptor::TYPE_STRING:
+ return false;
+ default:
+ return true;
+ }
+}
} // namespace
MessageBuilderGenerator::MessageBuilderGenerator(const Descriptor* descriptor,
@@ -76,12 +98,13 @@ MessageBuilderGenerator::MessageBuilderGenerator(const Descriptor* descriptor,
context_(context),
name_resolver_(context->GetNameResolver()),
field_generators_(descriptor, context_) {
- GOOGLE_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
+ Y_ABSL_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
<< "Generator factory error: A non-lite message generator is used to "
"generate lite messages.";
for (int i = 0; i < descriptor_->field_count(); i++) {
if (IsRealOneof(descriptor_->field(i))) {
- oneofs_.insert(descriptor_->field(i)->containing_oneof());
+ const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof();
+ Y_ABSL_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof);
}
}
}
@@ -122,12 +145,13 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
}
// oneof
- std::map<TProtoStringType, TProtoStringType> vars;
- for (auto oneof : oneofs_) {
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
- vars["oneof_index"] = StrCat(oneof->index());
+ vars["oneof_index"] = y_absl::StrCat(oneof->index());
// oneofCase_ and oneof_
printer->Print(vars,
"private int $oneof_name$Case_ = 0;\n"
@@ -142,12 +166,11 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
"\n"
"public Builder clear$oneof_capitalized_name$() {\n"
" $oneof_name$Case_ = 0;\n"
- " $oneof_name$_ = null;\n");
- printer->Print(" onChanged();\n");
- printer->Print(
- " return this;\n"
- "}\n"
- "\n");
+ " $oneof_name$_ = null;\n"
+ " onChanged();\n"
+ " return this;\n"
+ "}\n"
+ "\n");
}
// Integers for bit fields.
@@ -168,24 +191,26 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
.GenerateBuilderMembers(printer);
}
- // Override methods declared in GeneratedMessage to return the concrete
- // generated type so callsites won't depend on GeneratedMessage. This
- // is needed to keep binary compatibility when we change generated code
- // to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
- // we changed all generated code to subclass GeneratedMessageV3).
- printer->Print(
- "@java.lang.Override\n"
- "public final Builder setUnknownFields(\n"
- " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
- " return super.setUnknownFields(unknownFields);\n"
- "}\n"
- "\n"
- "@java.lang.Override\n"
- "public final Builder mergeUnknownFields(\n"
- " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
- " return super.mergeUnknownFields(unknownFields);\n"
- "}\n"
- "\n");
+ if (context_->options().opensource_runtime) {
+ // Override methods declared in GeneratedMessage to return the concrete
+ // generated type so callsites won't depend on GeneratedMessage. This
+ // is needed to keep binary compatibility when we change generated code
+ // to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
+ // we changed all generated code to subclass GeneratedMessageV3).
+ printer->Print(
+ "@java.lang.Override\n"
+ "public final Builder setUnknownFields(\n"
+ " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
+ " return super.setUnknownFields(unknownFields);\n"
+ "}\n"
+ "\n"
+ "@java.lang.Override\n"
+ "public final Builder mergeUnknownFields(\n"
+ " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
+ " return super.mergeUnknownFields(unknownFields);\n"
+ "}\n"
+ "\n");
+ }
printer->Print(
"\n"
@@ -231,7 +256,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) {
printer->Print(
"case $number$:\n"
" return internalGet$capitalized_name$();\n",
- "number", StrCat(field->number()), "capitalized_name",
+ "number", y_absl::StrCat(field->number()), "capitalized_name",
info->capitalized_name);
}
printer->Print(
@@ -256,7 +281,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) {
printer->Print(
"case $number$:\n"
" return internalGetMutable$capitalized_name$();\n",
- "number", StrCat(field->number()), "capitalized_name",
+ "number", y_absl::StrCat(field->number()), "capitalized_name",
info->capitalized_name);
}
printer->Print(
@@ -288,43 +313,63 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) {
void MessageBuilderGenerator::GenerateCommonBuilderMethods(
io::Printer* printer) {
+ // Decide if we really need to have the "maybeForceBuilderInitialization()"
+ // method.
+ // TODO(b/249158148): Remove the need for this entirely
+ bool need_maybe_force_builder_init = false;
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ if (descriptor_->field(i)->message_type() != nullptr &&
+ !IsRealOneof(descriptor_->field(i)) &&
+ HasHasbit(descriptor_->field(i))) {
+ need_maybe_force_builder_init = true;
+ break;
+ }
+ }
+
+ const char* force_builder_init = need_maybe_force_builder_init
+ ? " maybeForceBuilderInitialization();"
+ : "";
+
printer->Print(
"// Construct using $classname$.newBuilder()\n"
"private Builder() {\n"
- " maybeForceBuilderInitialization();\n"
+ "$force_builder_init$\n"
"}\n"
"\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
+ "classname", name_resolver_->GetImmutableClassName(descriptor_),
+ "force_builder_init", force_builder_init);
printer->Print(
"private Builder(\n"
" com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n"
" super(parent);\n"
- " maybeForceBuilderInitialization();\n"
+ "$force_builder_init$\n"
"}\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "ver",
- GeneratedCodeVersionSuffix());
+ GeneratedCodeVersionSuffix(), "force_builder_init", force_builder_init);
- printer->Print(
- "private void maybeForceBuilderInitialization() {\n"
- " if (com.google.protobuf.GeneratedMessage$ver$\n"
- " .alwaysUseFieldBuilders) {\n",
- "ver", GeneratedCodeVersionSuffix());
+ if (need_maybe_force_builder_init) {
+ printer->Print(
+ "private void maybeForceBuilderInitialization() {\n"
+ " if (com.google.protobuf.GeneratedMessage$ver$\n"
+ " .alwaysUseFieldBuilders) {\n",
+ "ver", GeneratedCodeVersionSuffix());
- printer->Indent();
- printer->Indent();
- for (int i = 0; i < descriptor_->field_count(); i++) {
- if (!IsRealOneof(descriptor_->field(i))) {
- field_generators_.get(descriptor_->field(i))
- .GenerateFieldBuilderInitializationCode(printer);
+ printer->Indent();
+ printer->Indent();
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ if (!IsRealOneof(descriptor_->field(i))) {
+ field_generators_.get(descriptor_->field(i))
+ .GenerateFieldBuilderInitializationCode(printer);
+ }
}
- }
- printer->Outdent();
- printer->Outdent();
+ printer->Outdent();
+ printer->Outdent();
- printer->Print(
- " }\n"
- "}\n");
+ printer->Print(
+ " }\n"
+ "}\n");
+ }
printer->Print(
"@java.lang.Override\n"
@@ -332,19 +377,22 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
" super.clear();\n");
printer->Indent();
+ int totalBuilderInts = (descriptor_->field_count() + 31) / 32;
+ for (int i = 0; i < totalBuilderInts; i++) {
+ printer->Print("$bit_field_name$ = 0;\n", "bit_field_name",
+ GetBitFieldName(i));
+ }
for (int i = 0; i < descriptor_->field_count(); i++) {
- if (!IsRealOneof(descriptor_->field(i))) {
- field_generators_.get(descriptor_->field(i))
- .GenerateBuilderClearCode(printer);
- }
+ field_generators_.get(descriptor_->field(i))
+ .GenerateBuilderClearCode(printer);
}
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
printer->Print(
"$oneof_name$Case_ = 0;\n"
"$oneof_name$_ = null;\n",
- "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name);
+ "oneof_name", context_->GetOneofGeneratorInfo(kv.second)->name);
}
printer->Outdent();
@@ -385,134 +433,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
"\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
- printer->Print(
- "@java.lang.Override\n"
- "public $classname$ buildPartial() {\n"
- " $classname$ result = new $classname$(this);\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
-
- printer->Indent();
-
- int totalBuilderBits = 0;
- int totalMessageBits = 0;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const ImmutableFieldGenerator& field =
- field_generators_.get(descriptor_->field(i));
- totalBuilderBits += field.GetNumBitsForBuilder();
- totalMessageBits += field.GetNumBitsForMessage();
- }
- int totalBuilderInts = (totalBuilderBits + 31) / 32;
- int totalMessageInts = (totalMessageBits + 31) / 32;
-
- // Local vars for from and to bit fields to avoid accessing the builder and
- // message over and over for these fields. Seems to provide a slight
- // perforamance improvement in micro benchmark and this is also what proto1
- // code does.
- for (int i = 0; i < totalBuilderInts; i++) {
- printer->Print("int from_$bit_field_name$ = $bit_field_name$;\n",
- "bit_field_name", GetBitFieldName(i));
- }
- for (int i = 0; i < totalMessageInts; i++) {
- printer->Print("int to_$bit_field_name$ = 0;\n", "bit_field_name",
- GetBitFieldName(i));
- }
-
- // Output generation code for each field.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- field_generators_.get(descriptor_->field(i)).GenerateBuildingCode(printer);
- }
-
- // Copy the bit field results to the generated message
- for (int i = 0; i < totalMessageInts; i++) {
- printer->Print("result.$bit_field_name$ = to_$bit_field_name$;\n",
- "bit_field_name", GetBitFieldName(i));
- }
-
- for (auto oneof : oneofs_) {
- printer->Print("result.$oneof_name$Case_ = $oneof_name$Case_;\n",
- "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name);
- }
-
- printer->Outdent();
-
- printer->Print(" onBuilt();\n");
-
- printer->Print(
- " return result;\n"
- "}\n"
- "\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
-
- // Override methods declared in GeneratedMessage to return the concrete
- // generated type so callsites won't depend on GeneratedMessage. This
- // is needed to keep binary compatibility when we change generated code
- // to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
- // we changed all generated code to subclass GeneratedMessageV3).
- printer->Print(
- "@java.lang.Override\n"
- "public Builder clone() {\n"
- " return super.clone();\n"
- "}\n"
- "@java.lang.Override\n"
- "public Builder setField(\n"
- " com.google.protobuf.Descriptors.FieldDescriptor field,\n"
- " java.lang.Object value) {\n"
- " return super.setField(field, value);\n"
- "}\n"
- "@java.lang.Override\n"
- "public Builder clearField(\n"
- " com.google.protobuf.Descriptors.FieldDescriptor field) {\n"
- " return super.clearField(field);\n"
- "}\n"
- "@java.lang.Override\n"
- "public Builder clearOneof(\n"
- " com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n"
- " return super.clearOneof(oneof);\n"
- "}\n"
- "@java.lang.Override\n"
- "public Builder setRepeatedField(\n"
- " com.google.protobuf.Descriptors.FieldDescriptor field,\n"
- " int index, java.lang.Object value) {\n"
- " return super.setRepeatedField(field, index, value);\n"
- "}\n"
- "@java.lang.Override\n"
- "public Builder addRepeatedField(\n"
- " com.google.protobuf.Descriptors.FieldDescriptor field,\n"
- " java.lang.Object value) {\n"
- " return super.addRepeatedField(field, value);\n"
- "}\n");
-
- if (descriptor_->extension_range_count() > 0) {
- printer->Print(
- "@java.lang.Override\n"
- "public <Type> Builder setExtension(\n"
- " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
- " $classname$, Type> extension,\n"
- " Type value) {\n"
- " return super.setExtension(extension, value);\n"
- "}\n"
- "@java.lang.Override\n"
- "public <Type> Builder setExtension(\n"
- " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
- " $classname$, java.util.List<Type>> extension,\n"
- " int index, Type value) {\n"
- " return super.setExtension(extension, index, value);\n"
- "}\n"
- "@java.lang.Override\n"
- "public <Type> Builder addExtension(\n"
- " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
- " $classname$, java.util.List<Type>> extension,\n"
- " Type value) {\n"
- " return super.addExtension(extension, value);\n"
- "}\n"
- "@java.lang.Override\n"
- "public <Type> Builder clearExtension(\n"
- " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
- " $classname$, ?> extension) {\n"
- " return super.clearExtension(extension);\n"
- "}\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
- }
+ GenerateBuildPartial(printer);
// -----------------------------------------------------------------
@@ -546,7 +467,8 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
}
// Merge oneof fields.
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
printer->Print("switch (other.get$oneof_capitalized_name$Case()) {\n",
"oneof_capitalized_name",
context_->GetOneofGeneratorInfo(oneof)->capitalized_name);
@@ -554,7 +476,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
for (int j = 0; j < oneof->field_count(); j++) {
const FieldDescriptor* field = oneof->field(j);
printer->Print("case $field_name$: {\n", "field_name",
- ToUpper(field->name()));
+ y_absl::AsciiStrToUpper(field->name()));
printer->Indent();
field_generators_.get(field).GenerateMergingCode(printer);
printer->Print("break;\n");
@@ -566,7 +488,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
" break;\n"
"}\n",
"cap_oneof_name",
- ToUpper(context_->GetOneofGeneratorInfo(oneof)->name));
+ y_absl::AsciiStrToUpper(context_->GetOneofGeneratorInfo(oneof)->name));
printer->Outdent();
printer->Print("}\n");
}
@@ -578,7 +500,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
printer->Print(" this.mergeExtensionFields(other);\n");
}
- printer->Print(" this.mergeUnknownFields(other.unknownFields);\n");
+ printer->Print(" this.mergeUnknownFields(other.getUnknownFields());\n");
printer->Print(" onChanged();\n");
@@ -589,6 +511,154 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
}
}
+void MessageBuilderGenerator::GenerateBuildPartial(io::Printer* printer) {
+ printer->Print(
+ "@java.lang.Override\n"
+ "public $classname$ buildPartial() {\n"
+ " $classname$ result = new $classname$(this);\n",
+ "classname", name_resolver_->GetImmutableClassName(descriptor_));
+
+ printer->Indent();
+
+ // Handle the repeated fields first so that the "mutable bits" are cleared.
+ bool has_repeated_fields = false;
+ for (int i = 0; i < descriptor_->field_count(); ++i) {
+ if (BitfieldTracksMutability(descriptor_->field(i))) {
+ has_repeated_fields = true;
+ printer->Print("buildPartialRepeatedFields(result);\n");
+ break;
+ }
+ }
+
+ // One buildPartial#() per from_bit_field
+ int totalBuilderInts = (descriptor_->field_count() + 31) / 32;
+ if (totalBuilderInts > 0) {
+ for (int i = 0; i < totalBuilderInts; ++i) {
+ printer->Print(
+ "if ($bit_field_name$ != 0) { buildPartial$piece$(result); }\n",
+ "bit_field_name", GetBitFieldName(i), "piece", y_absl::StrCat(i));
+ }
+ }
+
+ if (!oneofs_.empty()) {
+ printer->Print("buildPartialOneofs(result);\n");
+ }
+
+ printer->Outdent();
+ printer->Print(
+ " onBuilt();\n"
+ " return result;\n"
+ "}\n"
+ "\n",
+ "classname", name_resolver_->GetImmutableClassName(descriptor_));
+
+ // Build Repeated Fields
+ if (has_repeated_fields) {
+ printer->Print(
+ "private void buildPartialRepeatedFields($classname$ result) {\n",
+ "classname", name_resolver_->GetImmutableClassName(descriptor_));
+ printer->Indent();
+ for (int i = 0; i < descriptor_->field_count(); ++i) {
+ if (BitfieldTracksMutability(descriptor_->field(i))) {
+ const ImmutableFieldGenerator& field =
+ field_generators_.get(descriptor_->field(i));
+ field.GenerateBuildingCode(printer);
+ }
+ }
+ printer->Outdent();
+ printer->Print("}\n\n");
+ }
+
+ // Build non-oneof fields
+ int start_field = 0;
+ for (int i = 0; i < totalBuilderInts; i++) {
+ start_field = GenerateBuildPartialPiece(printer, i, start_field);
+ }
+
+ // Build Oneofs
+ if (!oneofs_.empty()) {
+ printer->Print("private void buildPartialOneofs($classname$ result) {\n",
+ "classname",
+ name_resolver_->GetImmutableClassName(descriptor_));
+ printer->Indent();
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
+ printer->Print(
+ "result.$oneof_name$Case_ = $oneof_name$Case_;\n"
+ "result.$oneof_name$_ = this.$oneof_name$_;\n",
+ "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name);
+ for (int i = 0; i < oneof->field_count(); ++i) {
+ if (oneof->field(i)->message_type() != nullptr) {
+ const ImmutableFieldGenerator& field =
+ field_generators_.get(oneof->field(i));
+ field.GenerateBuildingCode(printer);
+ }
+ }
+ }
+ printer->Outdent();
+ printer->Print("}\n\n");
+ }
+}
+
+int MessageBuilderGenerator::GenerateBuildPartialPiece(io::Printer* printer,
+ int piece,
+ int first_field) {
+ printer->Print(
+ "private void buildPartial$piece$($classname$ result) {\n"
+ " int from_$bit_field_name$ = $bit_field_name$;\n",
+ "classname", name_resolver_->GetImmutableClassName(descriptor_), "piece",
+ y_absl::StrCat(piece), "bit_field_name", GetBitFieldName(piece));
+ printer->Indent();
+ y_absl::btree_set<int> declared_to_bitfields;
+
+ int bit = 0;
+ int next = first_field;
+ for (; bit < 32 && next < descriptor_->field_count(); ++next) {
+ const ImmutableFieldGenerator& field =
+ field_generators_.get(descriptor_->field(next));
+ bit += field.GetNumBitsForBuilder();
+
+ // Skip oneof fields that are handled separately
+ if (IsRealOneof(descriptor_->field(next))) {
+ continue;
+ }
+
+ // Skip repeated fields because they are currently handled
+ // in separate buildPartial sub-methods.
+ if (BitfieldTracksMutability(descriptor_->field(next))) {
+ continue;
+ }
+ // Skip fields without presence bits in the builder
+ if (field.GetNumBitsForBuilder() == 0) {
+ continue;
+ }
+
+ // Track message bits if necessary
+ if (field.GetNumBitsForMessage() > 0) {
+ int to_bitfield = field.GetMessageBitIndex() / 32;
+ if (declared_to_bitfields.count(to_bitfield) == 0) {
+ printer->Print("int to_$bit_field_name$ = 0;\n", "bit_field_name",
+ GetBitFieldName(to_bitfield));
+ declared_to_bitfields.insert(to_bitfield);
+ }
+ }
+
+ // Copy the field from the builder to the message
+ field.GenerateBuildingCode(printer);
+ }
+
+ // Copy the bit field results to the generated message
+ for (int to_bitfield : declared_to_bitfields) {
+ printer->Print("result.$bit_field_name$ |= to_$bit_field_name$;\n",
+ "bit_field_name", GetBitFieldName(to_bitfield));
+ }
+
+ printer->Outdent();
+ printer->Print("}\n\n");
+
+ return next;
+}
+
// ===================================================================
void MessageBuilderGenerator::GenerateBuilderParsingMethods(
@@ -599,20 +669,92 @@ void MessageBuilderGenerator::GenerateBuilderParsingMethods(
" com.google.protobuf.CodedInputStream input,\n"
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
" throws java.io.IOException {\n"
- " $classname$ parsedMessage = null;\n"
+ " if (extensionRegistry == null) {\n"
+ " throw new java.lang.NullPointerException();\n"
+ " }\n"
" try {\n"
- " parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);\n"
+ " boolean done = false;\n"
+ " while (!done) {\n"
+ " int tag = input.readTag();\n"
+ " switch (tag) {\n"
+ " case 0:\n" // zero signals EOF / limit reached
+ " done = true;\n"
+ " break;\n");
+ printer->Indent(); // method
+ printer->Indent(); // try
+ printer->Indent(); // while
+ printer->Indent(); // switch
+ GenerateBuilderFieldParsingCases(printer);
+ printer->Outdent(); // switch
+ printer->Outdent(); // while
+ printer->Outdent(); // try
+ printer->Outdent(); // method
+ printer->Print(
+ " default: {\n"
+ " if (!super.parseUnknownField(input, extensionRegistry, tag)) "
+ "{\n"
+ " done = true; // was an endgroup tag\n"
+ " }\n"
+ " break;\n"
+ " } // default:\n"
+ " } // switch (tag)\n"
+ " } // while (!done)\n"
" } catch (com.google.protobuf.InvalidProtocolBufferException e) {\n"
- " parsedMessage = ($classname$) e.getUnfinishedMessage();\n"
" throw e.unwrapIOException();\n"
" } finally {\n"
- " if (parsedMessage != null) {\n"
- " mergeFrom(parsedMessage);\n"
- " }\n"
- " }\n"
+ " onChanged();\n"
+ " } // finally\n"
" return this;\n"
- "}\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
+ "}\n");
+}
+
+void MessageBuilderGenerator::GenerateBuilderFieldParsingCases(
+ io::Printer* printer) {
+ std::unique_ptr<const FieldDescriptor*[]> sorted_fields(
+ SortFieldsByNumber(descriptor_));
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ const FieldDescriptor* field = sorted_fields[i];
+ GenerateBuilderFieldParsingCase(printer, field);
+ if (field->is_packable()) {
+ GenerateBuilderPackedFieldParsingCase(printer, field);
+ }
+ }
+}
+
+void MessageBuilderGenerator::GenerateBuilderFieldParsingCase(
+ io::Printer* printer, const FieldDescriptor* field) {
+ arc_ui32 tag = WireFormatLite::MakeTag(
+ field->number(), WireFormat::WireTypeForFieldType(field->type()));
+ TProtoStringType tagString = y_absl::StrCat(static_cast<arc_i32>(tag));
+ printer->Print("case $tag$: {\n", "tag", tagString);
+ printer->Indent();
+
+ field_generators_.get(field).GenerateBuilderParsingCode(printer);
+
+ printer->Outdent();
+ printer->Print(
+ " break;\n"
+ "} // case $tag$\n",
+ "tag", tagString);
+}
+
+void MessageBuilderGenerator::GenerateBuilderPackedFieldParsingCase(
+ io::Printer* printer, const FieldDescriptor* field) {
+ // To make packed = true wire compatible, we generate parsing code from a
+ // packed version of this field regardless of field->options().packed().
+ arc_ui32 tag = WireFormatLite::MakeTag(
+ field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
+ TProtoStringType tagString = y_absl::StrCat(static_cast<arc_i32>(tag));
+ printer->Print("case $tag$: {\n", "tag", tagString);
+ printer->Indent();
+
+ field_generators_.get(field).GenerateBuilderParsingCodeFromPacked(printer);
+
+ printer->Outdent();
+ printer->Print(
+ " break;\n"
+ "} // case $tag$\n",
+ "tag", tagString);
}
// ===================================================================
@@ -714,4 +856,4 @@ void MessageBuilderGenerator::GenerateIsInitialized(io::Printer* printer) {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.h
index f9c9a00a0c..16585da339 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder.h
@@ -35,10 +35,10 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "y_absl/container/btree_map.h"
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -63,23 +63,33 @@ class MessageBuilderGenerator {
public:
explicit MessageBuilderGenerator(const Descriptor* descriptor,
Context* context);
+ MessageBuilderGenerator(const MessageBuilderGenerator&) = delete;
+ MessageBuilderGenerator& operator=(const MessageBuilderGenerator&) = delete;
virtual ~MessageBuilderGenerator();
virtual void Generate(io::Printer* printer);
private:
void GenerateCommonBuilderMethods(io::Printer* printer);
+ void GenerateBuildPartial(io::Printer* printer);
+ int GenerateBuildPartialPiece(io::Printer* printer, int piece,
+ int first_field);
+ int GenerateBuildPartialPieceWithoutPresence(io::Printer* printer, int piece,
+ int first_field);
void GenerateDescriptorMethods(io::Printer* printer);
void GenerateBuilderParsingMethods(io::Printer* printer);
+ void GenerateBuilderFieldParsingCases(io::Printer* printer);
+ void GenerateBuilderFieldParsingCase(io::Printer* printer,
+ const FieldDescriptor* field);
+ void GenerateBuilderPackedFieldParsingCase(io::Printer* printer,
+ const FieldDescriptor* field);
void GenerateIsInitialized(io::Printer* printer);
const Descriptor* descriptor_;
Context* context_;
ClassNameResolver* name_resolver_;
FieldGeneratorMap<ImmutableFieldGenerator> field_generators_;
- std::set<const OneofDescriptor*> oneofs_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageBuilderGenerator);
+ y_absl::btree_map<int, const OneofDescriptor*> oneofs_;
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.cc
index bf41a71107..f85341d9ce 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.cc
@@ -32,29 +32,30 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/message_builder_lite.h>
+#include "google/protobuf/compiler/java/message_builder_lite.h"
#include <algorithm>
-#include <map>
#include <memory>
+#include <string>
#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/context.h>
-#include <google/protobuf/compiler/java/doc_comment.h>
-#include <google/protobuf/compiler/java/enum.h>
-#include <google/protobuf/compiler/java/extension.h>
-#include <google/protobuf/compiler/java/generator_factory.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/substitute.h"
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/doc_comment.h"
+#include "google/protobuf/compiler/java/enum.h"
+#include "google/protobuf/compiler/java/extension.h"
+#include "google/protobuf/compiler/java/generator_factory.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/coded_stream.h"
+#include "google/protobuf/io/printer.h"
+#include "google/protobuf/wire_format.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -67,12 +68,13 @@ MessageBuilderLiteGenerator::MessageBuilderLiteGenerator(
context_(context),
name_resolver_(context->GetNameResolver()),
field_generators_(descriptor, context_) {
- GOOGLE_CHECK(!HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
+ Y_ABSL_CHECK(!HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
<< "Generator factory error: A lite message generator is used to "
"generate non-lite messages.";
for (int i = 0; i < descriptor_->field_count(); i++) {
if (IsRealOneof(descriptor_->field(i))) {
- oneofs_.insert(descriptor_->field(i)->containing_oneof());
+ const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof();
+ Y_ABSL_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof);
}
}
}
@@ -81,41 +83,51 @@ MessageBuilderLiteGenerator::~MessageBuilderLiteGenerator() {}
void MessageBuilderLiteGenerator::Generate(io::Printer* printer) {
WriteMessageDocComment(printer, descriptor_);
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars = {
+ {"{", ""},
+ {"}", ""},
+ {"classname", name_resolver_->GetImmutableClassName(descriptor_)},
+ {"extra_interfaces", ExtraBuilderInterfaces(descriptor_)},
+ {"extendible",
+ descriptor_->extension_range_count() > 0 ? "Extendable" : ""},
+ };
printer->Print(
- "public static final class Builder extends\n"
+ vars,
+ "public static final class ${$Builder$}$ extends\n"
" com.google.protobuf.GeneratedMessageLite.$extendible$Builder<\n"
" $classname$, Builder> implements\n"
" $extra_interfaces$\n"
- " $classname$OrBuilder {\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_),
- "extra_interfaces", ExtraBuilderInterfaces(descriptor_), "extendible",
- descriptor_->extension_range_count() > 0 ? "Extendable" : "");
+ " $classname$OrBuilder {\n");
+ printer->Annotate("{", "}", descriptor_);
printer->Indent();
GenerateCommonBuilderMethods(printer);
// oneof
- std::map<TProtoStringType, TProtoStringType> vars;
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
- vars["oneof_index"] = StrCat(oneof->index());
+ vars["oneof_index"] = y_absl::StrCat(oneof->index());
// oneofCase() and clearOneof()
printer->Print(vars,
"@java.lang.Override\n"
"public $oneof_capitalized_name$Case\n"
- " get$oneof_capitalized_name$Case() {\n"
+ " ${$get$oneof_capitalized_name$Case$}$() {\n"
" return instance.get$oneof_capitalized_name$Case();\n"
- "}\n"
+ "}\n");
+ printer->Annotate("{", "}", oneof);
+ printer->Print(vars,
"\n"
- "public Builder clear$oneof_capitalized_name$() {\n"
+ "public Builder ${$clear$oneof_capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$oneof_capitalized_name$();\n"
" return this;\n"
"}\n"
"\n");
+ printer->Annotate("{", "}", oneof);
}
for (int i = 0; i < descriptor_->field_count(); i++) {
@@ -153,4 +165,4 @@ void MessageBuilderLiteGenerator::GenerateCommonBuilderMethods(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.h
index 0d895fcf05..a0feece646 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_builder_lite.h
@@ -35,10 +35,10 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "y_absl/container/btree_map.h"
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -63,6 +63,9 @@ class MessageBuilderLiteGenerator {
public:
explicit MessageBuilderLiteGenerator(const Descriptor* descriptor,
Context* context);
+ MessageBuilderLiteGenerator(const MessageBuilderLiteGenerator&) = delete;
+ MessageBuilderLiteGenerator& operator=(const MessageBuilderLiteGenerator&) =
+ delete;
virtual ~MessageBuilderLiteGenerator();
virtual void Generate(io::Printer* printer);
@@ -74,9 +77,7 @@ class MessageBuilderLiteGenerator {
Context* context_;
ClassNameResolver* name_resolver_;
FieldGeneratorMap<ImmutableFieldLiteGenerator> field_generators_;
- std::set<const OneofDescriptor*> oneofs_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageBuilderLiteGenerator);
+ y_absl::btree_map<int, const OneofDescriptor*> oneofs_;
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.cc
index a16abfcb34..1a5efaa938 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.cc
@@ -32,21 +32,21 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/message_field.h>
+#include "google/protobuf/compiler/java/message_field.h"
-#include <map>
#include <string>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "y_absl/log/absl_check.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/io/printer.h"
+#include "google/protobuf/wire_format.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -56,15 +56,16 @@ namespace java {
namespace {
-void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
- int builderBitIndex, const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetMessageVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
name_resolver->GetImmutableClassName(descriptor->message_type());
- (*variables)["kt_type"] = (*variables)["type"];
+ variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])});
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->message_type());
(*variables)["group_or_message"] =
@@ -74,38 +75,33 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
(*variables)["on_changed"] = "onChanged();";
(*variables)["ver"] = GeneratedCodeVersionSuffix();
(*variables)["get_parser"] =
- ExposePublicParser(descriptor->message_type()->file()) ? "PARSER"
- : "parser()";
+ ExposePublicParser(descriptor->message_type()->file()) &&
+ context->options().opensource_runtime
+ ? "PARSER"
+ : "parser()";
if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
- (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
// Note that these have a trailing ";".
- (*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
- (*variables)["set_has_field_bit_builder"] =
- GenerateSetBit(builderBitIndex) + ";";
- (*variables)["clear_has_field_bit_builder"] =
- GenerateClearBit(builderBitIndex) + ";";
+ (*variables)["set_has_field_bit_to_local"] =
+ GenerateSetBitToLocal(messageBitIndex);
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
- (*variables)["set_has_field_bit_message"] = "";
- (*variables)["set_has_field_bit_builder"] = "";
- (*variables)["clear_has_field_bit_builder"] = "";
-
- (*variables)["is_field_present_message"] =
- (*variables)["name"] + "_ != null";
+ (*variables)["set_has_field_bit_to_local"] = "";
+ variables->insert({"is_field_present_message",
+ y_absl::StrCat((*variables)["name"], "_ != null")});
}
// For repeated builders, one bit is used for whether the array is immutable.
@@ -113,17 +109,13 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex);
(*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex);
- // For repeated fields, one bit is used for whether the array is immutable
- // in the parsing constructor.
- (*variables)["get_mutable_bit_parser"] =
- GenerateGetBitMutableLocal(builderBitIndex);
- (*variables)["set_mutable_bit_parser"] =
- GenerateSetBitMutableLocal(builderBitIndex);
-
+ (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
+ (*variables)["set_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateSetBit(builderBitIndex), ";");
+ (*variables)["clear_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateClearBit(builderBitIndex), ";");
(*variables)["get_has_field_bit_from_local"] =
GenerateGetBitFromLocal(builderBitIndex);
- (*variables)["set_has_field_bit_to_local"] =
- GenerateSetBitToLocal(messageBitIndex);
}
} // namespace
@@ -133,21 +125,31 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ message_bit_index_(messageBitIndex),
+ builder_bit_index_(builderBitIndex),
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
ImmutableMessageFieldGenerator::~ImmutableMessageFieldGenerator() {}
+int ImmutableMessageFieldGenerator::GetMessageBitIndex() const {
+ return message_bit_index_;
+}
+
+int ImmutableMessageFieldGenerator::GetBuilderBitIndex() const {
+ return builder_bit_index_;
+}
+
int ImmutableMessageFieldGenerator::GetNumBitsForMessage() const {
return HasHasbit(descriptor_) ? 1 : 0;
}
-int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const {
- return GetNumBitsForMessage();
-}
+int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { return 1; }
void ImmutableMessageFieldGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
@@ -180,24 +182,6 @@ void ImmutableMessageFieldGenerator::GenerateMembers(
" return $get_has_field_bit_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
- WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
- printer->Print(
- variables_,
- "@java.lang.Override\n"
- "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
- " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
-
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(
- variables_,
- "@java.lang.Override\n"
- "$deprecation$public $type$OrBuilder "
- "${$get$capitalized_name$OrBuilder$}$() {\n"
- " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
} else {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(
@@ -207,24 +191,25 @@ void ImmutableMessageFieldGenerator::GenerateMembers(
" return $name$_ != null;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
- WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
- printer->Print(
- variables_,
- "@java.lang.Override\n"
- "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
- " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
-
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "@java.lang.Override\n"
- "$deprecation$public $type$OrBuilder "
- "${$get$capitalized_name$OrBuilder$}$() {\n"
- " return get$capitalized_name$();\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
}
+ WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
+ printer->Print(
+ variables_,
+ "@java.lang.Override\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
+ " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+
+ WriteFieldDocComment(printer, descriptor_);
+ printer->Print(
+ variables_,
+ "@java.lang.Override\n"
+ "$deprecation$public $type$OrBuilder "
+ "${$get$capitalized_name$OrBuilder$}$() {\n"
+ " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableMessageFieldGenerator::PrintNestedBuilderCondition(
@@ -262,9 +247,6 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
// When using nested-builders, the code initially works just like the
// non-nested builder case. It only creates a nested builder lazily on
// demand and then forever delegates to it after creation.
-
- bool has_hasbit = HasHasbit(descriptor_);
-
printer->Print(variables_, "private $type$ $name$_;\n");
printer->Print(variables_,
@@ -279,21 +261,11 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
// boolean hasField()
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
- if (has_hasbit) {
- printer->Print(
- variables_,
- "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
- " return $get_has_field_bit_builder$;\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
- } else {
- printer->Print(
- variables_,
- "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
- " return $name$Builder_ != null || $name$_ != null;\n"
- "}\n");
- printer->Annotate("{", "}", descriptor_);
- }
+ printer->Print(variables_,
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
+ " return $get_has_field_bit_builder$;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field getField()
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
@@ -311,12 +283,12 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
"if (value == null) {\n"
" throw new NullPointerException();\n"
"}\n"
- "$name$_ = value;\n"
- "$on_changed$\n",
+ "$name$_ = value;\n",
"$name$Builder_.setMessage(value);\n",
"$set_has_field_bit_builder$\n"
+ "$on_changed$\n"
"return this;\n");
// Field.Builder setField(Field.Builder builderForValue)
@@ -326,58 +298,48 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" $type$.Builder builderForValue)",
- "$name$_ = builderForValue.build();\n"
- "$on_changed$\n",
+ "$name$_ = builderForValue.build();\n",
"$name$Builder_.setMessage(builderForValue.build());\n",
"$set_has_field_bit_builder$\n"
+ "$on_changed$\n"
"return this;\n");
- // Field.Builder mergeField(Field value)
+ // Message.Builder mergeField(Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(
printer,
"$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)",
-
- has_hasbit
- ? "if ($get_has_field_bit_builder$ &&\n"
- " $name$_ != null &&\n"
- " $name$_ != $type$.getDefaultInstance()) {\n"
- " $name$_ =\n"
- " $type$.newBuilder($name$_).mergeFrom(value).buildPartial();\n"
- "} else {\n"
- " $name$_ = value;\n"
- "}\n"
- "$on_changed$\n"
- : "if ($name$_ != null) {\n"
- " $name$_ =\n"
- " $type$.newBuilder($name$_).mergeFrom(value).buildPartial();\n"
- "} else {\n"
- " $name$_ = value;\n"
- "}\n"
- "$on_changed$\n",
+ "if ($get_has_field_bit_builder$ &&\n"
+ " $name$_ != null &&\n"
+ " $name$_ != $type$.getDefaultInstance()) {\n"
+ " get$capitalized_name$Builder().mergeFrom(value);\n"
+ "} else {\n"
+ " $name$_ = value;\n"
+ "}\n",
"$name$Builder_.mergeFrom(value);\n",
"$set_has_field_bit_builder$\n"
+ "$on_changed$\n"
"return this;\n");
- // Field.Builder clearField()
+ // Message.Builder clearField()
WriteFieldDocComment(printer, descriptor_);
- PrintNestedBuilderFunction(
- printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()",
-
- "$name$_ = null;\n"
- "$on_changed$\n",
-
- has_hasbit ? "$name$Builder_.clear();\n"
- : "$name$_ = null;\n"
- "$name$Builder_ = null;\n",
-
- "$clear_has_field_bit_builder$\n"
- "return this;\n");
+ printer->Print(variables_,
+ "$deprecation$public Builder clear$capitalized_name$() {\n"
+ " $clear_has_field_bit_builder$\n"
+ " $name$_ = null;\n"
+ " if ($name$Builder_ != null) {\n"
+ " $name$Builder_.dispose();\n"
+ " $name$Builder_ = null;\n"
+ " }\n"
+ " $on_changed$\n"
+ " return this;\n"
+ "}\n");
+ // Field.Builder getFieldBuilder()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public $type$.Builder "
@@ -387,6 +349,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
" return get$capitalized_name$FieldBuilder().getBuilder();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // FieldOrBuilder getFieldOrBuilder()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public $type$OrBuilder "
@@ -399,6 +363,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
" }\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // SingleFieldBuilder getFieldFieldBuilder
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -419,9 +385,9 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$var $kt_name$: $kt_type$\n"
+ "$kt_deprecation$public var $kt_name$: $kt_type$\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -430,16 +396,17 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
" }\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
@@ -449,16 +416,14 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
void ImmutableMessageFieldGenerator::GenerateKotlinOrNull(io::Printer* printer) const {
if (descriptor_->has_optional_keyword()) {
printer->Print(variables_,
- "val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n"
+ "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n"
" get() = $kt_dsl_builder$.$name$OrNull\n");
}
}
void ImmutableMessageFieldGenerator::GenerateFieldBuilderInitializationCode(
io::Printer* printer) const {
- if (HasHasbit(descriptor_)) {
- printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n");
- }
+ printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n");
}
void ImmutableMessageFieldGenerator::GenerateInitializationCode(
@@ -466,17 +431,13 @@ void ImmutableMessageFieldGenerator::GenerateInitializationCode(
void ImmutableMessageFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
- if (HasHasbit(descriptor_)) {
- PrintNestedBuilderCondition(printer, "$name$_ = null;\n",
-
- "$name$Builder_.clear();\n");
- printer->Print(variables_, "$clear_has_field_bit_builder$\n");
- } else {
- PrintNestedBuilderCondition(printer, "$name$_ = null;\n",
-
- "$name$_ = null;\n"
- "$name$Builder_ = null;\n");
- }
+ // No need to clear the has-bit since we clear the bitField ints all at once.
+ printer->Print(variables_,
+ "$name$_ = null;\n"
+ "if ($name$Builder_ != null) {\n"
+ " $name$Builder_.dispose();\n"
+ " $name$Builder_ = null;\n"
+ "}\n");
}
void ImmutableMessageFieldGenerator::GenerateMergingCode(
@@ -489,50 +450,32 @@ void ImmutableMessageFieldGenerator::GenerateMergingCode(
void ImmutableMessageFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
- if (HasHasbit(descriptor_)) {
- printer->Print(variables_, "if ($get_has_field_bit_from_local$) {\n");
- printer->Indent();
- PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n",
- "result.$name$_ = $name$Builder_.build();\n");
- printer->Outdent();
- printer->Print(variables_,
- " $set_has_field_bit_to_local$;\n"
- "}\n");
- } else {
- PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n",
- "result.$name$_ = $name$Builder_.build();\n");
+ printer->Print(variables_,
+ "if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$Builder_ == null\n"
+ " ? $name$_\n"
+ " : $name$Builder_.build();\n");
+ if (GetNumBitsForMessage() > 0) {
+ printer->Print(variables_, " $set_has_field_bit_to_local$;\n");
}
+ printer->Print("}\n");
}
-void ImmutableMessageFieldGenerator::GenerateParsingCode(
+void ImmutableMessageFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "$type$.Builder subBuilder = null;\n"
- "if ($is_field_present_message$) {\n"
- " subBuilder = $name$_.toBuilder();\n"
- "}\n");
-
if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) {
printer->Print(variables_,
- "$name$_ = input.readGroup($number$, $type$.$get_parser$,\n"
- " extensionRegistry);\n");
+ "input.readGroup($number$,\n"
+ " get$capitalized_name$FieldBuilder().getBuilder(),\n"
+ " extensionRegistry);\n"
+ "$set_has_field_bit_builder$\n");
} else {
printer->Print(variables_,
- "$name$_ = input.readMessage($type$.$get_parser$, "
- "extensionRegistry);\n");
+ "input.readMessage(\n"
+ " get$capitalized_name$FieldBuilder().getBuilder(),\n"
+ " extensionRegistry);\n"
+ "$set_has_field_bit_builder$\n");
}
-
- printer->Print(variables_,
- "if (subBuilder != null) {\n"
- " subBuilder.mergeFrom($name$_);\n"
- " $name$_ = subBuilder.buildPartial();\n"
- "}\n"
- "$set_has_field_bit_message$\n");
-}
-
-void ImmutableMessageFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- // noop for messages.
}
void ImmutableMessageFieldGenerator::GenerateSerializationCode(
@@ -596,6 +539,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateMembers(
" return $has_oneof_case_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -779,24 +723,28 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
" $oneof_name$_ = null;\n"
" }\n"
" $set_oneof_case_message$;\n"
- " $on_changed$;\n"
+ " $on_changed$\n"
" return $name$Builder_;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
-void ImmutableMessageOneofFieldGenerator::GenerateBuildingCode(
+void ImmutableMessageOneofFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
- printer->Print(variables_, "if ($has_oneof_case_message$) {\n");
- printer->Indent();
-
- PrintNestedBuilderCondition(
- printer, "result.$oneof_name$_ = $oneof_name$_;\n",
-
- "result.$oneof_name$_ = $name$Builder_.build();\n");
+ // Make sure the builder gets cleared.
+ printer->Print(variables_,
+ "if ($name$Builder_ != null) {\n"
+ " $name$Builder_.clear();\n"
+ "}\n");
+}
- printer->Outdent();
- printer->Print("}\n");
+void ImmutableMessageOneofFieldGenerator::GenerateBuildingCode(
+ io::Printer* printer) const {
+ printer->Print(variables_,
+ "if ($has_oneof_case_message$ &&\n"
+ " $name$Builder_ != null) {\n"
+ " result.$oneof_name$_ = $name$Builder_.build();\n"
+ "}\n");
}
void ImmutableMessageOneofFieldGenerator::GenerateMergingCode(
@@ -805,32 +753,21 @@ void ImmutableMessageOneofFieldGenerator::GenerateMergingCode(
"merge$capitalized_name$(other.get$capitalized_name$());\n");
}
-void ImmutableMessageOneofFieldGenerator::GenerateParsingCode(
+void ImmutableMessageOneofFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "$type$.Builder subBuilder = null;\n"
- "if ($has_oneof_case_message$) {\n"
- " subBuilder = (($type$) $oneof_name$_).toBuilder();\n"
- "}\n");
-
if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) {
- printer->Print(
- variables_,
- "$oneof_name$_ = input.readGroup($number$, $type$.$get_parser$,\n"
- " extensionRegistry);\n");
+ printer->Print(variables_,
+ "input.readGroup($number$,\n"
+ " get$capitalized_name$FieldBuilder().getBuilder(),\n"
+ " extensionRegistry);\n"
+ "$set_oneof_case_message$;\n");
} else {
- printer->Print(
- variables_,
- "$oneof_name$_ =\n"
- " input.readMessage($type$.$get_parser$, extensionRegistry);\n");
+ printer->Print(variables_,
+ "input.readMessage(\n"
+ " get$capitalized_name$FieldBuilder().getBuilder(),\n"
+ " extensionRegistry);\n"
+ "$set_oneof_case_message$;\n");
}
-
- printer->Print(variables_,
- "if (subBuilder != null) {\n"
- " subBuilder.mergeFrom(($type$) $oneof_name$_);\n"
- " $oneof_name$_ = subBuilder.buildPartial();\n"
- "}\n");
- printer->Print(variables_, "$set_oneof_case_message$;\n");
}
void ImmutableMessageOneofFieldGenerator::GenerateSerializationCode(
@@ -857,11 +794,8 @@ void ImmutableMessageOneofFieldGenerator::GenerateSerializedSizeCode(
RepeatedImmutableMessageFieldGenerator::RepeatedImmutableMessageFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
- SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
- context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
-}
+ : ImmutableMessageFieldGenerator(descriptor, messageBitIndex,
+ builderBitIndex, context) {}
RepeatedImmutableMessageFieldGenerator::
~RepeatedImmutableMessageFieldGenerator() {}
@@ -904,7 +838,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateInterfaceMembers(
void RepeatedImmutableMessageFieldGenerator::GenerateMembers(
io::Printer* printer) const {
- printer->Print(variables_, "private java.util.List<$type$> $name$_;\n");
+ printer->Print(variables_, "@SuppressWarnings(\"serial\")\n"
+ "private java.util.List<$type$> $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@@ -914,6 +849,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers(
" return $name$_;\n" // note: unmodifiable list
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // List<FieldOrBuilder> getFieldOrBuilderList()
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -923,6 +860,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers(
" return $name$_;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // int getFieldCount()
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -931,6 +870,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers(
" return $name$_.size();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // Field getField(int index)
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -939,6 +880,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers(
" return $name$_.get(index);\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // FieldOrBuilder getFieldOrBuilder(int index)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -1164,7 +1107,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"return this;\n");
- // Builder clearAllRepeatedField()
+ // Builder clearRepeatedField()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(
printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()",
@@ -1191,6 +1134,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"return this;\n");
+ // Field.Builder getRepeatedFieldBuilder(int index)
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -1200,6 +1144,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
+ // FieldOrBuilder getRepeatedFieldOrBuilder(int index)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public $type$OrBuilder "
@@ -1213,6 +1158,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
+ // List<FieldOrBuilder> getRepeatedFieldOrBuilderList()
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -1226,6 +1172,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
+ // Field.Builder addRepeatedField()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public $type$.Builder "
@@ -1234,6 +1181,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
" $type$.getDefaultInstance());\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // Field.Builder addRepeatedFieldBuilder(int index)
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -1243,6 +1192,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
" index, $type$.getDefaultInstance());\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
+
+ // List<Field.Builder> getRepeatedFieldBuilderList()
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -1281,10 +1232,12 @@ void RepeatedImmutableMessageFieldGenerator::GenerateInitializationCode(
void RepeatedImmutableMessageFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
PrintNestedBuilderCondition(printer,
- "$name$_ = java.util.Collections.emptyList();\n"
- "$clear_mutable_bit_builder$;\n",
+ "$name$_ = java.util.Collections.emptyList();\n",
+ "$name$_ = null;\n"
"$name$Builder_.clear();\n");
+
+ printer->Print(variables_, "$clear_mutable_bit_builder$;\n");
}
void RepeatedImmutableMessageFieldGenerator::GenerateMergingCode(
@@ -1339,34 +1292,25 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuildingCode(
"result.$name$_ = $name$Builder_.build();\n");
}
-void RepeatedImmutableMessageFieldGenerator::GenerateParsingCode(
+void RepeatedImmutableMessageFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "if (!$get_mutable_bit_parser$) {\n"
- " $name$_ = new java.util.ArrayList<$type$>();\n"
- " $set_mutable_bit_parser$;\n"
- "}\n");
-
if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) {
- printer->Print(
- variables_,
- "$name$_.add(input.readGroup($number$, $type$.$get_parser$,\n"
- " extensionRegistry));\n");
+ printer->Print(variables_,
+ "$type$ m =\n"
+ " input.readGroup($number$,\n"
+ " $type$.$get_parser$,\n"
+ " extensionRegistry);\n");
} else {
- printer->Print(
- variables_,
- "$name$_.add(\n"
- " input.readMessage($type$.$get_parser$, extensionRegistry));\n");
+ printer->Print(variables_,
+ "$type$ m =\n"
+ " input.readMessage(\n"
+ " $type$.$get_parser$,\n"
+ " extensionRegistry);\n");
}
-}
-
-void RepeatedImmutableMessageFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- printer->Print(
- variables_,
- "if ($get_mutable_bit_parser$) {\n"
- " $name$_ = java.util.Collections.unmodifiableList($name$_);\n"
- "}\n");
+ PrintNestedBuilderCondition(printer,
+ "ensure$capitalized_name$IsMutable();\n"
+ "$name$_.add(m);\n",
+ "$name$Builder_.addMessage(m);\n");
}
void RepeatedImmutableMessageFieldGenerator::GenerateSerializationCode(
@@ -1419,12 +1363,12 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$ public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -1433,70 +1377,70 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
" )\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -1508,4 +1452,4 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.h
index 602612e4ad..6e3e2c479d 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field.h
@@ -35,10 +35,9 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -62,10 +61,16 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
int messageBitIndex,
int builderBitIndex,
Context* context);
+ ImmutableMessageFieldGenerator(const ImmutableMessageFieldGenerator&) =
+ delete;
+ ImmutableMessageFieldGenerator& operator=(
+ const ImmutableMessageFieldGenerator&) = delete;
~ImmutableMessageFieldGenerator() override;
// implements ImmutableFieldGenerator
// ---------------------------------------
+ int GetMessageBitIndex() const override;
+ int GetBuilderBitIndex() const override;
int GetNumBitsForMessage() const override;
int GetNumBitsForBuilder() const override;
void GenerateInterfaceMembers(io::Printer* printer) const override;
@@ -75,8 +80,7 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -89,20 +93,22 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ int message_bit_index_;
+ int builder_bit_index_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
ClassNameResolver* name_resolver_;
+ Context* context_;
- void PrintNestedBuilderCondition(io::Printer* printer,
- const char* regular_case,
- const char* nested_builder_case) const;
- void PrintNestedBuilderFunction(io::Printer* printer,
- const char* method_prototype,
- const char* regular_case,
- const char* nested_builder_case,
- const char* trailing_code) const;
+ virtual void PrintNestedBuilderCondition(
+ io::Printer* printer, const char* regular_case,
+ const char* nested_builder_case) const;
+ virtual void PrintNestedBuilderFunction(io::Printer* printer,
+ const char* method_prototype,
+ const char* regular_case,
+ const char* nested_builder_case,
+ const char* trailing_code) const;
private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageFieldGenerator);
void GenerateKotlinOrNull(io::Printer* printer) const;
};
@@ -112,25 +118,32 @@ class ImmutableMessageOneofFieldGenerator
ImmutableMessageOneofFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
Context* context);
+ ImmutableMessageOneofFieldGenerator(
+ const ImmutableMessageOneofFieldGenerator&) = delete;
+ ImmutableMessageOneofFieldGenerator& operator=(
+ const ImmutableMessageOneofFieldGenerator&) = delete;
~ImmutableMessageOneofFieldGenerator() override;
void GenerateMembers(io::Printer* printer) const override;
void GenerateBuilderMembers(io::Printer* printer) const override;
+ void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldGenerator);
};
-class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
+class RepeatedImmutableMessageFieldGenerator
+ : public ImmutableMessageFieldGenerator {
public:
explicit RepeatedImmutableMessageFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, Context* context);
+ RepeatedImmutableMessageFieldGenerator(
+ const RepeatedImmutableMessageFieldGenerator&) = delete;
+ RepeatedImmutableMessageFieldGenerator& operator=(
+ const RepeatedImmutableMessageFieldGenerator&) = delete;
~RepeatedImmutableMessageFieldGenerator() override;
// implements ImmutableFieldGenerator ---------------------------------------
@@ -143,8 +156,7 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -156,21 +168,14 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
TProtoStringType GetBoxedType() const override;
protected:
- const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
- ClassNameResolver* name_resolver_;
-
- void PrintNestedBuilderCondition(io::Printer* printer,
- const char* regular_case,
- const char* nested_builder_case) const;
+ void PrintNestedBuilderCondition(
+ io::Printer* printer, const char* regular_case,
+ const char* nested_builder_case) const override;
void PrintNestedBuilderFunction(io::Printer* printer,
const char* method_prototype,
const char* regular_case,
const char* nested_builder_case,
- const char* trailing_code) const;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableMessageFieldGenerator);
+ const char* trailing_code) const override;
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.cc
index 23d3c410f6..08cb34094c 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.cc
@@ -32,22 +32,21 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/message_field_lite.h>
+#include "google/protobuf/compiler/java/message_field_lite.h"
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "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/io/printer.h"
+#include "google/protobuf/wire_format.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -56,15 +55,16 @@ namespace java {
namespace {
-void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
- int builderBitIndex, const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetMessageVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
name_resolver->GetImmutableClassName(descriptor->message_type());
- (*variables)["kt_type"] = (*variables)["type"];
+ variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])});
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->message_type());
(*variables)["group_or_message"] =
@@ -74,11 +74,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (HasHasbit(descriptor)) {
@@ -87,17 +88,17 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateSetBit(messageBitIndex), ";");
(*variables)["clear_has_field_bit_message"] =
- GenerateClearBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateClearBit(messageBitIndex), ";");
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
(*variables)["set_has_field_bit_message"] = "";
(*variables)["clear_has_field_bit_message"] = "";
- (*variables)["is_field_present_message"] =
- (*variables)["name"] + "_ != null";
+ variables->insert({"is_field_present_message",
+ y_absl::StrCat((*variables)["name"], "_ != null")});
}
(*variables)["get_has_field_bit_from_local"] =
@@ -108,6 +109,9 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
(*variables)["null_check"] = "value.getClass();\n";
+ // Annotations often use { and } to determine ranges.
+ (*variables)["{"] = "";
+ (*variables)["}"] = "";
}
} // namespace
@@ -118,10 +122,11 @@ ImmutableMessageFieldLiteGenerator::ImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
- name_resolver_(context->GetNameResolver()) {
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
ImmutableMessageFieldLiteGenerator::~ImmutableMessageFieldLiteGenerator() {}
@@ -137,9 +142,13 @@ int ImmutableMessageFieldLiteGenerator::GetNumBitsForMessage() const {
void ImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
- printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n");
+ printer->Print(variables_,
+ "$deprecation$boolean ${$has$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
- printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n");
+ printer->Print(variables_,
+ "$deprecation$$type$ ${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableMessageFieldLiteGenerator::GenerateMembers(
@@ -288,9 +297,9 @@ void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers(
void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$var $kt_name$: $kt_type$\n"
+ "$kt_deprecation$public var $kt_name$: $kt_type$\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -299,16 +308,17 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
" }\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
GenerateKotlinOrNull(printer);
@@ -317,7 +327,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
void ImmutableMessageFieldLiteGenerator::GenerateKotlinOrNull(io::Printer* printer) const {
if (descriptor_->has_optional_keyword()) {
printer->Print(variables_,
- "val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n"
+ "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n"
" get() = $kt_dsl_builder$.$name$OrNull\n");
}
}
@@ -495,10 +505,12 @@ RepeatedImmutableMessageFieldLiteGenerator::
RepeatedImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
RepeatedImmutableMessageFieldLiteGenerator::
@@ -517,17 +529,28 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers(
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$java.util.List<$type$> \n"
- " get$capitalized_name$List();\n");
+ " ${$get$capitalized_name$List$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$$type$ get$capitalized_name$(int index);\n");
+ printer->Print(
+ variables_,
+ "$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$int get$capitalized_name$Count();\n");
+ "$deprecation$int ${$get$capitalized_name$Count$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "@com.google.protobuf.ProtoField(\n"
+ " fieldNumber=$number$,\n"
+ " type=com.google.protobuf.FieldType.$annotation_field_type$)\n");
+ }
printer->Print(
variables_,
"private com.google.protobuf.Internal.ProtobufList<$type$> $name$_;\n");
@@ -806,12 +829,12 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$ public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -820,70 +843,70 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
" )\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -895,4 +918,4 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.h
index 5bf9607bc8..8bcc550f47 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_field_lite.h
@@ -36,10 +36,9 @@
#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -62,6 +61,10 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator {
explicit ImmutableMessageFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context);
+ ImmutableMessageFieldLiteGenerator(
+ const ImmutableMessageFieldLiteGenerator&) = delete;
+ ImmutableMessageFieldLiteGenerator& operator=(
+ const ImmutableMessageFieldLiteGenerator&) = delete;
~ImmutableMessageFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator
@@ -79,12 +82,12 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
const int messageBitIndex_;
ClassNameResolver* name_resolver_;
+ Context* context_;
private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageFieldLiteGenerator);
void GenerateKotlinOrNull(io::Printer* printer) const;
};
@@ -94,6 +97,10 @@ class ImmutableMessageOneofFieldLiteGenerator
ImmutableMessageOneofFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context);
+ ImmutableMessageOneofFieldLiteGenerator(
+ const ImmutableMessageOneofFieldLiteGenerator&) = delete;
+ ImmutableMessageOneofFieldLiteGenerator& operator=(
+ const ImmutableMessageOneofFieldLiteGenerator&) = delete;
~ImmutableMessageOneofFieldLiteGenerator() override;
void GenerateMembers(io::Printer* printer) const override;
@@ -101,8 +108,6 @@ class ImmutableMessageOneofFieldLiteGenerator
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16_t>* output) const override;
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldLiteGenerator);
};
class RepeatedImmutableMessageFieldLiteGenerator
@@ -110,6 +115,10 @@ class RepeatedImmutableMessageFieldLiteGenerator
public:
explicit RepeatedImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context);
+ RepeatedImmutableMessageFieldLiteGenerator(
+ const RepeatedImmutableMessageFieldLiteGenerator&) = delete;
+ RepeatedImmutableMessageFieldLiteGenerator& operator=(
+ const RepeatedImmutableMessageFieldLiteGenerator&) = delete;
~RepeatedImmutableMessageFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator ------------------------------------
@@ -126,11 +135,9 @@ class RepeatedImmutableMessageFieldLiteGenerator
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
ClassNameResolver* name_resolver_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableMessageFieldLiteGenerator);
+ Context* context_;
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.cc
index 90bd4b2382..8306511545 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.cc
@@ -32,32 +32,34 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/message_lite.h>
+#include "google/protobuf/compiler/java/message_lite.h"
#include <algorithm>
#include <cstdint>
-#include <map>
#include <memory>
+#include <string>
#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/context.h>
-#include <google/protobuf/compiler/java/doc_comment.h>
-#include <google/protobuf/compiler/java/enum_lite.h>
-#include <google/protobuf/compiler/java/extension_lite.h>
-#include <google/protobuf/compiler/java/generator_factory.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/message_builder.h>
-#include <google/protobuf/compiler/java/message_builder_lite.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "y_absl/strings/ascii.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/substitute.h"
+#include "google/protobuf/compiler/java/context.h"
+#include "google/protobuf/compiler/java/doc_comment.h"
+#include "google/protobuf/compiler/java/enum_lite.h"
+#include "google/protobuf/compiler/java/extension_lite.h"
+#include "google/protobuf/compiler/java/generator_factory.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/message_builder.h"
+#include "google/protobuf/compiler/java/message_builder_lite.h"
+#include "google/protobuf/compiler/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"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -74,12 +76,13 @@ ImmutableMessageLiteGenerator::ImmutableMessageLiteGenerator(
context_(context),
name_resolver_(context->GetNameResolver()),
field_generators_(descriptor, context_) {
- GOOGLE_CHECK(!HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
+ Y_ABSL_CHECK(!HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
<< "Generator factory error: A lite message generator is used to "
"generate non-lite messages.";
for (int i = 0; i < descriptor_->field_count(); i++) {
if (IsRealOneof(descriptor_->field(i))) {
- oneofs_.insert(descriptor_->field(i)->containing_oneof());
+ const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof();
+ Y_ABSL_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof);
}
}
}
@@ -114,26 +117,33 @@ int ImmutableMessageLiteGenerator::GenerateStaticVariableInitializers(
void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true, "OrBuilder");
+
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables = {
+ {"{", ""},
+ {"}", ""},
+ {"deprecation",
+ descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""},
+ {"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_)},
+ {"classname", descriptor_->name()},
+ };
+
+ if (!context_->options().opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
+ }
if (descriptor_->extension_range_count() > 0) {
printer->Print(
+ variables,
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends \n"
" $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessageLite.\n"
" ExtendableMessageOrBuilder<\n"
- " $classname$, $classname$.Builder> {\n",
- "deprecation",
- descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "",
- "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
- "classname", descriptor_->name(), "{", "", "}", "");
+ " $classname$, $classname$.Builder> {\n");
} else {
printer->Print(
+ variables,
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
" $extra_interfaces$\n"
- " com.google.protobuf.MessageLiteOrBuilder {\n",
- "deprecation",
- descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "",
- "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
- "classname", descriptor_->name(), "{", "", "}", "");
+ " com.google.protobuf.MessageLiteOrBuilder {\n");
}
printer->Annotate("{", "}", descriptor_);
@@ -143,14 +153,17 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
field_generators_.get(descriptor_->field(i))
.GenerateInterfaceMembers(printer);
}
- for (auto oneof : oneofs_) {
- printer->Print(
- "\n"
- "public $classname$.$oneof_capitalized_name$Case "
- "get$oneof_capitalized_name$Case();\n",
- "oneof_capitalized_name",
- context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname",
- context_->GetNameResolver()->GetImmutableClassName(descriptor_));
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
+ variables["oneof_capitalized_name"] =
+ context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
+ variables["classname"] =
+ context_->GetNameResolver()->GetImmutableClassName(descriptor_);
+ printer->Print(variables,
+ "\n"
+ "public ${$$classname$.$oneof_capitalized_name$Case$}$ "
+ "get$oneof_capitalized_name$Case();\n");
+ printer->Annotate("{", "}", oneof);
}
printer->Outdent();
@@ -162,7 +175,8 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
- std::map<TProtoStringType, TProtoStringType> variables;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables = {{"{", ""},
+ {"}", ""}};
variables["static"] = is_own_file ? " " : " static ";
variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
@@ -179,18 +193,18 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
if (descriptor_->extension_range_count() > 0) {
printer->Print(
variables,
- "$deprecation$public $static$final class $classname$ extends\n"
+ "$deprecation$public $static$final class ${$$classname$$}$ extends\n"
" com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n"
" $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n"
" $classname$OrBuilder {\n");
- builder_type = strings::Substitute(
+ builder_type = y_absl::Substitute(
"com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>",
name_resolver_->GetImmutableClassName(descriptor_));
} else {
printer->Print(
variables,
- "$deprecation$public $static$final class $classname$ extends\n"
+ "$deprecation$public $static$final class ${$$classname$$}$ extends\n"
" com.google.protobuf.GeneratedMessageLite<\n"
" $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n"
@@ -198,6 +212,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
builder_type = "com.google.protobuf.GeneratedMessageLite.Builder";
}
+ printer->Annotate("{", "}", descriptor_);
printer->Indent();
GenerateConstructor(printer);
@@ -230,49 +245,59 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
}
// oneof
- std::map<TProtoStringType, TProtoStringType> vars;
- for (auto oneof : oneofs_) {
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars = {{"{", ""},
+ {"}", ""}};
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
- vars["oneof_index"] = StrCat((oneof)->index());
- // oneofCase_ and oneof_
- printer->Print(vars,
- "private int $oneof_name$Case_ = 0;\n"
- "private java.lang.Object $oneof_name$_;\n");
+ vars["oneof_index"] = y_absl::StrCat((oneof)->index());
+ if (context_->options().opensource_runtime) {
+ // oneofCase_ and oneof_
+ printer->Print(vars,
+ "private int $oneof_name$Case_ = 0;\n"
+ "private java.lang.Object $oneof_name$_;\n");
+ }
// OneofCase enum
- printer->Print(vars, "public enum $oneof_capitalized_name$Case {\n");
+ printer->Print(vars, "public enum ${$$oneof_capitalized_name$Case$}$ {\n");
+ printer->Annotate("{", "}", oneof);
printer->Indent();
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print("$field_name$($field_number$),\n", "field_name",
- ToUpper(field->name()), "field_number",
- StrCat(field->number()));
+ y_absl::AsciiStrToUpper(field->name()), "field_number",
+ y_absl::StrCat(field->number()));
+ printer->Annotate("field_name", field);
}
printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name",
- ToUpper(vars["oneof_name"]));
+ y_absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Print(vars,
"private final int value;\n"
"private $oneof_capitalized_name$Case(int value) {\n"
" this.value = value;\n"
"}\n");
+ if (context_->options().opensource_runtime) {
+ printer->Print(
+ vars,
+ "/**\n"
+ " * @deprecated Use {@link #forNumber(int)} instead.\n"
+ " */\n"
+ "@java.lang.Deprecated\n"
+ "public static $oneof_capitalized_name$Case valueOf(int value) {\n"
+ " return forNumber(value);\n"
+ "}\n"
+ "\n");
+ }
printer->Print(
vars,
- "/**\n"
- " * @deprecated Use {@link #forNumber(int)} instead.\n"
- " */\n"
- "@java.lang.Deprecated\n"
- "public static $oneof_capitalized_name$Case valueOf(int value) {\n"
- " return forNumber(value);\n"
- "}\n"
- "\n"
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n");
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print(" case $field_number$: return $field_name$;\n",
- "field_number", StrCat(field->number()),
- "field_name", ToUpper(field->name()));
+ "field_number", y_absl::StrCat(field->number()),
+ "field_name", y_absl::AsciiStrToUpper(field->name()));
}
printer->Print(
" case 0: return $cap_oneof_name$_NOT_SET;\n"
@@ -284,30 +309,34 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
"public int getNumber() {\n"
" return this.value;\n"
"}\n",
- "cap_oneof_name", ToUpper(vars["oneof_name"]));
+ "cap_oneof_name", y_absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Outdent();
printer->Print("};\n\n");
// oneofCase()
printer->Print(vars,
"@java.lang.Override\n"
"public $oneof_capitalized_name$Case\n"
- "get$oneof_capitalized_name$Case() {\n"
+ "${$get$oneof_capitalized_name$Case$}$() {\n"
" return $oneof_capitalized_name$Case.forNumber(\n"
" $oneof_name$Case_);\n"
- "}\n"
+ "}\n");
+ printer->Annotate("{", "}", oneof);
+ printer->Print(vars,
"\n"
- "private void clear$oneof_capitalized_name$() {\n"
+ "private void ${$clear$oneof_capitalized_name$$}$() {\n"
" $oneof_name$Case_ = 0;\n"
" $oneof_name$_ = null;\n"
"}\n"
"\n");
+ printer->Annotate("{", "}", oneof);
}
// Fields
for (int i = 0; i < descriptor_->field_count(); i++) {
printer->Print("public static final int $constant_name$ = $number$;\n",
"constant_name", FieldConstantName(descriptor_->field(i)),
- "number", StrCat(descriptor_->field(i)->number()));
+ "number", y_absl::StrCat(descriptor_->field(i)->number()));
+ printer->Annotate("constant_name", descriptor_->field(i));
field_generators_.get(descriptor_->field(i)).GenerateMembers(printer);
printer->Print("\n");
}
@@ -496,11 +525,11 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo(
// Record the number of oneofs.
WriteIntToUtf16CharSequence(oneofs_.size(), &chars);
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
printer->Print(
"\"$oneof_name$_\",\n"
"\"$oneof_name$Case_\",\n",
- "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name);
+ "oneof_name", context_->GetOneofGeneratorInfo(kv.second)->name);
}
// Integers for bit fields.
@@ -734,10 +763,10 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl(
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
"@com.google.protobuf.kotlin.ProtoDslMarker\n");
printer->Print(
- "class Dsl private constructor(\n"
+ "public class Dsl private constructor(\n"
" private val _builder: $message$.Builder\n"
") {\n"
- " companion object {\n"
+ " public companion object {\n"
" @kotlin.jvm.JvmSynthetic\n"
" @kotlin.PublishedApi\n"
" internal fun _create(builder: $message$.Builder): Dsl = "
@@ -747,7 +776,8 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl(
" @kotlin.jvm.JvmSynthetic\n"
" @kotlin.PublishedApi\n"
" internal fun _build(): $message$ = _builder.build()\n",
- "message", name_resolver_->GetClassName(descriptor_, true));
+ "message",
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)));
printer->Indent();
@@ -757,18 +787,19 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl(
.GenerateKotlinDslMembers(printer);
}
- for (auto oneof : oneofs_) {
+ for (auto& kv : oneofs_) {
+ const OneofDescriptor* oneof = kv.second;
printer->Print(
- "val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n"
+ "public val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n"
" @JvmName(\"get$oneof_capitalized_name$Case\")\n"
" get() = _builder.get$oneof_capitalized_name$Case()\n\n"
- "fun clear$oneof_capitalized_name$() {\n"
+ "public fun clear$oneof_capitalized_name$() {\n"
" _builder.clear$oneof_capitalized_name$()\n"
"}\n",
"oneof_name", context_->GetOneofGeneratorInfo(oneof)->name,
"oneof_capitalized_name",
context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "message",
- name_resolver_->GetClassName(descriptor_, true));
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)));
}
if (descriptor_->extension_range_count() > 0) {
@@ -781,18 +812,24 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl(
void ImmutableMessageLiteGenerator::GenerateKotlinMembers(
io::Printer* printer) const {
+ printer->Print("@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n",
+ "camelcase_name",
+ name_resolver_->GetKotlinFactoryName(descriptor_));
+
printer->Print(
- "@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n"
- "inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
- "kotlin.Unit): "
- "$message$ =\n"
+ "public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
+ "kotlin.Unit): $message$ =\n"
" $message_kt$.Dsl._create($message$.newBuilder()).apply { block() "
"}._build()\n",
"camelcase_name", name_resolver_->GetKotlinFactoryName(descriptor_),
- "message_kt", name_resolver_->GetKotlinExtensionsClassName(descriptor_),
- "message", name_resolver_->GetClassName(descriptor_, true));
-
- printer->Print("object $name$Kt {\n", "name", descriptor_->name());
+ "message_kt",
+ EscapeKotlinKeywords(
+ name_resolver_->GetKotlinExtensionsClassName(descriptor_)),
+ "message",
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)));
+
+ WriteMessageDocComment(printer, descriptor_, /* kdoc */ true);
+ printer->Print("public object $name$Kt {\n", "name", descriptor_->name());
printer->Indent();
GenerateKotlinDsl(printer);
for (int i = 0; i < descriptor_->nested_type_count(); i++) {
@@ -807,13 +844,15 @@ void ImmutableMessageLiteGenerator::GenerateKotlinMembers(
void ImmutableMessageLiteGenerator::GenerateTopLevelKotlinMembers(
io::Printer* printer) const {
printer->Print(
- "inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
- "kotlin.Unit): "
- "$message$ =\n"
+ "public inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
+ "kotlin.Unit): $message$ =\n"
" $message_kt$.Dsl._create(this.toBuilder()).apply { block() "
"}._build()\n\n",
- "message", name_resolver_->GetClassName(descriptor_, true), "message_kt",
- name_resolver_->GetKotlinExtensionsClassName(descriptor_));
+ "message",
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)),
+ "message_kt",
+ EscapeKotlinKeywords(
+ name_resolver_->GetKotlinExtensionsClassName(descriptor_)));
for (int i = 0; i < descriptor_->nested_type_count(); i++) {
if (IsMapEntry(descriptor_->nested_type(i))) continue;
@@ -830,30 +869,33 @@ void ImmutableMessageLiteGenerator::GenerateKotlinOrNull(io::Printer* printer) c
const FieldDescriptor* field = descriptor_->field(i);
if (field->has_presence() && GetJavaType(field) == JAVATYPE_MESSAGE) {
printer->Print(
- "val $full_classname$OrBuilder.$camelcase_name$OrNull: "
+ "public 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),
+ "full_classname",
+ EscapeKotlinKeywords(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);
+ EscapeKotlinKeywords(
+ name_resolver_->GetImmutableClassName(field->message_type())),
+ "name", context_->GetFieldGeneratorInfo(field)->capitalized_name);
}
}
}
void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
io::Printer* printer) const {
- TProtoStringType message_name = name_resolver_->GetClassName(descriptor_, true);
+ TProtoStringType message_name =
+ EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true));
printer->Print(
"@Suppress(\"UNCHECKED_CAST\")\n"
"@kotlin.jvm.JvmSynthetic\n"
- "operator fun <T : kotlin.Any> 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$, "
- "List<*>>) as T\n"
+ "kotlin.collections.List<*>>) as T\n"
" } else {\n"
" _builder.getExtension(extension)\n"
" }\n"
@@ -865,8 +907,9 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
"@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n"
- "operator fun <E : kotlin.Any> get(\n"
- " extension: com.google.protobuf.ExtensionLite<$message$, List<E>>\n"
+ "public operator fun <E : kotlin.Any> get(\n"
+ " extension: com.google.protobuf.ExtensionLite<$message$, "
+ "kotlin.collections.List<E>>\n"
"): com.google.protobuf.kotlin.ExtensionList<E, $message$> {\n"
" return com.google.protobuf.kotlin.ExtensionList(extension, "
"_builder.getExtension(extension))\n"
@@ -875,7 +918,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "operator fun contains(extension: "
+ "public operator fun contains(extension: "
"com.google.protobuf.ExtensionLite<$message$, *>): "
"Boolean {\n"
" return _builder.hasExtension(extension)\n"
@@ -884,7 +927,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "fun clear(extension: "
+ "public fun clear(extension: "
"com.google.protobuf.ExtensionLite<$message$, *>) "
"{\n"
" _builder.clearExtension(extension)\n"
@@ -893,8 +936,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "@kotlin.PublishedApi\n"
- "internal fun <T : kotlin.Any> setExtension(extension: "
+ "public fun <T : kotlin.Any> setExtension(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>, "
"value: T) {\n"
" _builder.setExtension(extension, value)\n"
@@ -904,7 +946,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <T : Comparable<T>> set(\n"
+ "public inline operator fun <T : Comparable<T>> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
") {\n"
@@ -915,7 +957,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun set(\n"
+ "public inline operator fun set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, "
"com.google.protobuf.ByteString>,\n"
" value: com.google.protobuf.ByteString\n"
@@ -927,7 +969,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <T : com.google.protobuf.MessageLite> set(\n"
+ "public inline operator fun <T : com.google.protobuf.MessageLite> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
") {\n"
@@ -937,7 +979,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "fun<E : kotlin.Any> 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",
@@ -946,7 +988,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <E : kotlin.Any> "
+ "public inline operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign"
"(value: E) {\n"
@@ -956,7 +998,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "fun<E : kotlin.Any> 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"
@@ -967,7 +1009,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun <E : kotlin.Any> "
+ "public inline operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign(values: "
"Iterable<E>) {\n"
@@ -977,7 +1019,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
- "operator fun <E : kotlin.Any> "
+ "public operator fun <E : kotlin.Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.set(index: Int, value: "
"E) {\n"
@@ -988,7 +1030,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline fun com.google.protobuf.kotlin.ExtensionList<*, "
+ "public inline fun com.google.protobuf.kotlin.ExtensionList<*, "
"$message$>.clear() {\n"
" clear(extension)\n"
"}\n\n",
@@ -1000,4 +1042,4 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.h
index d1e4b68949..279404099e 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_lite.h
@@ -35,8 +35,8 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__
-#include <google/protobuf/compiler/java/field.h>
-#include <google/protobuf/compiler/java/message.h>
+#include "google/protobuf/compiler/java/field.h"
+#include "google/protobuf/compiler/java/message.h"
namespace google {
namespace protobuf {
@@ -46,6 +46,9 @@ namespace java {
class ImmutableMessageLiteGenerator : public MessageGenerator {
public:
ImmutableMessageLiteGenerator(const Descriptor* descriptor, Context* context);
+ ImmutableMessageLiteGenerator(const ImmutableMessageLiteGenerator&) = delete;
+ ImmutableMessageLiteGenerator& operator=(
+ const ImmutableMessageLiteGenerator&) = delete;
~ImmutableMessageLiteGenerator() override;
void Generate(io::Printer* printer) override;
@@ -73,8 +76,6 @@ class ImmutableMessageLiteGenerator : public MessageGenerator {
Context* context_;
ClassNameResolver* name_resolver_;
FieldGeneratorMap<ImmutableFieldLiteGenerator> field_generators_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageLiteGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.cc
new file mode 100644
index 0000000000..9ecfac21d0
--- /dev/null
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.cc
@@ -0,0 +1,51 @@
+// 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
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "google/protobuf/compiler/java/message_serialization.h"
+
+#include "y_absl/strings/str_cat.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/io/printer.h"
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace java {
+
+void GenerateSerializeExtensionRange(io::Printer* printer,
+ const Descriptor::ExtensionRange* range) {
+ printer->Print("extensionWriter.writeUntil($end$, output);\n", "end",
+ y_absl::StrCat(range->end));
+}
+
+} // namespace java
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.h
new file mode 100644
index 0000000000..3b7c8461cb
--- /dev/null
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/message_serialization.h
@@ -0,0 +1,103 @@
+// 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
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__
+#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__
+
+#include <algorithm>
+#include <cstddef>
+#include <vector>
+
+#include "google/protobuf/compiler/java/field.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/io/printer.h"
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace java {
+
+// Generates code to serialize a single extension range.
+void GenerateSerializeExtensionRange(io::Printer* printer,
+ const Descriptor::ExtensionRange* range);
+
+// Generates code to serialize all fields and extension ranges for the specified
+// message descriptor, sorting serialization calls in increasing order by field
+// number.
+//
+// Templatized to support different field generator implementations.
+template <typename FieldGenerator>
+void GenerateSerializeFieldsAndExtensions(
+ io::Printer* printer,
+ const FieldGeneratorMap<FieldGenerator>& field_generators,
+ const Descriptor* descriptor, const FieldDescriptor** sorted_fields) {
+ std::vector<const Descriptor::ExtensionRange*> sorted_extensions;
+ sorted_extensions.reserve(descriptor->extension_range_count());
+ for (int i = 0; i < descriptor->extension_range_count(); ++i) {
+ sorted_extensions.push_back(descriptor->extension_range(i));
+ }
+ std::sort(sorted_extensions.begin(), sorted_extensions.end(),
+ ExtensionRangeOrdering());
+
+ std::size_t range_idx = 0;
+
+ // Merge the fields and the extension ranges, both sorted by field number.
+ for (int i = 0; i < descriptor->field_count(); ++i) {
+ const FieldDescriptor* field = sorted_fields[i];
+
+ // Collapse all extension ranges up until the next field. This leads to
+ // shorter and more efficient codegen for messages containing a large
+ // number of extension ranges without fields in between them.
+ const Descriptor::ExtensionRange* range = nullptr;
+ while (range_idx < sorted_extensions.size() &&
+ sorted_extensions[range_idx]->end <= field->number()) {
+ range = sorted_extensions[range_idx++];
+ }
+
+ if (range != nullptr) {
+ GenerateSerializeExtensionRange(printer, range);
+ }
+ field_generators.get(field).GenerateSerializationCode(printer);
+ }
+
+ // After serializing all fields, serialize any remaining extensions via a
+ // single writeUntil call.
+ if (range_idx < sorted_extensions.size()) {
+ GenerateSerializeExtensionRange(printer, sorted_extensions.back());
+ }
+}
+
+} // namespace java
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.cc
index 5cadecadf3..5959805240 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.cc
@@ -28,18 +28,21 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <google/protobuf/compiler/java/name_resolver.h>
+#include "google/protobuf/compiler/java/name_resolver.h"
-#include <map>
#include <string>
-#include <google/protobuf/compiler/code_generator.h>
-#include <google/protobuf/stubs/substitute.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/names.h>
+#include "y_absl/log/absl_check.h"
+#include "y_absl/strings/ascii.h"
+#include "y_absl/strings/str_replace.h"
+#include "y_absl/strings/substitute.h"
+#include "google/protobuf/compiler/code_generator.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/names.h"
+
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -56,8 +59,8 @@ const char* kOuterClassNameSuffix = "OuterClass";
// Full name : foo.Bar.Baz
// Package name: foo
// After strip : Bar.Baz
-TProtoStringType StripPackageName(const TProtoStringType& full_name,
- const FileDescriptor* file) {
+y_absl::string_view StripPackageName(y_absl::string_view full_name,
+ const FileDescriptor* file) {
if (file->package().empty()) {
return full_name;
} else {
@@ -69,7 +72,8 @@ TProtoStringType StripPackageName(const TProtoStringType& full_name,
// Get the name of a message's Java class without package name prefix.
TProtoStringType ClassNameWithoutPackage(const Descriptor* descriptor,
bool immutable) {
- return StripPackageName(descriptor->full_name(), descriptor->file());
+ return TProtoStringType(
+ StripPackageName(descriptor->full_name(), descriptor->file()));
}
TProtoStringType ClassNameWithoutPackageKotlin(const Descriptor* descriptor) {
@@ -77,7 +81,7 @@ TProtoStringType ClassNameWithoutPackageKotlin(const Descriptor* descriptor) {
const Descriptor* temp = descriptor->containing_type();
while (temp) {
- result = temp->name() + "Kt." + result;
+ result = y_absl::StrCat(temp->name(), "Kt.", result);
temp = temp->containing_type();
}
return result;
@@ -91,24 +95,24 @@ TProtoStringType ClassNameWithoutPackage(const EnumDescriptor* descriptor,
if (message_descriptor == NULL) {
return descriptor->name();
} else {
- return ClassNameWithoutPackage(message_descriptor, immutable) + "." +
- descriptor->name();
+ return y_absl::StrCat(ClassNameWithoutPackage(message_descriptor, immutable),
+ ".", descriptor->name());
}
}
// Get the name of a service's Java class without package name prefix.
TProtoStringType ClassNameWithoutPackage(const ServiceDescriptor* descriptor,
bool immutable) {
- TProtoStringType full_name =
+ y_absl::string_view full_name =
StripPackageName(descriptor->full_name(), descriptor->file());
// We don't allow nested service definitions.
- GOOGLE_CHECK(full_name.find('.') == TProtoStringType::npos);
- return full_name;
+ Y_ABSL_CHECK(!y_absl::StrContains(full_name, '.'));
+ return TProtoStringType(full_name);
}
// Return true if a and b are equals (case insensitive).
-NameEquality CheckNameEquality(const TProtoStringType& a, const TProtoStringType& b) {
- if (ToUpper(a) == ToUpper(b)) {
+NameEquality CheckNameEquality(y_absl::string_view a, y_absl::string_view b) {
+ if (y_absl::AsciiStrToUpper(a) == y_absl::AsciiStrToUpper(b)) {
if (a == b) {
return NameEquality::EXACT_EQUAL;
}
@@ -119,7 +123,7 @@ NameEquality CheckNameEquality(const TProtoStringType& a, const TProtoStringType
// Check whether a given message or its nested types has the given class name.
bool MessageHasConflictingClassName(const Descriptor* message,
- const TProtoStringType& classname,
+ y_absl::string_view classname,
NameEquality equality_mode) {
if (CheckNameEquality(message->name(), classname) == equality_mode) {
return true;
@@ -141,10 +145,6 @@ bool MessageHasConflictingClassName(const Descriptor* message,
} // namespace
-ClassNameResolver::ClassNameResolver() {}
-
-ClassNameResolver::~ClassNameResolver() {}
-
TProtoStringType ClassNameResolver::GetFileDefaultImmutableClassName(
const FileDescriptor* file) {
TProtoStringType basename;
@@ -182,18 +182,18 @@ TProtoStringType ClassNameResolver::GetFileClassName(const FileDescriptor* file,
TProtoStringType ClassNameResolver::GetFileClassName(const FileDescriptor* file,
bool immutable, bool kotlin) {
if (kotlin) {
- return GetFileImmutableClassName(file) + "Kt";
+ return y_absl::StrCat(GetFileImmutableClassName(file), "Kt");
} else if (immutable) {
return GetFileImmutableClassName(file);
} else {
- return "Mutable" + GetFileImmutableClassName(file);
+ return y_absl::StrCat("Mutable", GetFileImmutableClassName(file));
}
}
// Check whether there is any type defined in the proto file that has
// the given class name.
bool ClassNameResolver::HasConflictingClassName(const FileDescriptor* file,
- const TProtoStringType& classname,
+ y_absl::string_view classname,
NameEquality equality_mode) {
for (int i = 0; i < file->enum_type_count(); i++) {
if (CheckNameEquality(file->enum_type(i)->name(), classname) ==
@@ -217,8 +217,12 @@ bool ClassNameResolver::HasConflictingClassName(const FileDescriptor* file,
}
TProtoStringType ClassNameResolver::GetDescriptorClassName(
- const FileDescriptor* descriptor) {
- return GetFileImmutableClassName(descriptor);
+ const FileDescriptor* file) {
+ if (options_.opensource_runtime) {
+ return GetFileImmutableClassName(file);
+ } else {
+ return y_absl::StrCat(GetFileImmutableClassName(file), "InternalDescriptors");
+ }
}
TProtoStringType ClassNameResolver::GetClassName(const FileDescriptor* descriptor,
@@ -228,7 +232,7 @@ TProtoStringType ClassNameResolver::GetClassName(const FileDescriptor* descripto
TProtoStringType ClassNameResolver::GetClassName(const FileDescriptor* descriptor,
bool immutable, bool kotlin) {
- TProtoStringType result = FileJavaPackage(descriptor, immutable);
+ TProtoStringType result = FileJavaPackage(descriptor, immutable, options_);
if (!result.empty()) result += '.';
result += GetFileClassName(descriptor, immutable, kotlin);
return result;
@@ -237,26 +241,26 @@ TProtoStringType ClassNameResolver::GetClassName(const FileDescriptor* descripto
// Get the full name of a Java class by prepending the Java package name
// or outer class name.
TProtoStringType ClassNameResolver::GetClassFullName(
- const TProtoStringType& name_without_package, const FileDescriptor* file,
+ y_absl::string_view name_without_package, const FileDescriptor* file,
bool immutable, bool is_own_file) {
return GetClassFullName(name_without_package, file, immutable, is_own_file,
false);
}
TProtoStringType ClassNameResolver::GetClassFullName(
- const TProtoStringType& name_without_package, const FileDescriptor* file,
+ y_absl::string_view name_without_package, const FileDescriptor* file,
bool immutable, bool is_own_file, bool kotlin) {
TProtoStringType result;
if (is_own_file) {
- result = FileJavaPackage(file, immutable);
+ result = FileJavaPackage(file, immutable, options_);
} else {
result = GetClassName(file, immutable, kotlin);
}
if (!result.empty()) {
- result += '.';
+ y_absl::StrAppend(&result, ".");
}
- result += name_without_package;
- if (kotlin) result += "Kt";
+ y_absl::StrAppend(&result, name_without_package);
+ if (kotlin) y_absl::StrAppend(&result, "Kt");
return result;
}
@@ -298,23 +302,23 @@ TProtoStringType ClassNameResolver::GetClassName(const ServiceDescriptor* descri
// Get the Java Class style full name of a message.
TProtoStringType ClassNameResolver::GetJavaClassFullName(
- const TProtoStringType& name_without_package, const FileDescriptor* file,
+ y_absl::string_view name_without_package, const FileDescriptor* file,
bool immutable) {
return GetJavaClassFullName(name_without_package, file, immutable, false);
}
TProtoStringType ClassNameResolver::GetJavaClassFullName(
- const TProtoStringType& name_without_package, const FileDescriptor* file,
+ y_absl::string_view name_without_package, const FileDescriptor* file,
bool immutable, bool kotlin) {
TProtoStringType result;
if (MultipleJavaFiles(file, immutable)) {
- result = FileJavaPackage(file, immutable);
+ result = FileJavaPackage(file, immutable, options_);
if (!result.empty()) result += '.';
} else {
result = GetClassName(file, immutable, kotlin);
if (!result.empty()) result += '$';
}
- result += StringReplace(name_without_package, ".", "$", true);
+ result += y_absl::StrReplaceAll(name_without_package, {{".", "$"}});
return result;
}
@@ -325,14 +329,15 @@ TProtoStringType ClassNameResolver::GetExtensionIdentifierName(
TProtoStringType ClassNameResolver::GetExtensionIdentifierName(
const FieldDescriptor* descriptor, bool immutable, bool kotlin) {
- return GetClassName(descriptor->containing_type(), immutable, kotlin) + "." +
- descriptor->name();
+ return y_absl::StrCat(
+ GetClassName(descriptor->containing_type(), immutable, kotlin), ".",
+ descriptor->name());
}
TProtoStringType ClassNameResolver::GetKotlinFactoryName(
const Descriptor* descriptor) {
TProtoStringType name = ToCamelCase(descriptor->name(), /* lower_first = */ true);
- return IsForbiddenKotlin(name) ? name + "_" : name;
+ return IsForbiddenKotlin(name) ? y_absl::StrCat(name, "_") : name;
}
TProtoStringType ClassNameResolver::GetJavaImmutableClassName(
@@ -367,14 +372,14 @@ TProtoStringType ClassNameResolver::GetJavaMutableClassName(
TProtoStringType ClassNameResolver::GetDowngradedFileClassName(
const FileDescriptor* file) {
- return "Downgraded" + GetFileClassName(file, false);
+ return y_absl::StrCat("Downgraded", GetFileClassName(file, false));
}
TProtoStringType ClassNameResolver::GetDowngradedClassName(
const Descriptor* descriptor) {
- return FileJavaPackage(descriptor->file()) + "." +
- GetDowngradedFileClassName(descriptor->file()) + "." +
- ClassNameWithoutPackage(descriptor, false);
+ return y_absl::StrCat(FileJavaPackage(descriptor->file(), true, options_), ".",
+ GetDowngradedFileClassName(descriptor->file()), ".",
+ ClassNameWithoutPackage(descriptor, false));
}
} // namespace java
@@ -382,4 +387,4 @@ TProtoStringType ClassNameResolver::GetDowngradedClassName(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.h
index 9744e8739f..3fda3a076e 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/name_resolver.h
@@ -31,13 +31,14 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__
-#include <map>
#include <string>
-#include <google/protobuf/stubs/common.h>
+#include "y_absl/container/flat_hash_map.h"
+#include "google/protobuf/compiler/java/options.h"
+#include "google/protobuf/port.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -58,8 +59,11 @@ enum NameEquality { NO_MATCH, EXACT_EQUAL, EQUAL_IGNORE_CASE };
// Thread-safety note: This class is *not* thread-safe.
class ClassNameResolver {
public:
- ClassNameResolver();
- ~ClassNameResolver();
+ explicit ClassNameResolver(const Options& options = {}) : options_(options) {}
+ ~ClassNameResolver() = default;
+
+ ClassNameResolver(const ClassNameResolver&) = delete;
+ ClassNameResolver& operator=(const ClassNameResolver&) = delete;
// Gets the unqualified outer class name for the file.
TProtoStringType GetFileClassName(const FileDescriptor* file, bool immutable);
@@ -74,7 +78,7 @@ class ClassNameResolver {
// Check whether there is any type defined in the proto file that has
// the given class name.
bool HasConflictingClassName(const FileDescriptor* file,
- const TProtoStringType& classname,
+ y_absl::string_view classname,
NameEquality equality_mode);
// Gets the name of the outer class that holds descriptor information.
@@ -128,25 +132,25 @@ class ClassNameResolver {
// Get the full name of a Java class by prepending the Java package name
// or outer class name.
- TProtoStringType GetClassFullName(const TProtoStringType& name_without_package,
+ TProtoStringType GetClassFullName(y_absl::string_view name_without_package,
const FileDescriptor* file, bool immutable,
bool is_own_file);
- TProtoStringType GetClassFullName(const TProtoStringType& name_without_package,
+ TProtoStringType GetClassFullName(y_absl::string_view name_without_package,
const FileDescriptor* file, bool immutable,
bool is_own_file, bool kotlin);
+ Options options_;
+
private:
// Get the Java Class style full name of a message.
- TProtoStringType GetJavaClassFullName(const TProtoStringType& name_without_package,
+ TProtoStringType GetJavaClassFullName(y_absl::string_view name_without_package,
const FileDescriptor* file, bool immutable);
- TProtoStringType GetJavaClassFullName(const TProtoStringType& name_without_package,
+ TProtoStringType GetJavaClassFullName(y_absl::string_view name_without_package,
const FileDescriptor* file, bool immutable,
bool kotlin);
// Caches the result to provide better performance.
- std::map<const FileDescriptor*, TProtoStringType>
+ y_absl::flat_hash_map<const FileDescriptor*, TProtoStringType>
file_immutable_outer_class_names_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver);
};
} // namespace java
@@ -154,6 +158,6 @@ class ClassNameResolver {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/names.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/names.cc
new file mode 100644
index 0000000000..7b10ec5f17
--- /dev/null
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/names.cc
@@ -0,0 +1,193 @@
+// 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
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+
+#include "google/protobuf/compiler/java/names.h"
+
+#include <string>
+
+#include "y_absl/container/flat_hash_set.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/compiler/java/names.h"
+#include "google/protobuf/compiler/java/options.h"
+#include "google/protobuf/descriptor.pb.h"
+
+// Must be last.
+#include "google/protobuf/port_def.inc"
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace java {
+
+namespace {
+
+const char* DefaultPackage(Options options) {
+ return options.opensource_runtime ? "" : "com.google.protos";
+}
+
+bool IsReservedName(y_absl::string_view name) {
+ static const auto& kReservedNames =
+ *new y_absl::flat_hash_set<y_absl::string_view>({
+ "abstract", "assert", "boolean", "break", "byte",
+ "case", "catch", "char", "class", "const",
+ "continue", "default", "do", "double", "else",
+ "enum", "extends", "final", "finally", "float",
+ "for", "goto", "if", "implements", "import",
+ "instanceof", "int", "interface", "long", "native",
+ "new", "package", "private", "protected", "public",
+ "return", "short", "static", "strictfp", "super",
+ "switch", "synchronized", "this", "throw", "throws",
+ "transient", "try", "void", "volatile", "while",
+ });
+ return kReservedNames.contains(name);
+}
+
+bool IsForbidden(y_absl::string_view field_name) {
+ // Names that should be avoided (in UpperCamelCase format).
+ // Using them will cause the compiler to generate accessors whose names
+ // collide with methods defined in base classes.
+ // Keep this list in sync with specialFieldNames in
+ // java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
+ static const auto& kForbiddenNames =
+ *new y_absl::flat_hash_set<y_absl::string_view>({
+ // java.lang.Object:
+ "Class",
+ // com.google.protobuf.MessageLiteOrBuilder:
+ "DefaultInstanceForType",
+ // com.google.protobuf.MessageLite:
+ "ParserForType",
+ "SerializedSize",
+ // com.google.protobuf.MessageOrBuilder:
+ "AllFields",
+ "DescriptorForType",
+ "InitializationErrorString",
+ "UnknownFields",
+ // obsolete. kept for backwards compatibility of generated code
+ "CachedSize",
+ });
+ return kForbiddenNames.contains(UnderscoresToCamelCase(field_name, true));
+}
+
+TProtoStringType FieldName(const FieldDescriptor* field) {
+ TProtoStringType field_name;
+ // Groups are hacky: The name of the field is just the lower-cased name
+ // of the group type. In Java, though, we would like to retain the original
+ // capitalization of the type name.
+ if (GetType(field) == FieldDescriptor::TYPE_GROUP) {
+ field_name = field->message_type()->name();
+ } else {
+ field_name = field->name();
+ }
+ if (IsForbidden(field_name)) {
+ // Append a trailing "#" to indicate that the name should be decorated to
+ // avoid collision with other names.
+ y_absl::StrAppend(&field_name, "#");
+ }
+ return field_name;
+}
+
+} // namespace
+
+TProtoStringType ClassName(const Descriptor* descriptor) {
+ ClassNameResolver name_resolver;
+ return name_resolver.GetClassName(descriptor, true);
+}
+
+TProtoStringType ClassName(const EnumDescriptor* descriptor) {
+ ClassNameResolver name_resolver;
+ return name_resolver.GetClassName(descriptor, true);
+}
+
+TProtoStringType ClassName(const ServiceDescriptor* descriptor) {
+ ClassNameResolver name_resolver;
+ return name_resolver.GetClassName(descriptor, true);
+}
+
+TProtoStringType ClassName(const FileDescriptor* descriptor) {
+ ClassNameResolver name_resolver;
+ return name_resolver.GetClassName(descriptor, true);
+}
+
+TProtoStringType FileJavaPackage(const FileDescriptor* file, bool immutable,
+ Options options) {
+ TProtoStringType result;
+
+ if (file->options().has_java_package()) {
+ result = file->options().java_package();
+ } else {
+ result = DefaultPackage(options);
+ if (!file->package().empty()) {
+ if (!result.empty()) result += '.';
+ result += file->package();
+ }
+ }
+
+ return result;
+}
+
+TProtoStringType FileJavaPackage(const FileDescriptor* file, Options options) {
+ return FileJavaPackage(file, true /* immutable */, options);
+}
+
+TProtoStringType CapitalizedFieldName(const FieldDescriptor* field) {
+ return UnderscoresToCamelCase(FieldName(field), true);
+}
+
+TProtoStringType UnderscoresToCamelCase(const FieldDescriptor* field) {
+ return UnderscoresToCamelCase(FieldName(field), false);
+}
+
+TProtoStringType UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) {
+ return UnderscoresToCamelCase(FieldName(field), true);
+}
+
+TProtoStringType UnderscoresToCamelCase(const MethodDescriptor* method) {
+ return UnderscoresToCamelCase(method->name(), false);
+}
+
+TProtoStringType UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) {
+ TProtoStringType name = UnderscoresToCamelCase(field);
+ if (IsReservedName(name)) {
+ y_absl::StrAppend(&name, "_");
+ }
+ return name;
+}
+
+} // namespace java
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
+
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/names.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/names.h
index 9aeddc81cc..2f7f1b802e 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/names.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/names.h
@@ -40,6 +40,12 @@
#include <string>
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/compiler/java/options.h"
+
+// Must be last.
+#include "google/protobuf/port_def.inc"
+
namespace google {
namespace protobuf {
@@ -85,7 +91,8 @@ TProtoStringType ClassName(const ServiceDescriptor* descriptor);
//
// Returns:
// Java package name.
-TProtoStringType FileJavaPackage(const FileDescriptor* descriptor);
+TProtoStringType FileJavaPackage(const FileDescriptor* descriptor,
+ Options options = {});
// Requires:
// descriptor != NULL
@@ -93,8 +100,36 @@ TProtoStringType FileJavaPackage(const FileDescriptor* descriptor);
// Capitalized camel case name field name.
TProtoStringType CapitalizedFieldName(const FieldDescriptor* descriptor);
+// Returns:
+// Converts a name to camel-case. If cap_first_letter is true, capitalize the
+// first letter.
+TProtoStringType UnderscoresToCamelCase(y_absl::string_view input,
+ bool cap_next_letter);
+// Requires:
+// field != NULL
+// Returns:
+// Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes
+// "fooBarBaz" or "FooBarBaz", respectively.
+TProtoStringType UnderscoresToCamelCase(const FieldDescriptor* field);
+
+// Requires:
+// method != NULL
+// Returns:
+// Similar, but for method names. (Typically, this merely has the effect
+// of lower-casing the first letter of the name.)
+TProtoStringType UnderscoresToCamelCase(const MethodDescriptor* method);
+
+// Requires:
+// field != NULL
+// Returns:
+// Same as UnderscoresToCamelCase, but checks for reserved keywords
+TProtoStringType UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field);
+
+
} // namespace java
} // namespace compiler
} // namespace protobuf
} // namespace google
+
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/options.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/options.h
index 1454c23206..09364d72d7 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/options.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/options.h
@@ -32,6 +32,11 @@
#define GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__
#include <string>
+#include "util/generic/string.h"
+
+#include "google/protobuf/port_def.inc"
+
+using TProtoStringType = TString;
namespace google {
namespace protobuf {
@@ -54,6 +59,7 @@ struct Options {
// When set, the protoc will generate the current files and all the transitive
// dependencies as lite runtime.
bool enforce_lite;
+ bool opensource_runtime = PROTO2_IS_OSS;
// If true, we should build .meta files and emit @Generated annotations into
// generated code.
bool annotate_code;
@@ -70,4 +76,5 @@ struct Options {
} // namespace protobuf
} // namespace google
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.cc
index adb556a892..d63cdb4eca 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.cc
@@ -32,21 +32,20 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/primitive_field.h>
+#include "google/protobuf/compiler/java/primitive_field.h"
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "y_absl/log/absl_check.h"
+#include "y_absl/log/absl_log.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/io/printer.h"
+#include "google/protobuf/wire_format.h"
namespace google {
namespace protobuf {
@@ -57,71 +56,73 @@ using internal::WireFormat;
namespace {
-void SetPrimitiveVariables(const FieldDescriptor* descriptor,
- int messageBitIndex, int builderBitIndex,
- const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetPrimitiveVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
JavaType javaType = GetJavaType(descriptor);
- (*variables)["type"] = PrimitiveTypeName(javaType);
- (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType);
- (*variables)["kt_type"] = KotlinTypeName(javaType);
- (*variables)["field_type"] = (*variables)["type"];
+ (*variables)["type"] = TProtoStringType(PrimitiveTypeName(javaType));
+ (*variables)["boxed_type"] = TProtoStringType(BoxedPrimitiveTypeName(javaType));
+ (*variables)["kt_type"] = TProtoStringType(KotlinTypeName(javaType));
+ variables->insert({"field_type", (*variables)["type"]});
+ TProtoStringType name = (*variables)["name"];
if (javaType == JAVATYPE_BOOLEAN || javaType == JAVATYPE_DOUBLE ||
javaType == JAVATYPE_FLOAT || javaType == JAVATYPE_INT ||
javaType == JAVATYPE_LONG) {
TProtoStringType capitalized_type = UnderscoresToCamelCase(
PrimitiveTypeName(javaType), /*cap_first_letter=*/true);
(*variables)["field_list_type"] =
- "com.google.protobuf.Internal." + capitalized_type + "List";
- (*variables)["empty_list"] = "empty" + capitalized_type + "List()";
- (*variables)["create_list"] = "new" + capitalized_type + "List()";
+ y_absl::StrCat("com.google.protobuf.Internal.", capitalized_type, "List");
+ (*variables)["empty_list"] =
+ y_absl::StrCat("empty", capitalized_type, "List()");
+ (*variables)["create_list"] =
+ y_absl::StrCat("new", capitalized_type, "List()");
(*variables)["mutable_copy_list"] =
- "mutableCopy(" + (*variables)["name"] + "_)";
+ y_absl::StrCat("mutableCopy(", name, "_)");
(*variables)["name_make_immutable"] =
- (*variables)["name"] + "_.makeImmutable()";
+ y_absl::StrCat(name, "_.makeImmutable()");
(*variables)["repeated_get"] =
- (*variables)["name"] + "_.get" + capitalized_type;
+ y_absl::StrCat(name, "_.get", capitalized_type);
(*variables)["repeated_add"] =
- (*variables)["name"] + "_.add" + capitalized_type;
+ y_absl::StrCat(name, "_.add", capitalized_type);
(*variables)["repeated_set"] =
- (*variables)["name"] + "_.set" + capitalized_type;
+ y_absl::StrCat(name, "_.set", capitalized_type);
} else {
+ TProtoStringType boxed_type = (*variables)["boxed_type"];
(*variables)["field_list_type"] =
- "java.util.List<" + (*variables)["boxed_type"] + ">";
+ y_absl::StrCat("java.util.List<", boxed_type, ">");
(*variables)["create_list"] =
- "new java.util.ArrayList<" + (*variables)["boxed_type"] + ">()";
- (*variables)["mutable_copy_list"] = "new java.util.ArrayList<" +
- (*variables)["boxed_type"] + ">(" +
- (*variables)["name"] + "_)";
+ y_absl::StrCat("new java.util.ArrayList<", boxed_type, ">()");
+ (*variables)["mutable_copy_list"] =
+ y_absl::StrCat("new java.util.ArrayList<", boxed_type, ">(", name, "_)");
(*variables)["empty_list"] = "java.util.Collections.emptyList()";
- (*variables)["name_make_immutable"] =
- (*variables)["name"] + "_ = java.util.Collections.unmodifiableList(" +
- (*variables)["name"] + "_)";
- (*variables)["repeated_get"] = (*variables)["name"] + "_.get";
- (*variables)["repeated_add"] = (*variables)["name"] + "_.add";
- (*variables)["repeated_set"] = (*variables)["name"] + "_.set";
+ (*variables)["name_make_immutable"] = y_absl::StrCat(
+ name, "_ = java.util.Collections.unmodifiableList(", name, "_)");
+ (*variables)["repeated_get"] = y_absl::StrCat(name, "_.get");
+ (*variables)["repeated_add"] = y_absl::StrCat(name, "_.add");
+ (*variables)["repeated_set"] = y_absl::StrCat(name, "_.set");
}
- (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
+ (*variables)["default"] =
+ ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_init"] =
IsDefaultValueJavaDefault(descriptor)
? ""
- : ("= " + ImmutableDefaultValue(descriptor, name_resolver));
- (*variables)["capitalized_type"] =
- GetCapitalizedType(descriptor, /* immutable = */ true);
+ : y_absl::StrCat("= ", ImmutableDefaultValue(descriptor, name_resolver,
+ context->options()));
+ (*variables)["capitalized_type"] = TProtoStringType(GetCapitalizedType(
+ descriptor, /* immutable = */ true, context->options()));
(*variables)["tag"] =
- StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
- (*variables)["tag_size"] = StrCat(
+ y_absl::StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
+ (*variables)["tag_size"] = y_absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
if (IsReferenceType(GetJavaType(descriptor))) {
(*variables)["null_check"] =
- " if (value == null) {\n"
- " throw new NullPointerException();\n"
- " }\n";
+ "if (value == null) { throw new NullPointerException(); }";
} else {
(*variables)["null_check"] = "";
}
@@ -131,52 +132,41 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
(*variables)["kt_deprecation"] =
descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ", name,
+ " is deprecated\") ")
: "";
int fixed_size = FixedSize(GetType(descriptor));
if (fixed_size != -1) {
- (*variables)["fixed_size"] = StrCat(fixed_size);
+ (*variables)["fixed_size"] = y_absl::StrCat(fixed_size);
}
(*variables)["on_changed"] = "onChanged();";
if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
- (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
-
// Note that these have a trailing ";".
- (*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
- (*variables)["set_has_field_bit_builder"] =
- GenerateSetBit(builderBitIndex) + ";";
- (*variables)["clear_has_field_bit_builder"] =
- GenerateClearBit(builderBitIndex) + ";";
-
+ (*variables)["set_has_field_bit_to_local"] =
+ y_absl::StrCat(GenerateSetBitToLocal(messageBitIndex), ";");
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
- (*variables)["set_has_field_bit_message"] = "";
- (*variables)["set_has_field_bit_builder"] = "";
- (*variables)["clear_has_field_bit_builder"] = "";
-
+ (*variables)["set_has_field_bit_to_local"] = "";
switch (descriptor->type()) {
case FieldDescriptor::TYPE_BYTES:
(*variables)["is_field_present_message"] =
- "!" + (*variables)["name"] + "_.isEmpty()";
+ y_absl::StrCat("!", name, "_.isEmpty()");
break;
case FieldDescriptor::TYPE_FLOAT:
(*variables)["is_field_present_message"] =
- "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] +
- "_) != 0";
+ y_absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0");
break;
case FieldDescriptor::TYPE_DOUBLE:
- (*variables)["is_field_present_message"] =
- "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] +
- "_) != 0";
+ (*variables)["is_field_present_message"] = y_absl::StrCat(
+ "java.lang.Double.doubleToRawLongBits(", name, "_) != 0");
break;
default:
- (*variables)["is_field_present_message"] =
- (*variables)["name"] + "_ != " + (*variables)["default"];
+ variables->insert(
+ {"is_field_present_message",
+ y_absl::StrCat(name, "_ != ", (*variables)["default"])});
break;
}
}
@@ -186,17 +176,15 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex);
(*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex);
- // For repeated fields, one bit is used for whether the array is immutable
- // in the parsing constructor.
- (*variables)["get_mutable_bit_parser"] =
- GenerateGetBitMutableLocal(builderBitIndex);
- (*variables)["set_mutable_bit_parser"] =
- GenerateSetBitMutableLocal(builderBitIndex);
-
+ // Always track the presence of a field explicitly in the builder, regardless
+ // of syntax.
+ (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
(*variables)["get_has_field_bit_from_local"] =
GenerateGetBitFromLocal(builderBitIndex);
- (*variables)["set_has_field_bit_to_local"] =
- GenerateSetBitToLocal(messageBitIndex);
+ (*variables)["set_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateSetBit(builderBitIndex), ";");
+ (*variables)["clear_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateClearBit(builderBitIndex), ";");
}
} // namespace
@@ -206,21 +194,30 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ message_bit_index_(messageBitIndex),
+ builder_bit_index_(builderBitIndex),
+ name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
ImmutablePrimitiveFieldGenerator::~ImmutablePrimitiveFieldGenerator() {}
+int ImmutablePrimitiveFieldGenerator::GetMessageBitIndex() const {
+ return message_bit_index_;
+}
+
+int ImmutablePrimitiveFieldGenerator::GetBuilderBitIndex() const {
+ return builder_bit_index_;
+}
+
int ImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const {
return HasHasbit(descriptor_) ? 1 : 0;
}
-int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const {
- return GetNumBitsForMessage();
-}
+int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { return 1; }
void ImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
@@ -235,7 +232,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers(
void ImmutablePrimitiveFieldGenerator::GenerateMembers(
io::Printer* printer) const {
- printer->Print(variables_, "private $field_type$ $name$_;\n");
+ printer->Print(variables_, "private $field_type$ $name$_ = $default$;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
@@ -285,9 +282,9 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder "
"${$set$capitalized_name$$}$($type$ value) {\n"
- "$null_check$"
- " $set_has_field_bit_builder$\n"
+ " $null_check$\n"
" $name$_ = value;\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -318,9 +315,9 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$var $kt_name$: $kt_type$\n"
+ "$kt_deprecation$public var $kt_name$: $kt_type$\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -329,17 +326,18 @@ void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers(
" }\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
if (HasHazzer(descriptor_)) {
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
}
@@ -359,9 +357,8 @@ void ImmutablePrimitiveFieldGenerator::GenerateInitializationCode(
void ImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "$name$_ = $default$;\n"
- "$clear_has_field_bit_builder$\n");
+ // No need to clear the has-bit since we clear the bitField ints all at once.
+ printer->Print(variables_, "$name$_ = $default$;\n");
}
void ImmutablePrimitiveFieldGenerator::GenerateMergingCode(
@@ -381,35 +378,20 @@ void ImmutablePrimitiveFieldGenerator::GenerateMergingCode(
void ImmutablePrimitiveFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
- if (HasHazzer(descriptor_)) {
- if (IsDefaultValueJavaDefault(descriptor_)) {
- printer->Print(variables_,
- "if ($get_has_field_bit_from_local$) {\n"
- " result.$name$_ = $name$_;\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n");
- } else {
- printer->Print(variables_,
- "if ($get_has_field_bit_from_local$) {\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n"
- "result.$name$_ = $name$_;\n");
- }
- } else {
- printer->Print(variables_, "result.$name$_ = $name$_;\n");
+ printer->Print(variables_,
+ "if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$_;\n");
+ if (GetNumBitsForMessage() > 0) {
+ printer->Print(variables_, " $set_has_field_bit_to_local$\n");
}
+ printer->Print("}\n");
}
-void ImmutablePrimitiveFieldGenerator::GenerateParsingCode(
+void ImmutablePrimitiveFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
printer->Print(variables_,
- "$set_has_field_bit_message$\n"
- "$name$_ = input.read$capitalized_type$();\n");
-}
-
-void ImmutablePrimitiveFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- // noop for primitives.
+ "$name$_ = input.read$capitalized_type$();\n"
+ "$set_has_field_bit_builder$\n");
}
void ImmutablePrimitiveFieldGenerator::GenerateSerializationCode(
@@ -467,7 +449,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateEqualsCode(
case JAVATYPE_ENUM:
case JAVATYPE_MESSAGE:
default:
- GOOGLE_LOG(FATAL) << "Can't get here.";
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
break;
}
}
@@ -518,13 +500,13 @@ void ImmutablePrimitiveFieldGenerator::GenerateHashCode(
case JAVATYPE_ENUM:
case JAVATYPE_MESSAGE:
default:
- GOOGLE_LOG(FATAL) << "Can't get here.";
+ Y_ABSL_LOG(FATAL) << "Can't get here.";
break;
}
}
TProtoStringType ImmutablePrimitiveFieldGenerator::GetBoxedType() const {
- return BoxedPrimitiveTypeName(GetJavaType(descriptor_));
+ return TProtoStringType(BoxedPrimitiveTypeName(GetJavaType(descriptor_)));
}
// ===================================================================
@@ -545,7 +527,7 @@ ImmutablePrimitiveOneofFieldGenerator::
void ImmutablePrimitiveOneofFieldGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -568,7 +550,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateMembers(
void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
@@ -591,7 +573,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder "
"${$set$capitalized_name$$}$($type$ value) {\n"
- "$null_check$"
+ " $null_check$\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = value;\n"
" $on_changed$\n"
@@ -614,12 +596,15 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
+void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderClearCode(
+ io::Printer* printer) const {
+ // No-Op: When a primitive field is in a oneof, clearing the oneof clears that
+ // field.
+}
+
void ImmutablePrimitiveOneofFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "if ($has_oneof_case_message$) {\n"
- " result.$oneof_name$_ = $oneof_name$_;\n"
- "}\n");
+ // no-op
}
void ImmutablePrimitiveOneofFieldGenerator::GenerateMergingCode(
@@ -628,7 +613,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateMergingCode(
"set$capitalized_name$(other.get$capitalized_name$());\n");
}
-void ImmutablePrimitiveOneofFieldGenerator::GenerateParsingCode(
+void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
printer->Print(variables_,
"$oneof_name$_ = input.read$capitalized_type$();\n"
@@ -677,11 +662,8 @@ RepeatedImmutablePrimitiveFieldGenerator::
int messageBitIndex,
int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
- SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
- context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
-}
+ : ImmutablePrimitiveFieldGenerator(descriptor, messageBitIndex,
+ builderBitIndex, context) {}
RepeatedImmutablePrimitiveFieldGenerator::
~RepeatedImmutablePrimitiveFieldGenerator() {}
@@ -710,7 +692,8 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers(
void RepeatedImmutablePrimitiveFieldGenerator::GenerateMembers(
io::Printer* printer) const {
- printer->Print(variables_, "private $field_list_type$ $name$_;\n");
+ printer->Print(variables_, "@SuppressWarnings(\"serial\")\n"
+ "private $field_list_type$ $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
@@ -760,7 +743,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
" if (!$get_mutable_bit_builder$) {\n"
" $name$_ = $mutable_copy_list$;\n"
" $set_mutable_bit_builder$;\n"
- " }\n"
+ " }\n"
"}\n");
// Note: We return an unmodifiable list because otherwise the caller
@@ -795,7 +778,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$ value) {\n"
- "$null_check$"
+ " $null_check$\n"
" ensure$capitalized_name$IsMutable();\n"
" $repeated_set$(index, value);\n"
" $on_changed$\n"
@@ -807,7 +790,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder "
"${$add$capitalized_name$$}$($type$ value) {\n"
- "$null_check$"
+ " $null_check$\n"
" ensure$capitalized_name$IsMutable();\n"
" $repeated_add$(value);\n"
" $on_changed$\n"
@@ -849,12 +832,12 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$ public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -863,70 +846,70 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers(
" )\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -945,9 +928,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateInitializationCode(
void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "$name$_ = $empty_list$;\n"
- "$clear_mutable_bit_builder$;\n");
+ printer->Print(variables_, "$name$_ = $empty_list$;\n");
}
void RepeatedImmutablePrimitiveFieldGenerator::GenerateMergingCode(
@@ -982,38 +963,24 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuildingCode(
"result.$name$_ = $name$_;\n");
}
-void RepeatedImmutablePrimitiveFieldGenerator::GenerateParsingCode(
+void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
printer->Print(variables_,
- "if (!$get_mutable_bit_parser$) {\n"
- " $name$_ = $create_list$;\n"
- " $set_mutable_bit_parser$;\n"
- "}\n"
- "$repeated_add$(input.read$capitalized_type$());\n");
+ "$type$ v = input.read$capitalized_type$();\n"
+ "ensure$capitalized_name$IsMutable();\n"
+ "$repeated_add$(v);\n");
}
-void RepeatedImmutablePrimitiveFieldGenerator::GenerateParsingCodeFromPacked(
- io::Printer* printer) const {
- printer->Print(
- variables_,
- "int length = input.readRawVarint32();\n"
- "int limit = input.pushLimit(length);\n"
- "if (!$get_mutable_bit_parser$ && input.getBytesUntilLimit() > 0) {\n"
- " $name$_ = $create_list$;\n"
- " $set_mutable_bit_parser$;\n"
- "}\n"
- "while (input.getBytesUntilLimit() > 0) {\n"
- " $repeated_add$(input.read$capitalized_type$());\n"
- "}\n"
- "input.popLimit(limit);\n");
-}
-
-void RepeatedImmutablePrimitiveFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
+void RepeatedImmutablePrimitiveFieldGenerator::
+ GenerateBuilderParsingCodeFromPacked(io::Printer* printer) const {
printer->Print(variables_,
- "if ($get_mutable_bit_parser$) {\n"
- " $name_make_immutable$; // C\n"
- "}\n");
+ "int length = input.readRawVarint32();\n"
+ "int limit = input.pushLimit(length);\n"
+ "ensure$capitalized_name$IsMutable();\n"
+ "while (input.getBytesUntilLimit() > 0) {\n"
+ " $repeated_add$(input.read$capitalized_type$());\n"
+ "}\n"
+ "input.popLimit(limit);\n");
}
void RepeatedImmutablePrimitiveFieldGenerator::GenerateSerializationCode(
@@ -1102,7 +1069,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateHashCode(
}
TProtoStringType RepeatedImmutablePrimitiveFieldGenerator::GetBoxedType() const {
- return BoxedPrimitiveTypeName(GetJavaType(descriptor_));
+ return TProtoStringType(BoxedPrimitiveTypeName(GetJavaType(descriptor_)));
}
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.h
index a2c0041388..dae385afa6 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field.h
@@ -35,10 +35,9 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -62,10 +61,16 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator {
int messageBitIndex,
int builderBitIndex,
Context* context);
+ ImmutablePrimitiveFieldGenerator(const ImmutablePrimitiveFieldGenerator&) =
+ delete;
+ ImmutablePrimitiveFieldGenerator& operator=(
+ const ImmutablePrimitiveFieldGenerator&) = delete;
~ImmutablePrimitiveFieldGenerator() override;
// implements ImmutableFieldGenerator
// ---------------------------------------
+ int GetMessageBitIndex() const override;
+ int GetBuilderBitIndex() const override;
int GetNumBitsForMessage() const override;
int GetNumBitsForBuilder() const override;
void GenerateInterfaceMembers(io::Printer* printer) const override;
@@ -75,8 +80,7 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -89,11 +93,10 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ int message_bit_index_;
+ int builder_bit_index_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
ClassNameResolver* name_resolver_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveFieldGenerator);
};
class ImmutablePrimitiveOneofFieldGenerator
@@ -102,26 +105,32 @@ class ImmutablePrimitiveOneofFieldGenerator
ImmutablePrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
int builderBitIndex, Context* context);
+ ImmutablePrimitiveOneofFieldGenerator(
+ const ImmutablePrimitiveOneofFieldGenerator&) = delete;
+ ImmutablePrimitiveOneofFieldGenerator& operator=(
+ const ImmutablePrimitiveOneofFieldGenerator&) = delete;
~ImmutablePrimitiveOneofFieldGenerator() override;
void GenerateMembers(io::Printer* printer) const override;
void GenerateBuilderMembers(io::Printer* printer) const override;
+ void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldGenerator);
};
class RepeatedImmutablePrimitiveFieldGenerator
- : public ImmutableFieldGenerator {
+ : public ImmutablePrimitiveFieldGenerator {
public:
explicit RepeatedImmutablePrimitiveFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, Context* context);
+ RepeatedImmutablePrimitiveFieldGenerator(
+ const RepeatedImmutablePrimitiveFieldGenerator&) = delete;
+ RepeatedImmutablePrimitiveFieldGenerator& operator=(
+ const RepeatedImmutablePrimitiveFieldGenerator&) = delete;
~RepeatedImmutablePrimitiveFieldGenerator() override;
// implements ImmutableFieldGenerator ---------------------------------------
@@ -134,9 +143,9 @@ class RepeatedImmutablePrimitiveFieldGenerator
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingCodeFromPacked(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCodeFromPacked(
+ io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -146,13 +155,6 @@ class RepeatedImmutablePrimitiveFieldGenerator
void GenerateKotlinDslMembers(io::Printer* printer) const override;
TProtoStringType GetBoxedType() const override;
-
- private:
- const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
- ClassNameResolver* name_resolver_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.cc
index 5fd47c47e1..0d4c633456 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.cc
@@ -32,21 +32,19 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/primitive_field_lite.h>
+#include "google/protobuf/compiler/java/primitive_field_lite.h"
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "y_absl/log/absl_check.h"
+#include "y_absl/strings/ascii.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/wire_format.h"
namespace google {
namespace protobuf {
@@ -65,65 +63,70 @@ bool EnableExperimentalRuntimeForLite() {
#endif // !PROTOBUF_EXPERIMENT
}
-void SetPrimitiveVariables(const FieldDescriptor* descriptor,
- int messageBitIndex, int builderBitIndex,
- const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetPrimitiveVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
JavaType javaType = GetJavaType(descriptor);
- (*variables)["type"] = PrimitiveTypeName(javaType);
- (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType);
- (*variables)["kt_type"] = KotlinTypeName(javaType);
- (*variables)["field_type"] = (*variables)["type"];
- (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
- (*variables)["capitalized_type"] =
- GetCapitalizedType(descriptor, /* immutable = */ true);
+ (*variables)["type"] = TProtoStringType(PrimitiveTypeName(javaType));
+ (*variables)["boxed_type"] = TProtoStringType(BoxedPrimitiveTypeName(javaType));
+ (*variables)["kt_type"] = TProtoStringType(KotlinTypeName(javaType));
+ variables->insert({"field_type", (*variables)["type"]});
+ (*variables)["default"] =
+ ImmutableDefaultValue(descriptor, name_resolver, context->options());
+ (*variables)["capitalized_type"] = TProtoStringType(GetCapitalizedType(
+ descriptor, /* immutable = */ true, context->options()));
(*variables)["tag"] =
- StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
- (*variables)["tag_size"] = StrCat(
+ y_absl::StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
+ (*variables)["tag_size"] = y_absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
TProtoStringType capitalized_type = UnderscoresToCamelCase(
PrimitiveTypeName(javaType), true /* cap_next_letter */);
+ TProtoStringType name = (*variables)["name"];
switch (javaType) {
case JAVATYPE_INT:
case JAVATYPE_LONG:
case JAVATYPE_FLOAT:
case JAVATYPE_DOUBLE:
case JAVATYPE_BOOLEAN:
- (*variables)["field_list_type"] =
- "com.google.protobuf.Internal." + capitalized_type + "List";
- (*variables)["empty_list"] = "empty" + capitalized_type + "List()";
+ (*variables)["field_list_type"] = y_absl::StrCat(
+ "com.google.protobuf.Internal.", capitalized_type, "List");
+ (*variables)["empty_list"] =
+ y_absl::StrCat("empty", capitalized_type, "List()");
(*variables)["make_name_unmodifiable"] =
- (*variables)["name"] + "_.makeImmutable()";
+ y_absl::StrCat(name, "_.makeImmutable()");
(*variables)["repeated_get"] =
- (*variables)["name"] + "_.get" + capitalized_type;
+ y_absl::StrCat(name, "_.get", capitalized_type);
(*variables)["repeated_add"] =
- (*variables)["name"] + "_.add" + capitalized_type;
+ y_absl::StrCat(name, "_.add", capitalized_type);
(*variables)["repeated_set"] =
- (*variables)["name"] + "_.set" + capitalized_type;
+ y_absl::StrCat(name, "_.set", capitalized_type);
(*variables)["visit_type"] = capitalized_type;
- (*variables)["visit_type_list"] = "visit" + capitalized_type + "List";
+ (*variables)["visit_type_list"] =
+ y_absl::StrCat("visit", capitalized_type, "List");
break;
default:
- (*variables)["field_list_type"] =
- "com.google.protobuf.Internal.ProtobufList<" +
- (*variables)["boxed_type"] + ">";
+ variables->insert(
+ {"field_list_type",
+ y_absl::StrCat("com.google.protobuf.Internal.ProtobufList<",
+ (*variables)["boxed_type"], ">")});
(*variables)["empty_list"] = "emptyProtobufList()";
(*variables)["make_name_unmodifiable"] =
- (*variables)["name"] + "_.makeImmutable()";
- (*variables)["repeated_get"] = (*variables)["name"] + "_.get";
- (*variables)["repeated_add"] = (*variables)["name"] + "_.add";
- (*variables)["repeated_set"] = (*variables)["name"] + "_.set";
+ y_absl::StrCat(name, "_.makeImmutable()");
+ (*variables)["repeated_get"] = y_absl::StrCat(name, "_.get");
+ (*variables)["repeated_add"] = y_absl::StrCat(name, "_.add");
+ (*variables)["repeated_set"] = y_absl::StrCat(name, "_.set");
(*variables)["visit_type"] = "ByteString";
(*variables)["visit_type_list"] = "visitList";
}
if (javaType == JAVATYPE_BYTES) {
(*variables)["bytes_default"] =
- ToUpper((*variables)["name"]) + "_DEFAULT_VALUE";
+ y_absl::StrCat(y_absl::AsciiStrToUpper(name), "_DEFAULT_VALUE");
}
if (IsReferenceType(javaType)) {
@@ -140,12 +143,12 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
(*variables)["kt_deprecation"] =
descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ", name,
+ " is deprecated\") ")
: "";
int fixed_size = FixedSize(GetType(descriptor));
if (fixed_size != -1) {
- (*variables)["fixed_size"] = StrCat(fixed_size);
+ (*variables)["fixed_size"] = y_absl::StrCat(fixed_size);
}
if (HasHasbit(descriptor)) {
@@ -154,9 +157,9 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateSetBit(messageBitIndex), ";");
(*variables)["clear_has_field_bit_message"] =
- GenerateClearBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateClearBit(messageBitIndex), ";");
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
@@ -166,21 +169,20 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
switch (descriptor->type()) {
case FieldDescriptor::TYPE_BYTES:
(*variables)["is_field_present_message"] =
- "!" + (*variables)["name"] + "_.isEmpty()";
+ y_absl::StrCat("!", name, "_.isEmpty()");
break;
case FieldDescriptor::TYPE_FLOAT:
(*variables)["is_field_present_message"] =
- "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] +
- "_) != 0";
+ y_absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0");
break;
case FieldDescriptor::TYPE_DOUBLE:
- (*variables)["is_field_present_message"] =
- "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] +
- "_) != 0";
+ (*variables)["is_field_present_message"] = y_absl::StrCat(
+ "java.lang.Double.doubleToRawLongBits(", name, "_) != 0");
break;
default:
- (*variables)["is_field_present_message"] =
- (*variables)["name"] + "_ != " + (*variables)["default"];
+ variables->insert(
+ {"is_field_present_message",
+ y_absl::StrCat(name, "_ != ", (*variables)["default"])});
break;
}
}
@@ -189,6 +191,9 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
GenerateGetBitFromLocal(builderBitIndex);
(*variables)["set_has_field_bit_to_local"] =
GenerateSetBitToLocal(messageBitIndex);
+ // Annotations often use { and } variables to denote ranges.
+ (*variables)["{"] = "";
+ (*variables)["}"] = "";
}
} // namespace
@@ -199,10 +204,11 @@ ImmutablePrimitiveFieldLiteGenerator::ImmutablePrimitiveFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
+ context_(context),
name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
ImmutablePrimitiveFieldLiteGenerator::~ImmutablePrimitiveFieldLiteGenerator() {}
@@ -219,7 +225,9 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateInterfaceMembers(
"$deprecation$boolean has$capitalized_name$();\n");
}
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
- printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n");
+ printer->Print(variables_,
+ "$deprecation$$type$ ${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
@@ -231,6 +239,20 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
variables_,
"private static final $field_type$ $bytes_default$ = $default$;\n");
}
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "@com.google.protobuf.ProtoField(\n"
+ " fieldNumber=$number$,\n"
+ " type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
+ " isRequired=$required$)\n");
+ if (HasHazzer(descriptor_)) {
+ printer->Print(variables_,
+ "@com.google.protobuf.ProtoPresenceCheckedField(\n"
+ " presenceBitsId=$bit_field_id$,\n"
+ " mask=$bit_field_mask$)\n");
+ }
+ }
printer->Print(variables_, "private $field_type$ $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
@@ -325,7 +347,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$kt_deprecation$var $kt_name$: $kt_type$\n"
+ "$kt_deprecation$public var $kt_name$: $kt_type$\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -334,17 +356,18 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers(
" }\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
if (HasHazzer(descriptor_)) {
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
}
@@ -371,7 +394,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateInitializationCode(
}
TProtoStringType ImmutablePrimitiveFieldLiteGenerator::GetBoxedType() const {
- return BoxedPrimitiveTypeName(GetJavaType(descriptor_));
+ return TProtoStringType(BoxedPrimitiveTypeName(GetJavaType(descriptor_)));
}
// ===================================================================
@@ -393,7 +416,7 @@ ImmutablePrimitiveOneofFieldLiteGenerator::
void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -441,7 +464,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateFieldInfo(
void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -492,7 +515,7 @@ RepeatedImmutablePrimitiveFieldLiteGenerator::
name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
RepeatedImmutablePrimitiveFieldLiteGenerator::
@@ -507,13 +530,17 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateInterfaceMembers(
WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"$deprecation$java.util.List<$boxed_type$> "
- "get$capitalized_name$List();\n");
+ "${$get$capitalized_name$List$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT);
printer->Print(variables_,
- "$deprecation$int get$capitalized_name$Count();\n");
+ "$deprecation$int ${$get$capitalized_name$Count$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER);
- printer->Print(variables_,
- "$deprecation$$type$ get$capitalized_name$(int index);\n");
+ printer->Print(
+ variables_,
+ "$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
@@ -671,12 +698,12 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$ public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -685,70 +712,70 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers(
" )\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -769,7 +796,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateInitializationCode(
}
TProtoStringType RepeatedImmutablePrimitiveFieldLiteGenerator::GetBoxedType() const {
- return BoxedPrimitiveTypeName(GetJavaType(descriptor_));
+ return TProtoStringType(BoxedPrimitiveTypeName(GetJavaType(descriptor_)));
}
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.h
index 1eaf8d8e09..48090484ee 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/primitive_field_lite.h
@@ -36,10 +36,9 @@
#define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -62,6 +61,10 @@ class ImmutablePrimitiveFieldLiteGenerator
public:
explicit ImmutablePrimitiveFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context);
+ ImmutablePrimitiveFieldLiteGenerator(
+ const ImmutablePrimitiveFieldLiteGenerator&) = delete;
+ ImmutablePrimitiveFieldLiteGenerator& operator=(
+ const ImmutablePrimitiveFieldLiteGenerator&) = delete;
~ImmutablePrimitiveFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator
@@ -79,12 +82,10 @@ class ImmutablePrimitiveFieldLiteGenerator
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
const int messageBitIndex_;
+ Context* context_;
ClassNameResolver* name_resolver_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveFieldLiteGenerator);
};
class ImmutablePrimitiveOneofFieldLiteGenerator
@@ -93,6 +94,10 @@ class ImmutablePrimitiveOneofFieldLiteGenerator
ImmutablePrimitiveOneofFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context);
+ ImmutablePrimitiveOneofFieldLiteGenerator(
+ const ImmutablePrimitiveOneofFieldLiteGenerator&) = delete;
+ ImmutablePrimitiveOneofFieldLiteGenerator& operator=(
+ const ImmutablePrimitiveOneofFieldLiteGenerator&) = delete;
~ImmutablePrimitiveOneofFieldLiteGenerator() override;
void GenerateMembers(io::Printer* printer) const override;
@@ -100,9 +105,6 @@ class ImmutablePrimitiveOneofFieldLiteGenerator
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16_t>* output) const override;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldLiteGenerator);
};
class RepeatedImmutablePrimitiveFieldLiteGenerator
@@ -110,6 +112,10 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator
public:
explicit RepeatedImmutablePrimitiveFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context);
+ RepeatedImmutablePrimitiveFieldLiteGenerator(
+ const RepeatedImmutablePrimitiveFieldLiteGenerator&) = delete;
+ RepeatedImmutablePrimitiveFieldLiteGenerator& operator=(
+ const RepeatedImmutablePrimitiveFieldLiteGenerator&) = delete;
~RepeatedImmutablePrimitiveFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator ------------------------------------
@@ -126,11 +132,9 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
Context* context_;
ClassNameResolver* name_resolver_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldLiteGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/service.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/service.cc
index 602ab4c7b9..3f6d896c6d 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/service.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/service.cc
@@ -32,17 +32,18 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/service.h>
+#include "google/protobuf/compiler/java/service.h"
-#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 "y_absl/log/absl_log.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/io/printer.h"
// Must be last.
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -68,6 +69,10 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
WriteServiceDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true);
+ if (!context_->options().opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
+ }
+
printer->Print(
"public $static$ abstract class $classname$\n"
" implements com.google.protobuf.Service {\n",
@@ -92,7 +97,7 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
" return $file$.getDescriptor().getServices().get($index$);\n"
"}\n",
"file", name_resolver_->GetImmutableClassName(descriptor_->file()),
- "index", StrCat(descriptor_->index()));
+ "index", y_absl::StrCat(descriptor_->index()));
GenerateGetDescriptorForType(printer);
// Generate more stuff.
@@ -211,8 +216,8 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- std::map<TProtoStringType, TProtoStringType> vars;
- vars["index"] = StrCat(i);
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
+ vars["index"] = y_absl::StrCat(i);
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
@@ -258,8 +263,8 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod(
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- std::map<TProtoStringType, TProtoStringType> vars;
- vars["index"] = StrCat(i);
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
+ vars["index"] = y_absl::StrCat(i);
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
@@ -303,8 +308,8 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- std::map<TProtoStringType, TProtoStringType> vars;
- vars["index"] = StrCat(i);
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
+ vars["index"] = y_absl::StrCat(i);
vars["type"] =
(which == REQUEST)
? name_resolver_->GetImmutableClassName(method->input_type())
@@ -358,8 +363,8 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
printer->Print(" {\n");
printer->Indent();
- std::map<TProtoStringType, TProtoStringType> vars;
- vars["index"] = StrCat(i);
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
+ vars["index"] = y_absl::StrCat(i);
vars["output"] = GetOutput(method);
printer->Print(vars,
"channel.callMethod(\n"
@@ -422,8 +427,8 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
printer->Print(" {\n");
printer->Indent();
- std::map<TProtoStringType, TProtoStringType> vars;
- vars["index"] = StrCat(i);
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
+ vars["index"] = y_absl::StrCat(i);
vars["output"] = GetOutput(method);
printer->Print(vars,
"return ($output$) channel.callBlockingMethod(\n"
@@ -445,7 +450,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
void ImmutableServiceGenerator::GenerateMethodSignature(
io::Printer* printer, const MethodDescriptor* method,
IsAbstract is_abstract) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["name"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
@@ -459,7 +464,7 @@ void ImmutableServiceGenerator::GenerateMethodSignature(
void ImmutableServiceGenerator::GenerateBlockingMethodSignature(
io::Printer* printer, const MethodDescriptor* method) {
- std::map<TProtoStringType, TProtoStringType> vars;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> vars;
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
@@ -476,4 +481,4 @@ void ImmutableServiceGenerator::GenerateBlockingMethodSignature(
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/service.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/service.h
index a03a3de561..a59223c7cb 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/service.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/service.h
@@ -35,8 +35,7 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__
-#include <map>
-#include <google/protobuf/descriptor.h>
+#include "google/protobuf/descriptor.h"
namespace google {
namespace protobuf {
@@ -60,6 +59,8 @@ namespace java {
class ServiceGenerator {
public:
explicit ServiceGenerator(const ServiceDescriptor* descriptor);
+ ServiceGenerator(const ServiceGenerator&) = delete;
+ ServiceGenerator& operator=(const ServiceGenerator&) = delete;
virtual ~ServiceGenerator();
virtual void Generate(io::Printer* printer) = 0;
@@ -69,15 +70,15 @@ class ServiceGenerator {
protected:
const ServiceDescriptor* descriptor_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator);
};
class ImmutableServiceGenerator : public ServiceGenerator {
public:
ImmutableServiceGenerator(const ServiceDescriptor* descriptor,
Context* context);
+ ImmutableServiceGenerator(const ImmutableServiceGenerator&) = delete;
+ ImmutableServiceGenerator& operator=(const ImmutableServiceGenerator&) =
+ delete;
~ImmutableServiceGenerator() override;
void Generate(io::Printer* printer) override;
@@ -128,7 +129,6 @@ class ImmutableServiceGenerator : public ServiceGenerator {
Context* context_;
ClassNameResolver* name_resolver_;
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableServiceGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.cc
index 0a8b8edb01..79c6afab4e 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.cc
@@ -30,19 +30,20 @@
// Author: xiaofeng@google.com (Feng Xiao)
-#include <google/protobuf/compiler/java/shared_code_generator.h>
+#include "google/protobuf/compiler/java/shared_code_generator.h"
#include <memory>
-#include <google/protobuf/compiler/code_generator.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/io/zero_copy_stream.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/compiler/java/helpers.h>
-#include <google/protobuf/compiler/java/name_resolver.h>
-#include <google/protobuf/compiler/java/names.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "y_absl/strings/escaping.h"
+#include "google/protobuf/compiler/code_generator.h"
+#include "google/protobuf/compiler/java/helpers.h"
+#include "google/protobuf/compiler/java/name_resolver.h"
+#include "google/protobuf/compiler/java/names.h"
+#include "google/protobuf/compiler/retention.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/descriptor.pb.h"
+#include "google/protobuf/io/printer.h"
+#include "google/protobuf/io/zero_copy_stream.h"
namespace google {
namespace protobuf {
@@ -51,20 +52,22 @@ namespace java {
SharedCodeGenerator::SharedCodeGenerator(const FileDescriptor* file,
const Options& options)
- : name_resolver_(new ClassNameResolver), file_(file), options_(options) {}
+ : name_resolver_(new ClassNameResolver(options)),
+ file_(file),
+ options_(options) {}
SharedCodeGenerator::~SharedCodeGenerator() {}
void SharedCodeGenerator::Generate(
GeneratorContext* context, std::vector<TProtoStringType>* file_list,
std::vector<TProtoStringType>* annotation_file_list) {
- TProtoStringType java_package = FileJavaPackage(file_);
+ TProtoStringType java_package = FileJavaPackage(file_, true, options_);
TProtoStringType package_dir = JavaPackageToDir(java_package);
if (HasDescriptorMethods(file_, options_.enforce_lite)) {
// Generate descriptors.
TProtoStringType classname = name_resolver_->GetDescriptorClassName(file_);
- TProtoStringType filename = package_dir + classname + ".java";
+ TProtoStringType filename = y_absl::StrCat(package_dir, classname, ".java");
file_list->push_back(filename);
std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename));
GeneratedCodeInfo annotations;
@@ -73,8 +76,8 @@ void SharedCodeGenerator::Generate(
std::unique_ptr<io::Printer> printer(
new io::Printer(output.get(), '$',
options_.annotate_code ? &annotation_collector : NULL));
- TProtoStringType info_relative_path = classname + ".java.pb.meta";
- TProtoStringType info_full_path = filename + ".pb.meta";
+ TProtoStringType info_relative_path = y_absl::StrCat(classname, ".java.pb.meta");
+ TProtoStringType info_full_path = y_absl::StrCat(filename, ".pb.meta");
printer->Print(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n"
@@ -87,7 +90,12 @@ void SharedCodeGenerator::Generate(
"package", java_package);
}
PrintGeneratedAnnotation(printer.get(), '$',
- options_.annotate_code ? info_relative_path : "");
+ options_.annotate_code ? info_relative_path : "",
+ options_);
+
+ if (!options_.opensource_runtime) {
+ printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
+ }
printer->Print(
"public final class $classname$ {\n"
" public static com.google.protobuf.Descriptors.FileDescriptor\n"
@@ -127,8 +135,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
// This makes huge bytecode files and can easily hit the compiler's internal
// code size limits (error "code to large"). String literals are apparently
// embedded raw, which is what we want.
- FileDescriptorProto file_proto;
- file_->CopyTo(&file_proto);
+ FileDescriptorProto file_proto = StripSourceRetentionOptions(*file_);
TProtoStringType file_data;
file_proto.SerializeToString(&file_data);
@@ -152,7 +159,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
}
}
printer->Print("\"$data$\"", "data",
- CEscape(file_data.substr(i, kBytesPerLine)));
+ y_absl::CEscape(file_data.substr(i, kBytesPerLine)));
}
printer->Outdent();
@@ -163,14 +170,14 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
std::vector<std::pair<TProtoStringType, TProtoStringType> > dependencies;
for (int i = 0; i < file_->dependency_count(); i++) {
TProtoStringType filename = file_->dependency(i)->name();
- TProtoStringType package = FileJavaPackage(file_->dependency(i));
+ TProtoStringType package = FileJavaPackage(file_->dependency(i), true, options_);
TProtoStringType classname =
name_resolver_->GetDescriptorClassName(file_->dependency(i));
TProtoStringType full_name;
if (package.empty()) {
full_name = classname;
} else {
- full_name = package + "." + classname;
+ full_name = y_absl::StrCat(package, ".", classname);
}
dependencies.push_back(std::make_pair(filename, full_name));
}
@@ -180,13 +187,15 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
printer->Print(
"descriptor = com.google.protobuf.Descriptors.FileDescriptor\n"
" .internalBuildGeneratedFileFrom(descriptorData,\n");
- printer->Print(
- " new com.google.protobuf.Descriptors.FileDescriptor[] {\n");
+ if (options_.opensource_runtime) {
+ printer->Print(
+ " new com.google.protobuf.Descriptors.FileDescriptor[] {\n");
- for (int i = 0; i < dependencies.size(); i++) {
- const TProtoStringType& dependency = dependencies[i].second;
- printer->Print(" $dependency$.getDescriptor(),\n", "dependency",
- dependency);
+ for (int i = 0; i < dependencies.size(); i++) {
+ const TProtoStringType& dependency = dependencies[i].second;
+ printer->Print(" $dependency$.getDescriptor(),\n", "dependency",
+ dependency);
+ }
}
printer->Print(" });\n");
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.h
index 026124715a..b49214bc13 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/shared_code_generator.h
@@ -39,8 +39,8 @@
#include <string>
#include <vector>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/compiler/java/options.h>
+#include "google/protobuf/compiler/java/options.h"
+#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@@ -67,6 +67,8 @@ namespace java {
class SharedCodeGenerator {
public:
SharedCodeGenerator(const FileDescriptor* file, const Options& options);
+ SharedCodeGenerator(const SharedCodeGenerator&) = delete;
+ SharedCodeGenerator& operator=(const SharedCodeGenerator&) = delete;
~SharedCodeGenerator();
void Generate(GeneratorContext* generator_context,
@@ -79,7 +81,6 @@ class SharedCodeGenerator {
std::unique_ptr<ClassNameResolver> name_resolver_;
const FileDescriptor* file_;
const Options options_;
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SharedCodeGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.cc
index 066e3bd701..62581f65b9 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.cc
@@ -33,21 +33,20 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/string_field.h>
+#include "google/protobuf/compiler/java/string_field.h"
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "y_absl/container/flat_hash_map.h"
+#include "y_absl/log/absl_check.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/io/printer.h"
+#include "google/protobuf/wire_format.h"
namespace google {
namespace protobuf {
@@ -59,86 +58,78 @@ using internal::WireFormatLite;
namespace {
-void SetPrimitiveVariables(const FieldDescriptor* descriptor,
- int messageBitIndex, int builderBitIndex,
- const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetPrimitiveVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
- (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY";
+ (*variables)["empty_list"] =
+ "com.google.protobuf.LazyStringArrayList.emptyList()";
- (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
- (*variables)["default_init"] =
- "= " + ImmutableDefaultValue(descriptor, name_resolver);
+ (*variables)["default"] =
+ ImmutableDefaultValue(descriptor, name_resolver, context->options());
+ (*variables)["default_init"] = y_absl::StrCat(
+ "= ",
+ ImmutableDefaultValue(descriptor, name_resolver, context->options()));
(*variables)["capitalized_type"] = "String";
(*variables)["tag"] =
- StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
- (*variables)["tag_size"] = StrCat(
+ y_absl::StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
+ (*variables)["tag_size"] = y_absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
(*variables)["null_check"] =
- " if (value == null) {\n"
- " throw new NullPointerException();\n"
- " }\n";
- (*variables)["isStringEmpty"] = "com.google.protobuf.GeneratedMessage" +
- GeneratedCodeVersionSuffix() +
- ".isStringEmpty";
- (*variables)["writeString"] = "com.google.protobuf.GeneratedMessage" +
- GeneratedCodeVersionSuffix() + ".writeString";
- (*variables)["computeStringSize"] = "com.google.protobuf.GeneratedMessage" +
- GeneratedCodeVersionSuffix() +
- ".computeStringSize";
+ "if (value == null) { throw new NullPointerException(); }";
+ (*variables)["isStringEmpty"] =
+ y_absl::StrCat("com.google.protobuf.GeneratedMessage",
+ GeneratedCodeVersionSuffix(), ".isStringEmpty");
+ (*variables)["writeString"] =
+ y_absl::StrCat("com.google.protobuf.GeneratedMessage",
+ GeneratedCodeVersionSuffix(), ".writeString");
+ (*variables)["computeStringSize"] =
+ y_absl::StrCat("com.google.protobuf.GeneratedMessage",
+ GeneratedCodeVersionSuffix(), ".computeStringSize");
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
(*variables)["on_changed"] = "onChanged();";
if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
- (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
+ (*variables)["set_has_field_bit_to_local"] =
+ GenerateSetBitToLocal(messageBitIndex);
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
- (*variables)["set_has_field_bit_builder"] =
- GenerateSetBit(builderBitIndex) + ";";
- (*variables)["clear_has_field_bit_builder"] =
- GenerateClearBit(builderBitIndex) + ";";
+ y_absl::StrCat(GenerateSetBit(messageBitIndex), ";");
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
+ (*variables)["get_has_field_bit_message"] = "";
+ (*variables)["set_has_field_bit_to_local"] = "";
(*variables)["set_has_field_bit_message"] = "";
- (*variables)["set_has_field_bit_builder"] = "";
- (*variables)["clear_has_field_bit_builder"] = "";
- (*variables)["is_field_present_message"] =
- "!" + (*variables)["isStringEmpty"] + "(" + (*variables)["name"] + "_)";
+ variables->insert({"is_field_present_message",
+ y_absl::StrCat("!", (*variables)["isStringEmpty"], "(",
+ (*variables)["name"], "_)")});
}
- // For repeated builders, one bit is used for whether the array is immutable.
- (*variables)["get_mutable_bit_builder"] = GenerateGetBit(builderBitIndex);
- (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex);
- (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex);
-
- // For repeated fields, one bit is used for whether the array is immutable
- // in the parsing constructor.
- (*variables)["get_mutable_bit_parser"] =
- GenerateGetBitMutableLocal(builderBitIndex);
- (*variables)["set_mutable_bit_parser"] =
- GenerateSetBitMutableLocal(builderBitIndex);
-
+ (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
(*variables)["get_has_field_bit_from_local"] =
GenerateGetBitFromLocal(builderBitIndex);
- (*variables)["set_has_field_bit_to_local"] =
- GenerateSetBitToLocal(messageBitIndex);
+ (*variables)["set_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateSetBit(builderBitIndex), ";");
+ (*variables)["clear_has_field_bit_builder"] =
+ y_absl::StrCat(GenerateClearBit(builderBitIndex), ";");
}
} // namespace
@@ -148,21 +139,30 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
ImmutableStringFieldGenerator::ImmutableStringFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ message_bit_index_(messageBitIndex),
+ builder_bit_index_(builderBitIndex),
+ name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
ImmutableStringFieldGenerator::~ImmutableStringFieldGenerator() {}
+int ImmutableStringFieldGenerator::GetMessageBitIndex() const {
+ return message_bit_index_;
+}
+
+int ImmutableStringFieldGenerator::GetBuilderBitIndex() const {
+ return builder_bit_index_;
+}
+
int ImmutableStringFieldGenerator::GetNumBitsForMessage() const {
return HasHasbit(descriptor_) ? 1 : 0;
}
-int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const {
- return GetNumBitsForMessage();
-}
+int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const { return 1; }
// A note about how strings are handled. This code used to just store a String
// in the Message. This had two issues:
@@ -194,8 +194,7 @@ int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const {
// separate fields but rather use dynamic type checking.
//
// For single fields, the logic for this is done inside the generated code. For
-// repeated fields, the logic is done in LazyStringArrayList and
-// UnmodifiableLazyStringList.
+// repeated fields, the logic is done in LazyStringArrayList.
void ImmutableStringFieldGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
if (HasHazzer(descriptor_)) {
@@ -214,7 +213,9 @@ void ImmutableStringFieldGenerator::GenerateInterfaceMembers(
void ImmutableStringFieldGenerator::GenerateMembers(
io::Printer* printer) const {
- printer->Print(variables_, "private volatile java.lang.Object $name$_;\n");
+ printer->Print(variables_,
+ "@SuppressWarnings(\"serial\")\n"
+ "private volatile java.lang.Object $name$_ = $default$;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
@@ -333,9 +334,9 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
- "$null_check$"
- " $set_has_field_bit_builder$\n"
+ " $null_check$\n"
" $name$_ = value;\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -344,14 +345,14 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers(
/* builder */ true);
printer->Print(
variables_,
- "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
- " $clear_has_field_bit_builder$\n");
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n");
printer->Annotate("{", "}", descriptor_);
// The default value is not a simple literal so we want to avoid executing
// it multiple times. Instead, get the default out of the default instance.
printer->Print(variables_,
" $name$_ = getDefaultInstance().get$capitalized_name$();\n");
printer->Print(variables_,
+ " $clear_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -362,14 +363,14 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers(
variables_,
"$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
- "$null_check$");
+ " $null_check$\n");
printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_, " checkByteStringIsUtf8(value);\n");
}
printer->Print(variables_,
- " $set_has_field_bit_builder$\n"
" $name$_ = value;\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -377,9 +378,9 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers(
void ImmutableStringFieldGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$var $kt_name$: kotlin.String\n"
+ "$kt_deprecation$public var $kt_name$: kotlin.String\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -388,17 +389,18 @@ void ImmutableStringFieldGenerator::GenerateKotlinDslMembers(
" }\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
if (HasHazzer(descriptor_)) {
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
}
@@ -416,9 +418,7 @@ void ImmutableStringFieldGenerator::GenerateInitializationCode(
void ImmutableStringFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "$name$_ = $default$;\n"
- "$clear_has_field_bit_builder$\n");
+ printer->Print(variables_, "$name$_ = $default$;\n");
}
void ImmutableStringFieldGenerator::GenerateMergingCode(
@@ -428,14 +428,15 @@ void ImmutableStringFieldGenerator::GenerateMergingCode(
// all string fields to Strings when copying fields from a Message.
printer->Print(variables_,
"if (other.has$capitalized_name$()) {\n"
- " $set_has_field_bit_builder$\n"
" $name$_ = other.$name$_;\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
"}\n");
} else {
printer->Print(variables_,
"if (!other.get$capitalized_name$().isEmpty()) {\n"
" $name$_ = other.$name$_;\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
"}\n");
}
@@ -443,35 +444,28 @@ void ImmutableStringFieldGenerator::GenerateMergingCode(
void ImmutableStringFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
- if (HasHazzer(descriptor_)) {
- printer->Print(variables_,
- "if ($get_has_field_bit_from_local$) {\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n");
+ printer->Print(variables_,
+ "if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$_;\n");
+ if (GetNumBitsForMessage() > 0) {
+ printer->Print(variables_, " $set_has_field_bit_to_local$;\n");
}
- printer->Print(variables_, "result.$name$_ = $name$_;\n");
+ printer->Print("}\n");
}
-void ImmutableStringFieldGenerator::GenerateParsingCode(
+void ImmutableStringFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
- "java.lang.String s = input.readStringRequireUtf8();\n"
- "$set_has_field_bit_message$\n"
- "$name$_ = s;\n");
+ "$name$_ = input.readStringRequireUtf8();\n"
+ "$set_has_field_bit_builder$\n");
} else {
printer->Print(variables_,
- "com.google.protobuf.ByteString bs = input.readBytes();\n"
- "$set_has_field_bit_message$\n"
- "$name$_ = bs;\n");
+ "$name$_ = input.readBytes();\n"
+ "$set_has_field_bit_builder$\n");
}
}
-void ImmutableStringFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- // noop for strings.
-}
-
void ImmutableStringFieldGenerator::GenerateSerializationCode(
io::Printer* printer) const {
printer->Print(variables_,
@@ -523,7 +517,7 @@ ImmutableStringOneofFieldGenerator::~ImmutableStringOneofFieldGenerator() {}
void ImmutableStringOneofFieldGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
@@ -587,7 +581,7 @@ void ImmutableStringOneofFieldGenerator::GenerateMembers(
void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -655,7 +649,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
- "$null_check$"
+ " $null_check$\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = value;\n"
" $on_changed$\n"
@@ -682,7 +676,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers(
variables_,
"$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
- "$null_check$");
+ " $null_check$\n");
printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_, " checkByteStringIsUtf8(value);\n");
@@ -695,6 +689,11 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers(
"}\n");
}
+void ImmutableStringOneofFieldGenerator::GenerateBuilderClearCode(
+ io::Printer* printer) const {
+ // No-Op: String fields in oneofs are correctly cleared by clearing the oneof
+}
+
void ImmutableStringOneofFieldGenerator::GenerateMergingCode(
io::Printer* printer) const {
// Allow a slight breach of abstraction here in order to avoid forcing
@@ -707,13 +706,10 @@ void ImmutableStringOneofFieldGenerator::GenerateMergingCode(
void ImmutableStringOneofFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
- printer->Print(variables_,
- "if ($has_oneof_case_message$) {\n"
- " result.$oneof_name$_ = $oneof_name$_;\n"
- "}\n");
+ // No-Op: oneof fields are built by a single statement
}
-void ImmutableStringOneofFieldGenerator::GenerateParsingCode(
+void ImmutableStringOneofFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
@@ -749,11 +745,8 @@ void ImmutableStringOneofFieldGenerator::GenerateSerializedSizeCode(
RepeatedImmutableStringFieldGenerator::RepeatedImmutableStringFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
- SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
- context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
-}
+ : ImmutableStringFieldGenerator(descriptor, messageBitIndex,
+ builderBitIndex, context) {}
RepeatedImmutableStringFieldGenerator::
~RepeatedImmutableStringFieldGenerator() {}
@@ -796,7 +789,9 @@ void RepeatedImmutableStringFieldGenerator::GenerateInterfaceMembers(
void RepeatedImmutableStringFieldGenerator::GenerateMembers(
io::Printer* printer) const {
printer->Print(variables_,
- "private com.google.protobuf.LazyStringList $name$_;\n");
+ "@SuppressWarnings(\"serial\")\n"
+ "private com.google.protobuf.LazyStringArrayList $name$_ =\n"
+ " $empty_list$;\n");
PrintExtraFieldInfo(variables_, printer);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
@@ -840,17 +835,17 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
// memory allocations. Note, immutable is a strong guarantee here -- not
// just that the list cannot be modified via the reference but that the
// list can never be modified.
- printer->Print(
- variables_,
- "private com.google.protobuf.LazyStringList $name$_ = $empty_list$;\n");
+ printer->Print(variables_,
+ "private com.google.protobuf.LazyStringArrayList $name$_ =\n"
+ " $empty_list$;\n");
printer->Print(
variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
- " if (!$get_mutable_bit_builder$) {\n"
+ " if (!$name$_.isModifiable()) {\n"
" $name$_ = new com.google.protobuf.LazyStringArrayList($name$_);\n"
- " $set_mutable_bit_builder$;\n"
- " }\n"
+ " }\n"
+ " $set_has_field_bit_builder$\n"
"}\n");
// Note: We return an unmodifiable list because otherwise the caller
@@ -861,7 +856,8 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ProtocolStringList\n"
" ${$get$capitalized_name$List$}$() {\n"
- " return $name$_.getUnmodifiableView();\n"
+ " $name$_.makeImmutable();\n"
+ " return $name$_;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT);
@@ -891,9 +887,10 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, java.lang.String value) {\n"
- "$null_check$"
+ " $null_check$\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.set(index, value);\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -903,9 +900,10 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
"$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
- "$null_check$"
+ " $null_check$\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.add(value);\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -918,6 +916,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
" ensure$capitalized_name$IsMutable();\n"
" com.google.protobuf.AbstractMessageLite.Builder.addAll(\n"
" values, $name$_);\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -927,8 +926,9 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
printer->Print(
variables_,
"$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
- " $name$_ = $empty_list$;\n"
- " $clear_mutable_bit_builder$;\n"
+ " $name$_ =\n"
+ " $empty_list$;\n"
+ " $clear_has_field_bit_builder$;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -940,7 +940,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
variables_,
"$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
- "$null_check$");
+ " $null_check$\n");
printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_, " checkByteStringIsUtf8(value);\n");
@@ -948,6 +948,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_,
" ensure$capitalized_name$IsMutable();\n"
" $name$_.add(value);\n"
+ " $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return this;\n"
"}\n");
@@ -963,13 +964,14 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
// property for List<String>
- WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
+ WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>\n"
" @kotlin.jvm.JvmSynthetic\n"
@@ -979,11 +981,11 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers(
// List<String>.add(String)
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: kotlin.String) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
@@ -991,12 +993,12 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers(
// List<String> += String
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: kotlin.String) {\n"
" add(value)\n"
@@ -1004,12 +1006,12 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers(
// List<String>.addAll(Iterable<String>)
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<kotlin.String>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
@@ -1017,13 +1019,13 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers(
// List<String> += Iterable<String>
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<kotlin.String>) {\n"
" addAll(values)\n"
@@ -1031,23 +1033,23 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers(
// List<String>[Int] = String
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: kotlin.String) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
@@ -1061,14 +1063,16 @@ void RepeatedImmutableStringFieldGenerator::
void RepeatedImmutableStringFieldGenerator::GenerateInitializationCode(
io::Printer* printer) const {
- printer->Print(variables_, "$name$_ = $empty_list$;\n");
+ printer->Print(variables_,
+ "$name$_ =\n"
+ " $empty_list$;\n");
}
void RepeatedImmutableStringFieldGenerator::GenerateBuilderClearCode(
io::Printer* printer) const {
printer->Print(variables_,
- "$name$_ = $empty_list$;\n"
- "$clear_mutable_bit_builder$;\n");
+ "$name$_ =\n"
+ " $empty_list$;\n");
}
void RepeatedImmutableStringFieldGenerator::GenerateMergingCode(
@@ -1082,7 +1086,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateMergingCode(
"if (!other.$name$_.isEmpty()) {\n"
" if ($name$_.isEmpty()) {\n"
" $name$_ = other.$name$_;\n"
- " $clear_mutable_bit_builder$;\n"
+ " $set_has_field_bit_builder$\n"
" } else {\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.addAll(other.$name$_);\n"
@@ -1095,44 +1099,28 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const {
// The code below ensures that the result has an immutable list. If our
// list is immutable, we can just reuse it. If not, we make it immutable.
-
printer->Print(variables_,
- "if ($get_mutable_bit_builder$) {\n"
- " $name$_ = $name$_.getUnmodifiableView();\n"
- " $clear_mutable_bit_builder$;\n"
- "}\n"
- "result.$name$_ = $name$_;\n");
+ "if ($get_has_field_bit_from_local$) {\n"
+ " $name$_.makeImmutable();\n"
+ " result.$name$_ = $name$_;\n"
+ "}\n");
}
-void RepeatedImmutableStringFieldGenerator::GenerateParsingCode(
+void RepeatedImmutableStringFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
- "java.lang.String s = input.readStringRequireUtf8();\n");
+ "java.lang.String s = input.readStringRequireUtf8();\n"
+ "ensure$capitalized_name$IsMutable();\n"
+ "$name$_.add(s);\n");
} else {
printer->Print(variables_,
- "com.google.protobuf.ByteString bs = input.readBytes();\n");
- }
- printer->Print(variables_,
- "if (!$get_mutable_bit_parser$) {\n"
- " $name$_ = new com.google.protobuf.LazyStringArrayList();\n"
- " $set_mutable_bit_parser$;\n"
- "}\n");
- if (CheckUtf8(descriptor_)) {
- printer->Print(variables_, "$name$_.add(s);\n");
- } else {
- printer->Print(variables_, "$name$_.add(bs);\n");
+ "com.google.protobuf.ByteString bs = input.readBytes();\n"
+ "ensure$capitalized_name$IsMutable();\n"
+ "$name$_.add(bs);\n");
}
}
-void RepeatedImmutableStringFieldGenerator::GenerateParsingDoneCode(
- io::Printer* printer) const {
- printer->Print(variables_,
- "if ($get_mutable_bit_parser$) {\n"
- " $name$_ = $name$_.getUnmodifiableView();\n"
- "}\n");
-}
-
void RepeatedImmutableStringFieldGenerator::GenerateSerializationCode(
io::Printer* printer) const {
printer->Print(variables_,
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.h
index 3a83f1fc2a..e7ef4d7c06 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field.h
@@ -36,10 +36,9 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -62,10 +61,15 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
explicit ImmutableStringFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
int builderBitIndex, Context* context);
+ ImmutableStringFieldGenerator(const ImmutableStringFieldGenerator&) = delete;
+ ImmutableStringFieldGenerator& operator=(
+ const ImmutableStringFieldGenerator&) = delete;
~ImmutableStringFieldGenerator() override;
// implements ImmutableFieldGenerator
// ---------------------------------------
+ int GetMessageBitIndex() const override;
+ int GetBuilderBitIndex() const override;
int GetNumBitsForMessage() const override;
int GetNumBitsForBuilder() const override;
void GenerateInterfaceMembers(io::Printer* printer) const override;
@@ -75,8 +79,7 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -89,11 +92,10 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ int message_bit_index_;
+ int builder_bit_index_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
ClassNameResolver* name_resolver_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldGenerator);
};
class ImmutableStringOneofFieldGenerator
@@ -102,25 +104,33 @@ class ImmutableStringOneofFieldGenerator
ImmutableStringOneofFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
Context* context);
+ ImmutableStringOneofFieldGenerator(
+ const ImmutableStringOneofFieldGenerator&) = delete;
+ ImmutableStringOneofFieldGenerator& operator=(
+ const ImmutableStringOneofFieldGenerator&) = delete;
~ImmutableStringOneofFieldGenerator() override;
private:
void GenerateMembers(io::Printer* printer) const override;
void GenerateBuilderMembers(io::Printer* printer) const override;
+ void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldGenerator);
};
-class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator {
+class RepeatedImmutableStringFieldGenerator
+ : public ImmutableStringFieldGenerator {
public:
explicit RepeatedImmutableStringFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, Context* context);
+ RepeatedImmutableStringFieldGenerator(
+ const RepeatedImmutableStringFieldGenerator&) = delete;
+ RepeatedImmutableStringFieldGenerator& operator=(
+ const RepeatedImmutableStringFieldGenerator&) = delete;
~RepeatedImmutableStringFieldGenerator() override;
// implements ImmutableFieldGenerator ---------------------------------------
@@ -133,8 +143,7 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator {
void GenerateBuilderClearCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateBuildingCode(io::Printer* printer) const override;
- void GenerateParsingCode(io::Printer* printer) const override;
- void GenerateParsingDoneCode(io::Printer* printer) const override;
+ void GenerateBuilderParsingCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
@@ -144,13 +153,6 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator {
void GenerateKotlinDslMembers(io::Printer* printer) const override;
TProtoStringType GetBoxedType() const override;
-
- private:
- const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
- ClassNameResolver* name_resolver_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldGenerator);
};
} // namespace java
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.cc
index 91cb53d484..6e57d1bbef 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.cc
@@ -33,21 +33,19 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/compiler/java/string_field_lite.h>
+#include "google/protobuf/compiler/java/string_field_lite.h"
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/wire_format.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 "y_absl/container/flat_hash_map.h"
+#include "y_absl/log/absl_check.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/wire_format.h"
namespace google {
namespace protobuf {
@@ -59,23 +57,25 @@ using internal::WireFormatLite;
namespace {
-void SetPrimitiveVariables(const FieldDescriptor* descriptor,
- int messageBitIndex, int builderBitIndex,
- const FieldGeneratorInfo* info,
- ClassNameResolver* name_resolver,
- std::map<TProtoStringType, TProtoStringType>* variables) {
+void SetPrimitiveVariables(
+ const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
+ const FieldGeneratorInfo* info, ClassNameResolver* name_resolver,
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType>* variables,
+ Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["empty_list"] =
"com.google.protobuf.GeneratedMessageLite.emptyProtobufList()";
- (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
- (*variables)["default_init"] =
- "= " + ImmutableDefaultValue(descriptor, name_resolver);
+ (*variables)["default"] =
+ ImmutableDefaultValue(descriptor, name_resolver, context->options());
+ (*variables)["default_init"] = y_absl::StrCat(
+ "= ",
+ ImmutableDefaultValue(descriptor, name_resolver, context->options()));
(*variables)["capitalized_type"] = "java.lang.String";
(*variables)["tag"] =
- StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
- (*variables)["tag_size"] = StrCat(
+ y_absl::StrCat(static_cast<arc_i32>(WireFormat::MakeTag(descriptor)));
+ (*variables)["tag_size"] = y_absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
@@ -86,36 +86,49 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
// by the proto compiler
(*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
- (*variables)["kt_deprecation"] =
- descriptor->options().deprecated()
- ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
- " is deprecated\") "
- : "";
+ variables->insert(
+ {"kt_deprecation",
+ descriptor->options().deprecated()
+ ? y_absl::StrCat("@kotlin.Deprecated(message = \"Field ",
+ (*variables)["name"], " is deprecated\") ")
+ : ""});
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
+ if (!context->options().opensource_runtime) {
+ (*variables)["enforce_utf8"] = CheckUtf8(descriptor) ? "true" : "false";
+ }
if (HasHasbit(descriptor)) {
+ if (!context->options().opensource_runtime) {
+ (*variables)["bit_field_id"] = y_absl::StrCat(messageBitIndex / 32);
+ (*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex);
+ (*variables)["bit_field_mask"] =
+ y_absl::StrCat(1 << (messageBitIndex % 32));
+ }
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
- GenerateSetBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateSetBit(messageBitIndex), ";");
(*variables)["clear_has_field_bit_message"] =
- GenerateClearBit(messageBitIndex) + ";";
+ y_absl::StrCat(GenerateClearBit(messageBitIndex), ";");
(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
(*variables)["set_has_field_bit_message"] = "";
(*variables)["clear_has_field_bit_message"] = "";
- (*variables)["is_field_present_message"] =
- "!" + (*variables)["name"] + "_.isEmpty()";
+ variables->insert({"is_field_present_message",
+ y_absl::StrCat("!", (*variables)["name"], "_.isEmpty()")});
}
(*variables)["get_has_field_bit_from_local"] =
GenerateGetBitFromLocal(builderBitIndex);
(*variables)["set_has_field_bit_to_local"] =
GenerateSetBitToLocal(messageBitIndex);
+ // Annotations often use { and } variables to denote text ranges.
+ (*variables)["{"] = "";
+ (*variables)["}"] = "";
}
} // namespace
@@ -126,10 +139,11 @@ ImmutableStringFieldLiteGenerator::ImmutableStringFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
- name_resolver_(context->GetNameResolver()) {
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
ImmutableStringFieldLiteGenerator::~ImmutableStringFieldLiteGenerator() {}
@@ -168,19 +182,38 @@ void ImmutableStringFieldLiteGenerator::GenerateInterfaceMembers(
if (HasHazzer(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
- "$deprecation$boolean has$capitalized_name$();\n");
+ "$deprecation$boolean ${$has$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
- printer->Print(variables_,
- "$deprecation$java.lang.String get$capitalized_name$();\n");
+ printer->Print(
+ variables_,
+ "$deprecation$java.lang.String ${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"$deprecation$com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes();\n");
+ " ${$get$capitalized_name$Bytes$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableStringFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "@com.google.protobuf.ProtoField(\n"
+ " fieldNumber=$number$,\n"
+ " type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
+ " isRequired=$required$,\n"
+ " isEnforceUtf8=$enforce_utf8$)\n");
+ if (HasHazzer(descriptor_)) {
+ printer->Print(variables_,
+ "@com.google.protobuf.ProtoPresenceCheckedField(\n"
+ " presenceBitsId=$bit_field_id$,\n"
+ " mask=$bit_field_mask$)\n");
+ }
+ }
printer->Print(variables_, "private java.lang.String $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
@@ -311,9 +344,9 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers(
void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
io::Printer* printer) const {
- WriteFieldDocComment(printer, descriptor_);
+ WriteFieldDocComment(printer, descriptor_, /* kdoc */ true);
printer->Print(variables_,
- "$kt_deprecation$var $kt_name$: kotlin.String\n"
+ "$kt_deprecation$public var $kt_name$: kotlin.String\n"
" @JvmName(\"${$get$kt_capitalized_name$$}$\")\n"
" get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n"
" @JvmName(\"${$set$kt_capitalized_name$$}$\")\n"
@@ -322,17 +355,18 @@ void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
" }\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
- "fun ${$clear$kt_capitalized_name$$}$() {\n"
+ "public fun ${$clear$kt_capitalized_name$$}$() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}\n");
if (HasHazzer(descriptor_)) {
- WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
+ WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
+ "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n"
" return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n"
"}\n");
}
@@ -374,7 +408,7 @@ ImmutableStringOneofFieldLiteGenerator::
void ImmutableStringOneofFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -452,7 +486,7 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateFieldInfo(
void ImmutableStringOneofFieldLiteGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
- GOOGLE_DCHECK(HasHazzer(descriptor_));
+ Y_ABSL_DCHECK(HasHazzer(descriptor_));
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"@java.lang.Override\n"
@@ -519,10 +553,12 @@ RepeatedImmutableStringFieldLiteGenerator::
RepeatedImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context)
- : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
+ : descriptor_(descriptor),
+ name_resolver_(context->GetNameResolver()),
+ context_(context) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
- name_resolver_, &variables_);
+ name_resolver_, &variables_, context);
}
RepeatedImmutableStringFieldLiteGenerator::
@@ -537,22 +573,34 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateInterfaceMembers(
WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"$deprecation$java.util.List<java.lang.String>\n"
- " get$capitalized_name$List();\n");
+ " ${$get$capitalized_name$List$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT);
printer->Print(variables_,
- "$deprecation$int get$capitalized_name$Count();\n");
+ "$deprecation$int ${$get$capitalized_name$Count$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER);
- printer->Print(
- variables_,
- "$deprecation$java.lang.String get$capitalized_name$(int index);\n");
+ printer->Print(variables_,
+ "$deprecation$java.lang.String "
+ "${$get$capitalized_name$$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER);
printer->Print(variables_,
"$deprecation$com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes(int index);\n");
+ " ${$get$capitalized_name$Bytes$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
+ if (!context_->options().opensource_runtime) {
+ printer->Print(
+ variables_,
+ "@com.google.protobuf.ProtoField(\n"
+ " fieldNumber=$number$,\n"
+ " type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
+ " isEnforceUtf8=$enforce_utf8$)\n");
+ }
printer->Print(
variables_,
"private com.google.protobuf.Internal.ProtobufList<java.lang.String> "
@@ -748,14 +796,15 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
" */\n"
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
- "class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
+ "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()"
" : com.google.protobuf.kotlin.DslProxy()\n");
// property for List<String>
- WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
+ WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER,
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
- "$kt_deprecation$ val $kt_name$: "
+ "$kt_deprecation$public val $kt_name$: "
"com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>\n"
"@kotlin.OptIn"
@@ -766,11 +815,11 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
// List<String>.add(String)
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: kotlin.String) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
@@ -778,12 +827,12 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
// List<String> += String
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: kotlin.String) {\n"
" add(value)\n"
@@ -791,12 +840,12 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
// List<String>.addAll(Iterable<String>)
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<kotlin.String>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
@@ -804,13 +853,13 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
// List<String> += Iterable<String>
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
- "inline operator fun com.google.protobuf.kotlin.DslList"
+ "public inline operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<kotlin.String>) {\n"
" addAll(values)\n"
@@ -818,23 +867,23 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
// List<String>[Int] = String
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n"
- "operator fun com.google.protobuf.kotlin.DslList"
+ "public operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: kotlin.String) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
- /* builder */ false);
+ /* builder */ false, /* kdoc */ true);
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n"
- "fun com.google.protobuf.kotlin.DslList"
+ "public fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.h
index 73e51e3238..e65b9953d3 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/string_field_lite.h
@@ -37,10 +37,9 @@
#define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__
#include <cstdint>
-#include <map>
#include <string>
-#include <google/protobuf/compiler/java/field.h>
+#include "google/protobuf/compiler/java/field.h"
namespace google {
namespace protobuf {
@@ -63,6 +62,10 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
explicit ImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context);
+ ImmutableStringFieldLiteGenerator(const ImmutableStringFieldLiteGenerator&) =
+ delete;
+ ImmutableStringFieldLiteGenerator& operator=(
+ const ImmutableStringFieldLiteGenerator&) = delete;
~ImmutableStringFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator
@@ -80,12 +83,10 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
const int messageBitIndex_;
ClassNameResolver* name_resolver_;
-
- private:
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldLiteGenerator);
+ Context* context_;
};
class ImmutableStringOneofFieldLiteGenerator
@@ -93,6 +94,10 @@ class ImmutableStringOneofFieldLiteGenerator
public:
ImmutableStringOneofFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, Context* context);
+ ImmutableStringOneofFieldLiteGenerator(
+ const ImmutableStringOneofFieldLiteGenerator&) = delete;
+ ImmutableStringOneofFieldLiteGenerator& operator=(
+ const ImmutableStringOneofFieldLiteGenerator&) = delete;
~ImmutableStringOneofFieldLiteGenerator() override;
private:
@@ -100,8 +105,6 @@ class ImmutableStringOneofFieldLiteGenerator
void GenerateBuilderMembers(io::Printer* printer) const override;
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16_t>* output) const override;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator);
};
class RepeatedImmutableStringFieldLiteGenerator
@@ -109,6 +112,10 @@ class RepeatedImmutableStringFieldLiteGenerator
public:
explicit RepeatedImmutableStringFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context);
+ RepeatedImmutableStringFieldLiteGenerator(
+ const RepeatedImmutableStringFieldLiteGenerator&) = delete;
+ RepeatedImmutableStringFieldLiteGenerator& operator=(
+ const RepeatedImmutableStringFieldLiteGenerator&) = delete;
~RepeatedImmutableStringFieldLiteGenerator() override;
// implements ImmutableFieldLiteGenerator ------------------------------------
@@ -125,10 +132,9 @@ class RepeatedImmutableStringFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
- std::map<TProtoStringType, TProtoStringType> variables_;
+ y_absl::flat_hash_map<y_absl::string_view, TProtoStringType> variables_;
ClassNameResolver* name_resolver_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldLiteGenerator);
+ Context* context_;
};
} // namespace java