diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:44 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:44 +0300 |
commit | 59e19371de37995fcb36beb16cd6ec030af960bc (patch) | |
tree | fa68e36093ebff8b805462e9e6d331fe9d348214 /contrib/libs/protoc/src/google/protobuf/compiler/java | |
parent | 89db6fe2fe2c32d2a832ddfeb04e8d078e301084 (diff) | |
download | ydb-59e19371de37995fcb36beb16cd6ec030af960bc.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/protoc/src/google/protobuf/compiler/java')
58 files changed, 11006 insertions, 11006 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.cc index 3403cfca2c..26ba96dcf0 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.cc @@ -1,202 +1,202 @@ -// 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. - +// 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/java_context.h> - + #include <google/protobuf/compiler/java/java_field.h> #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/map_util.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -Context::Context(const FileDescriptor* file, const Options& options) - : name_resolver_(new ClassNameResolver), options_(options) { - InitializeFieldGeneratorInfo(file); -} - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +Context::Context(const FileDescriptor* file, const Options& options) + : name_resolver_(new ClassNameResolver), options_(options) { + InitializeFieldGeneratorInfo(file); +} + Context::~Context() {} - + ClassNameResolver* Context::GetNameResolver() const { - return name_resolver_.get(); -} - -namespace { -// Whether two fields have conflicting accessors (assuming name1 and name2 -// are different). name1 and name2 are field1 and field2's camel-case name -// respectively. + return name_resolver_.get(); +} + +namespace { +// 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, TProtoStringType* info) { - if (field1->is_repeated()) { - if (field2->is_repeated()) { - // Both fields are repeated. - return false; - } else { - // field1 is repeated, and field2 is not. - if (name1 + "Count" == name2) { - *info = "both repeated field \"" + field1->name() + "\" and singular " + + if (field1->is_repeated()) { + if (field2->is_repeated()) { + // Both fields are repeated. + 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()\""; - return true; - } - if (name1 + "List" == name2) { - *info = "both repeated field \"" + field1->name() + "\" and singular " + + return true; + } + if (name1 + "List" == name2) { + *info = "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 - // doesn't worth the effort to exhaust all of them because they rarely - // happen and as we are continuing adding new methods/changing existing - // methods the number of different conflicting cases will keep growing. - // We can just add more cases here when they are found in the real world. - return false; - } - } else { - if (field2->is_repeated()) { - return IsConflicting(field2, name2, field1, name1, info); - } else { - // None of the two fields are repeated. - return false; - } - } -} -} // namespace - -void Context::InitializeFieldGeneratorInfo(const FileDescriptor* file) { - for (int i = 0; i < file->message_type_count(); ++i) { - InitializeFieldGeneratorInfoForMessage(file->message_type(i)); - } -} - -void Context::InitializeFieldGeneratorInfoForMessage( - const Descriptor* message) { - for (int i = 0; i < message->nested_type_count(); ++i) { - InitializeFieldGeneratorInfoForMessage(message->nested_type(i)); - } + return true; + } + // Well, there are obviously many more conflicting cases, but it probably + // doesn't worth the effort to exhaust all of them because they rarely + // happen and as we are continuing adding new methods/changing existing + // methods the number of different conflicting cases will keep growing. + // We can just add more cases here when they are found in the real world. + return false; + } + } else { + if (field2->is_repeated()) { + return IsConflicting(field2, name2, field1, name1, info); + } else { + // None of the two fields are repeated. + return false; + } + } +} +} // namespace + +void Context::InitializeFieldGeneratorInfo(const FileDescriptor* file) { + for (int i = 0; i < file->message_type_count(); ++i) { + InitializeFieldGeneratorInfoForMessage(file->message_type(i)); + } +} + +void Context::InitializeFieldGeneratorInfoForMessage( + const Descriptor* message) { + for (int i = 0; i < message->nested_type_count(); ++i) { + InitializeFieldGeneratorInfoForMessage(message->nested_type(i)); + } std::vector<const FieldDescriptor*> fields; fields.reserve(message->field_count()); - for (int i = 0; i < message->field_count(); ++i) { - fields.push_back(message->field(i)); - } - InitializeFieldGeneratorInfoForFields(fields); - - for (int i = 0; i < message->oneof_decl_count(); ++i) { - const OneofDescriptor* oneof = message->oneof_decl(i); - OneofGeneratorInfo info; - info.name = UnderscoresToCamelCase(oneof->name(), false); - info.capitalized_name = UnderscoresToCamelCase(oneof->name(), true); - oneof_generator_info_map_[oneof] = info; - } -} - -void Context::InitializeFieldGeneratorInfoForFields( + for (int i = 0; i < message->field_count(); ++i) { + fields.push_back(message->field(i)); + } + InitializeFieldGeneratorInfoForFields(fields); + + for (int i = 0; i < message->oneof_decl_count(); ++i) { + const OneofDescriptor* oneof = message->oneof_decl(i); + OneofGeneratorInfo info; + info.name = UnderscoresToCamelCase(oneof->name(), false); + info.capitalized_name = UnderscoresToCamelCase(oneof->name(), true); + oneof_generator_info_map_[oneof] = info; + } +} + +void Context::InitializeFieldGeneratorInfoForFields( const std::vector<const FieldDescriptor*>& fields) { - // Find out all fields that conflict with some other field in the same - // message. + // Find out all fields that conflict with some other field in the same + // message. std::vector<bool> is_conflict(fields.size()); std::vector<TProtoStringType> conflict_reason(fields.size()); - for (int i = 0; i < fields.size(); ++i) { - const FieldDescriptor* field = fields[i]; + for (int i = 0; i < fields.size(); ++i) { + const FieldDescriptor* field = fields[i]; const TProtoStringType& name = UnderscoresToCapitalizedCamelCase(field); - for (int j = i + 1; j < fields.size(); ++j) { - const FieldDescriptor* other = fields[j]; + for (int j = i + 1; j < fields.size(); ++j) { + const FieldDescriptor* other = fields[j]; const TProtoStringType& other_name = UnderscoresToCapitalizedCamelCase(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() + "\""; - } else if (IsConflicting(field, name, other, other_name, - &conflict_reason[j])) { - is_conflict[i] = is_conflict[j] = true; - conflict_reason[i] = conflict_reason[j]; - } - } - if (is_conflict[i]) { - GOOGLE_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; + 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() + "\""; + } else if (IsConflicting(field, name, other, other_name, + &conflict_reason[j])) { + is_conflict[i] = is_conflict[j] = true; + conflict_reason[i] = conflict_reason[j]; + } + } + if (is_conflict[i]) { + GOOGLE_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); - // 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.capitalized_name = UnderscoresToCapitalizedCamelCase(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()); - info.disambiguated_reason = conflict_reason[i]; - } - field_generator_info_map_[field] = info; - } -} - -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(); - } - return result; -} - -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(); - } - return result; -} - -// Does this message class have generated parsing, serialization, and other -// standard methods for which reflection-based fallback implementations exist? -bool Context::HasGeneratedMethods(const Descriptor* descriptor) const { - return options_.enforce_lite || - descriptor->file()->options().optimize_for() != FileOptions::CODE_SIZE; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + info.disambiguated_reason = conflict_reason[i]; + } + field_generator_info_map_[field] = info; + } +} + +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(); + } + return result; +} + +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(); + } + return result; +} + +// Does this message class have generated parsing, serialization, and other +// standard methods for which reflection-based fallback implementations exist? +bool Context::HasGeneratedMethods(const Descriptor* descriptor) const { + return options_.enforce_lite || + descriptor->file()->options().optimize_for() != FileOptions::CODE_SIZE; +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.h index 3fa6af1778..4c54a2c414 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_context.h @@ -1,45 +1,45 @@ -// 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_CONTEXT_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ - -#include <map> -#include <memory> -#include <vector> - +// 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_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/java_options.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { class FileDescriptor; class FieldDescriptor; class OneofDescriptor; @@ -50,64 +50,64 @@ namespace java { class ClassNameResolver; // name_resolver.h } } // namespace compiler -} // namespace protobuf +} // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -struct FieldGeneratorInfo; -struct OneofGeneratorInfo; -// A context object holds the information that is shared among all code -// generators. -class Context { - public: - Context(const FileDescriptor* file, const Options& options); - ~Context(); - - // Get the name resolver associated with this context. The resolver - // can be used to map descriptors to Java class names. +namespace protobuf { +namespace compiler { +namespace java { + +struct FieldGeneratorInfo; +struct OneofGeneratorInfo; +// A context object holds the information that is shared among all code +// generators. +class Context { + public: + Context(const FileDescriptor* file, const Options& options); + ~Context(); + + // Get the name resolver associated with this context. The resolver + // can be used to map descriptors to Java class names. ClassNameResolver* GetNameResolver() const; - - // Get the FieldGeneratorInfo for a given field. - const FieldGeneratorInfo* GetFieldGeneratorInfo( - const FieldDescriptor* field) const; - - // Get the OneofGeneratorInfo for a given oneof. - const OneofGeneratorInfo* GetOneofGeneratorInfo( - const OneofDescriptor* oneof) const; - - const Options& options() const { return options_; } - - // Enforces all the files (including transitive dependencies) to use - // LiteRuntime. - - bool EnforceLite() const { return options_.enforce_lite; } - - // Does this message class have generated parsing, serialization, and other - // standard methods for which reflection-based fallback implementations exist? - bool HasGeneratedMethods(const Descriptor* descriptor) const; - - private: - void InitializeFieldGeneratorInfo(const FileDescriptor* file); - void InitializeFieldGeneratorInfoForMessage(const Descriptor* message); - void InitializeFieldGeneratorInfoForFields( + + // Get the FieldGeneratorInfo for a given field. + const FieldGeneratorInfo* GetFieldGeneratorInfo( + const FieldDescriptor* field) const; + + // Get the OneofGeneratorInfo for a given oneof. + const OneofGeneratorInfo* GetOneofGeneratorInfo( + const OneofDescriptor* oneof) const; + + const Options& options() const { return options_; } + + // Enforces all the files (including transitive dependencies) to use + // LiteRuntime. + + bool EnforceLite() const { return options_.enforce_lite; } + + // Does this message class have generated parsing, serialization, and other + // standard methods for which reflection-based fallback implementations exist? + bool HasGeneratedMethods(const Descriptor* descriptor) const; + + private: + void InitializeFieldGeneratorInfo(const FileDescriptor* file); + void InitializeFieldGeneratorInfoForMessage(const Descriptor* message); + void InitializeFieldGeneratorInfoForFields( const std::vector<const FieldDescriptor*>& fields); - + std::unique_ptr<ClassNameResolver> name_resolver_; std::map<const FieldDescriptor*, FieldGeneratorInfo> field_generator_info_map_; std::map<const OneofDescriptor*, OneofGeneratorInfo> oneof_generator_info_map_; - Options options_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Context); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + Options options_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Context); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.cc index 51a85cdc7c..db7737a149 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.cc @@ -1,191 +1,191 @@ -// 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. - +// 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/java_doc_comment.h> - -#include <vector> - + +#include <vector> + #include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + TProtoStringType EscapeJavadoc(const TProtoStringType& input) { TProtoStringType result; - result.reserve(input.size() * 2); - - char prev = '*'; - + result.reserve(input.size() * 2); + + char prev = '*'; + for (TProtoStringType::size_type i = 0; i < input.size(); i++) { - char c = input[i]; - switch (c) { - case '*': - // Avoid "/*". - if (prev == '/') { - result.append("*"); - } else { - result.push_back(c); - } - break; - case '/': - // Avoid "*/". - if (prev == '*') { - result.append("/"); - } else { - result.push_back(c); - } - break; - case '@': - // '@' starts javadoc tags including the @deprecated tag, which will - // cause a compile-time error if inserted before a declaration that - // does not have a corresponding @Deprecated annotation. - result.append("@"); - break; - case '<': - // Avoid interpretation as HTML. - result.append("<"); - break; - case '>': - // Avoid interpretation as HTML. - result.append(">"); - break; - case '&': - // Avoid interpretation as HTML. - result.append("&"); - break; - case '\\': - // Java interprets Unicode escape sequences anywhere! - result.append("\"); - break; - default: - result.push_back(c); - break; - } - - prev = c; - } - - return result; -} - + char c = input[i]; + switch (c) { + case '*': + // Avoid "/*". + if (prev == '/') { + result.append("*"); + } else { + result.push_back(c); + } + break; + case '/': + // Avoid "*/". + if (prev == '*') { + result.append("/"); + } else { + result.push_back(c); + } + break; + case '@': + // '@' starts javadoc tags including the @deprecated tag, which will + // cause a compile-time error if inserted before a declaration that + // does not have a corresponding @Deprecated annotation. + result.append("@"); + break; + case '<': + // Avoid interpretation as HTML. + result.append("<"); + break; + case '>': + // Avoid interpretation as HTML. + result.append(">"); + break; + case '&': + // Avoid interpretation as HTML. + result.append("&"); + break; + case '\\': + // Java interprets Unicode escape sequences anywhere! + result.append("\"); + break; + default: + result.push_back(c); + break; + } + + prev = c; + } + + return result; +} + static void WriteDocCommentBodyForLocation(io::Printer* printer, const SourceLocation& location) { 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 (!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); + std::vector<TProtoStringType> lines = Split(comments, "\n"); - while (!lines.empty() && lines.back().empty()) { - lines.pop_back(); - } - - 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 - // close the comment. - if (!lines[i].empty() && lines[i][0] == '/') { - printer->Print(" * $line$\n", "line", lines[i]); - } else { - printer->Print(" *$line$\n", "line", lines[i]); - } - } - printer->Print( - " * </pre>\n" - " *\n"); - } -} - -template <typename DescriptorType> + while (!lines.empty() && lines.back().empty()) { + lines.pop_back(); + } + + 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 + // close the comment. + if (!lines[i].empty() && lines[i][0] == '/') { + printer->Print(" * $line$\n", "line", lines[i]); + } else { + printer->Print(" *$line$\n", "line", lines[i]); + } + } + printer->Print( + " * </pre>\n" + " *\n"); + } +} + +template <typename DescriptorType> static void WriteDocCommentBody(io::Printer* printer, const DescriptorType* descriptor) { - SourceLocation location; - if (descriptor->GetSourceLocation(&location)) { - WriteDocCommentBodyForLocation(printer, location); - } -} - + SourceLocation location; + if (descriptor->GetSourceLocation(&location)) { + WriteDocCommentBodyForLocation(printer, location); + } +} + static TProtoStringType FirstLineOf(const TProtoStringType& value) { TProtoStringType result = value; - + TProtoStringType::size_type pos = result.find_first_of('\n'); if (pos != TProtoStringType::npos) { - result.erase(pos); - } - - // If line ends in an opening brace, make it "{ ... }" so it looks nice. - if (!result.empty() && result[result.size() - 1] == '{') { - result.append(" ... }"); - } - - return result; -} - -void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) { - printer->Print("/**\n"); - WriteDocCommentBody(printer, message); - printer->Print( + result.erase(pos); + } + + // If line ends in an opening brace, make it "{ ... }" so it looks nice. + if (!result.empty() && result[result.size() - 1] == '{') { + result.append(" ... }"); + } + + return result; +} + +void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) { + printer->Print("/**\n"); + WriteDocCommentBody(printer, message); + printer->Print( " * Protobuf type {@code $fullname$}\n" " */\n", "fullname", EscapeJavadoc(message->full_name())); -} - -void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) { - // We start the comment with the main body based on the comments from the +} + +void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) { + // 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.: - // optional string foo = 5; + // optional string foo = 5; // 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); + // 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()))); - printer->Print(" */\n"); -} - + printer->Print(" */\n"); +} + void WriteFieldAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, @@ -371,46 +371,46 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, // Enum -void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) { - printer->Print("/**\n"); - WriteDocCommentBody(printer, enum_); - printer->Print( +void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) { + printer->Print("/**\n"); + WriteDocCommentBody(printer, enum_); + 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); - printer->Print( +} + +void WriteEnumValueDocComment(io::Printer* printer, + const EnumValueDescriptor* value) { + printer->Print("/**\n"); + WriteDocCommentBody(printer, value); + printer->Print( " * <code>$def$</code>\n" " */\n", "def", EscapeJavadoc(FirstLineOf(value->DebugString()))); -} - -void WriteServiceDocComment(io::Printer* printer, - const ServiceDescriptor* service) { - printer->Print("/**\n"); - WriteDocCommentBody(printer, service); - printer->Print( +} + +void WriteServiceDocComment(io::Printer* printer, + const ServiceDescriptor* service) { + printer->Print("/**\n"); + WriteDocCommentBody(printer, service); + printer->Print( " * Protobuf service {@code $fullname$}\n" " */\n", "fullname", EscapeJavadoc(service->full_name())); -} - -void WriteMethodDocComment(io::Printer* printer, - const MethodDescriptor* method) { - printer->Print("/**\n"); - WriteDocCommentBody(printer, method); - printer->Print( +} + +void WriteMethodDocComment(io::Printer* printer, + const MethodDescriptor* method) { + printer->Print("/**\n"); + WriteDocCommentBody(printer, method); + printer->Print( " * <code>$def$</code>\n" " */\n", "def", EscapeJavadoc(FirstLineOf(method->DebugString()))); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.h index e7faa4a6a0..14903ad1bc 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_doc_comment.h @@ -1,57 +1,57 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ + #include <google/protobuf/descriptor.h> - + #include <google/protobuf/port_def.inc> -namespace google { -namespace protobuf { +namespace google { +namespace protobuf { namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - +namespace protobuf { +namespace compiler { +namespace java { + enum FieldAccessorType { HAZZER, GETTER, @@ -66,8 +66,8 @@ 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); +void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field); void WriteFieldAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, @@ -80,22 +80,22 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, const bool builder = false); -void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_); -void WriteEnumValueDocComment(io::Printer* printer, - const EnumValueDescriptor* value); -void WriteServiceDocComment(io::Printer* printer, - const ServiceDescriptor* service); -void WriteMethodDocComment(io::Printer* printer, - const MethodDescriptor* method); - -// Exposed for testing only. +void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_); +void WriteEnumValueDocComment(io::Printer* printer, + const EnumValueDescriptor* value); +void WriteServiceDocComment(io::Printer* printer, + const ServiceDescriptor* service); +void WriteMethodDocComment(io::Printer* printer, + const MethodDescriptor* method); + +// Exposed for testing only. PROTOC_EXPORT TProtoStringType EscapeJavadoc(const TProtoStringType& input); - -} // namespace java -} // namespace compiler -} // namespace protobuf + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - + #include <google/protobuf/port_undef.inc> -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.cc index d9070eeaab..99948b9edd 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.cc @@ -1,40 +1,40 @@ -// 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 <map> +// 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 <map> #include <string> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_enum.h> @@ -43,138 +43,138 @@ #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, bool immutable_api, Context* context) : descriptor_(descriptor), immutable_api_(immutable_api), context_(context), name_resolver_(context->GetNameResolver()) { - for (int i = 0; i < descriptor_->value_count(); i++) { - const EnumValueDescriptor* value = descriptor_->value(i); - const EnumValueDescriptor* canonical_value = + for (int i = 0; i < descriptor_->value_count(); i++) { + const EnumValueDescriptor* value = descriptor_->value(i); + const EnumValueDescriptor* canonical_value = descriptor_->FindValueByNumber(value->number()); - - if (value == canonical_value) { - canonical_values_.push_back(value); - } else { - Alias alias; - alias.value = value; - alias.canonical_value = canonical_value; - aliases_.push_back(alias); - } - } -} - -EnumGenerator::~EnumGenerator() {} - -void EnumGenerator::Generate(io::Printer* printer) { - WriteEnumDocComment(printer, descriptor_); - MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_); - printer->Print( + + if (value == canonical_value) { + canonical_values_.push_back(value); + } else { + Alias alias; + alias.value = value; + alias.canonical_value = canonical_value; + aliases_.push_back(alias); + } + } +} + +EnumGenerator::~EnumGenerator() {} + +void EnumGenerator::Generate(io::Printer* printer) { + WriteEnumDocComment(printer, descriptor_); + MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_); + printer->Print( "$deprecation$public enum $classname$\n" - " implements com.google.protobuf.ProtocolMessageEnum {\n", + " implements com.google.protobuf.ProtocolMessageEnum {\n", "classname", descriptor_->name(), "deprecation", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""); - printer->Annotate("classname", descriptor_); - printer->Indent(); - - bool ordinal_is_index = true; + printer->Annotate("classname", descriptor_); + printer->Indent(); + + bool ordinal_is_index = true; TProtoStringType index_text = "ordinal()"; - for (int i = 0; i < canonical_values_.size(); i++) { - if (canonical_values_[i]->index() != i) { - ordinal_is_index = false; - index_text = "index"; - break; - } - } - - for (int i = 0; i < canonical_values_.size(); i++) { + for (int i = 0; i < canonical_values_.size(); i++) { + if (canonical_values_[i]->index() != i) { + ordinal_is_index = false; + index_text = "index"; + break; + } + } + + for (int i = 0; i < canonical_values_.size(); i++) { std::map<TProtoStringType, TProtoStringType> vars; - vars["name"] = canonical_values_[i]->name(); + vars["name"] = canonical_values_[i]->name(); vars["index"] = StrCat(canonical_values_[i]->index()); vars["number"] = StrCat(canonical_values_[i]->number()); - WriteEnumValueDocComment(printer, canonical_values_[i]); - if (canonical_values_[i]->options().deprecated()) { - printer->Print("@java.lang.Deprecated\n"); - } - if (ordinal_is_index) { + WriteEnumValueDocComment(printer, canonical_values_[i]); + if (canonical_values_[i]->options().deprecated()) { + printer->Print("@java.lang.Deprecated\n"); + } + if (ordinal_is_index) { printer->Print(vars, "$name$($number$),\n"); - } else { + } else { printer->Print(vars, "$name$($index$, $number$),\n"); - } + } printer->Annotate("name", canonical_values_[i]); - } - - if (SupportUnknownEnumValue(descriptor_->file())) { - if (ordinal_is_index) { + } + + if (SupportUnknownEnumValue(descriptor_->file())) { + if (ordinal_is_index) { printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", ""); - } else { + } else { printer->Print("${$UNRECOGNIZED$}$(-1, -1),\n", "{", "", "}", ""); - } + } printer->Annotate("{", "}", descriptor_); - } - - printer->Print( + } + + printer->Print( ";\n" "\n"); - - // ----------------------------------------------------------------- - - for (int i = 0; i < aliases_.size(); i++) { + + // ----------------------------------------------------------------- + + for (int i = 0; i < aliases_.size(); i++) { std::map<TProtoStringType, TProtoStringType> vars; - vars["classname"] = descriptor_->name(); - vars["name"] = aliases_[i].value->name(); - vars["canonical_name"] = aliases_[i].canonical_value->name(); - WriteEnumValueDocComment(printer, aliases_[i].value); + vars["classname"] = descriptor_->name(); + vars["name"] = aliases_[i].value->name(); + vars["canonical_name"] = aliases_[i].canonical_value->name(); + WriteEnumValueDocComment(printer, aliases_[i].value); printer->Print( vars, "public static final $classname$ $name$ = $canonical_name$;\n"); printer->Annotate("name", aliases_[i].value); - } - - for (int i = 0; i < descriptor_->value_count(); i++) { + } + + for (int i = 0; i < descriptor_->value_count(); i++) { std::map<TProtoStringType, TProtoStringType> vars; - vars["name"] = descriptor_->value(i)->name(); + vars["name"] = descriptor_->value(i)->name(); vars["number"] = StrCat(descriptor_->value(i)->number()); vars["{"] = ""; vars["}"] = ""; vars["deprecation"] = descriptor_->value(i)->options().deprecated() ? "@java.lang.Deprecated " : ""; - WriteEnumValueDocComment(printer, descriptor_->value(i)); - printer->Print(vars, + WriteEnumValueDocComment(printer, descriptor_->value(i)); + printer->Print(vars, "$deprecation$public static final int ${$$name$_VALUE$}$ = " "$number$;\n"); printer->Annotate("{", "}", descriptor_->value(i)); - } - printer->Print("\n"); - - // ----------------------------------------------------------------- - - printer->Print( + } + printer->Print("\n"); + + // ----------------------------------------------------------------- + + printer->Print( "\n" "public final int getNumber() {\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { - if (ordinal_is_index) { - printer->Print( + if (SupportUnknownEnumValue(descriptor_->file())) { + if (ordinal_is_index) { + printer->Print( " if (this == UNRECOGNIZED) {\n" " throw new java.lang.IllegalArgumentException(\n" " \"Can't get the number of an unknown enum value.\");\n" " }\n"); - } else { - printer->Print( + } else { + printer->Print( " if (index == -1) {\n" " throw new java.lang.IllegalArgumentException(\n" " \"Can't get the number of an unknown enum value.\");\n" " }\n"); - } - } - printer->Print( + } + } + printer->Print( " return value;\n" "}\n" "\n" @@ -197,18 +197,18 @@ void EnumGenerator::Generate(io::Printer* printer) { "public static $classname$ forNumber(int value) {\n" " switch (value) {\n", "classname", descriptor_->name()); - printer->Indent(); - printer->Indent(); - - for (int i = 0; i < canonical_values_.size(); i++) { + printer->Indent(); + printer->Indent(); + + 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())); - } - - printer->Outdent(); - printer->Outdent(); - printer->Print( + } + + printer->Outdent(); + printer->Outdent(); + printer->Print( " default: return null;\n" " }\n" "}\n" @@ -226,12 +226,12 @@ void EnumGenerator::Generate(io::Printer* printer) { " };\n" "\n", "classname", descriptor_->name()); - - // ----------------------------------------------------------------- - // Reflection - - if (HasDescriptorMethods(descriptor_, context_->EnforceLite())) { - printer->Print( + + // ----------------------------------------------------------------- + // Reflection + + if (HasDescriptorMethods(descriptor_, context_->EnforceLite())) { + printer->Print( "public final com.google.protobuf.Descriptors.EnumValueDescriptor\n" " getValueDescriptor() {\n"); if (SupportUnknownEnumValue(descriptor_->file())) { @@ -261,11 +261,11 @@ void EnumGenerator::Generate(io::Printer* printer) { "public static final com.google.protobuf.Descriptors.EnumDescriptor\n" " getDescriptor() {\n", "index_text", index_text); - - // TODO(kenton): Cache statically? Note that we can't access descriptors - // at module init time because it wouldn't work with descriptor.proto, but - // we can cache the value the first time getDescriptor() is called. - if (descriptor_->containing_type() == NULL) { + + // TODO(kenton): Cache statically? Note that we can't access descriptors + // at module init time because it wouldn't work with descriptor.proto, but + // we can cache the value the first time getDescriptor() is called. + if (descriptor_->containing_type() == NULL) { // The class generated for the File fully populates the descriptor with // extensions in both the mutable and immutable cases. (In the mutable api // this is accomplished by attempting to load the immutable outer class). @@ -274,9 +274,9 @@ void EnumGenerator::Generate(io::Printer* printer) { "file", name_resolver_->GetClassName(descriptor_->file(), immutable_api_), "index", StrCat(descriptor_->index())); - } else { - printer->Print( - " return $parent$.$descriptor$.getEnumTypes().get($index$);\n", + } else { + printer->Print( + " return $parent$.$descriptor$.getEnumTypes().get($index$);\n", "parent", name_resolver_->GetClassName(descriptor_->containing_type(), immutable_api_), @@ -287,40 +287,40 @@ void EnumGenerator::Generate(io::Printer* printer) { ? "getDefaultInstance().getDescriptorForType()" : "getDescriptor()", "index", StrCat(descriptor_->index())); - } - - printer->Print( + } + + printer->Print( "}\n" "\n" "private static final $classname$[] VALUES = ", "classname", descriptor_->name()); - - if (CanUseEnumValues()) { - // If the constants we are going to output are exactly the ones we - // have declared in the Java enum in the same order, then we can use - // the values() method that the Java compiler automatically generates - // for every enum. - printer->Print("values();\n"); - } else { + + if (CanUseEnumValues()) { + // If the constants we are going to output are exactly the ones we + // have declared in the Java enum in the same order, then we can use + // the values() method that the Java compiler automatically generates + // for every enum. + printer->Print("values();\n"); + } else { printer->Print("getStaticValuesArray();\n"); printer->Print("private static $classname$[] getStaticValuesArray() {\n", "classname", descriptor_->name()); printer->Indent(); - printer->Print( + printer->Print( "return new $classname$[] {\n" " ", "classname", descriptor_->name()); - for (int i = 0; i < descriptor_->value_count(); i++) { + for (int i = 0; i < descriptor_->value_count(); i++) { printer->Print("$name$, ", "name", descriptor_->value(i)->name()); - } - printer->Print( - "\n" - "};\n"); + } + printer->Print( + "\n" + "};\n"); printer->Outdent(); printer->Print("}"); - } - - printer->Print( + } + + printer->Print( "\n" "public static $classname$ valueOf(\n" " com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n" @@ -329,63 +329,63 @@ void EnumGenerator::Generate(io::Printer* printer) { " \"EnumValueDescriptor is not for this type.\");\n" " }\n", "classname", descriptor_->name()); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print( " if (desc.getIndex() == -1) {\n" " return UNRECOGNIZED;\n" " }\n"); - } - printer->Print( + } + printer->Print( " return VALUES[desc.getIndex()];\n" "}\n" "\n"); - - if (!ordinal_is_index) { - printer->Print("private final int index;\n"); - } - } - - // ----------------------------------------------------------------- - + + if (!ordinal_is_index) { + printer->Print("private final int index;\n"); + } + } + + // ----------------------------------------------------------------- + printer->Print("private final int value;\n\n"); - - if (ordinal_is_index) { + + if (ordinal_is_index) { printer->Print("private $classname$(int value) {\n", "classname", descriptor_->name()); - } else { + } else { printer->Print("private $classname$(int index, int value) {\n", "classname", descriptor_->name()); - } - if (HasDescriptorMethods(descriptor_, context_->EnforceLite()) && - !ordinal_is_index) { - printer->Print(" this.index = index;\n"); - } - printer->Print( + } + if (HasDescriptorMethods(descriptor_, context_->EnforceLite()) && + !ordinal_is_index) { + printer->Print(" this.index = index;\n"); + } + printer->Print( " this.value = value;\n" "}\n"); - - printer->Print( + + printer->Print( "\n" "// @@protoc_insertion_point(enum_scope:$full_name$)\n", "full_name", descriptor_->full_name()); - - printer->Outdent(); - printer->Print("}\n\n"); -} - -bool EnumGenerator::CanUseEnumValues() { - if (canonical_values_.size() != descriptor_->value_count()) { - return false; - } - for (int i = 0; i < descriptor_->value_count(); i++) { - if (descriptor_->value(i)->name() != canonical_values_[i]->name()) { - return false; - } - } - return true; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + + printer->Outdent(); + printer->Print("}\n\n"); +} + +bool EnumGenerator::CanUseEnumValues() { + if (canonical_values_.size() != descriptor_->value_count()) { + return false; + } + for (int i = 0; i < descriptor_->value_count(); i++) { + if (descriptor_->value(i)->name() != canonical_values_[i]->name()) { + return false; + } + } + return true; +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.h index 0a2c363b53..8974f8f005 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum.h @@ -1,46 +1,46 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ + #include <string> -#include <vector> +#include <vector> #include <google/protobuf/descriptor.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,52 +49,52 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class EnumGenerator { - public: - EnumGenerator(const EnumDescriptor* descriptor, bool immutable_api, - Context* context); - ~EnumGenerator(); - - void Generate(io::Printer* printer); - - private: - const EnumDescriptor* descriptor_; - +namespace protobuf { +namespace compiler { +namespace java { + +class EnumGenerator { + public: + EnumGenerator(const EnumDescriptor* descriptor, bool immutable_api, + Context* context); + ~EnumGenerator(); + + void Generate(io::Printer* printer); + + private: + const EnumDescriptor* descriptor_; + // The proto language allows multiple enum constants to have the same // numeric value. Java, however, does not allow multiple enum constants to // be considered equivalent. We treat the first defined constant for any - // given numeric value as "canonical" and the rest as aliases of that - // canonical value. + // given numeric value as "canonical" and the rest as aliases of that + // canonical value. std::vector<const EnumValueDescriptor*> canonical_values_; - - struct Alias { - const EnumValueDescriptor* value; - const EnumValueDescriptor* canonical_value; - }; + + struct Alias { + const EnumValueDescriptor* value; + const EnumValueDescriptor* canonical_value; + }; std::vector<Alias> aliases_; - - bool immutable_api_; - - Context* context_; - ClassNameResolver* name_resolver_; - - bool CanUseEnumValues(); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + bool immutable_api_; + + Context* context_; + ClassNameResolver* name_resolver_; + + bool CanUseEnumValues(); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.cc index 318c820198..dd0400414a 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.cc @@ -1,43 +1,43 @@ -// 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. - +// 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/java_enum_field.h> #include <cstdint> -#include <map> +#include <map> #include <string> - + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_context.h> @@ -47,34 +47,34 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { + void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - - (*variables)["type"] = - name_resolver->GetImmutableClassName(descriptor->enum_type()); + SetCommonFieldVariables(descriptor, info, variables); + + (*variables)["type"] = + name_resolver->GetImmutableClassName(descriptor->enum_type()); (*variables)["kt_type"] = (*variables)["type"]; - (*variables)["mutable_type"] = - name_resolver->GetMutableClassName(descriptor->enum_type()); - (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); + (*variables)["mutable_type"] = + name_resolver->GetMutableClassName(descriptor->enum_type()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_number"] = StrCat(descriptor->default_value_enum()->number()); (*variables)["tag"] = StrCat( static_cast<int32_t>(internal::WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( - internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + 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"] = @@ -82,123 +82,123 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, ? "@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 + (*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)["for_number"] = "valueOf"; + 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)["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"] = + // 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)["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()"; - } - + } + // 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_from_local"] = - GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); - - if (SupportUnknownEnumValue(descriptor->file())) { - (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED"; - } else { - (*variables)["unknown"] = (*variables)["default"]; - } -} - -} // namespace - -// =================================================================== - + (*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_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); + + if (SupportUnknownEnumValue(descriptor->file())) { + (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED"; + } else { + (*variables)["unknown"] = (*variables)["default"]; + } +} + +} // namespace + +// =================================================================== + ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, + SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); -} - -ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {} - -int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const { +} + +ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {} + +int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; -} - -int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { +} + +int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { return GetNumBitsForMessage(); -} - +} + void ImmutableEnumFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); - } - if (SupportUnknownEnumValue(descriptor_->file())) { + } + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Value();\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); -} - +} + void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const { printer->Print(variables_, "private int $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override $deprecation$public boolean " "${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - if (SupportUnknownEnumValue(descriptor_->file())) { + } + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override $deprecation$public int " "${$get$capitalized_name$Value$}$() {\n" " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override $deprecation$public $type$ " "${$get$capitalized_name$$}$() {\n" " @SuppressWarnings(\"deprecation\")\n" @@ -206,23 +206,23 @@ void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const { " return result == null ? $unknown$ : result;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableEnumFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { printer->Print(variables_, "private int $name$_ = $default_number$;\n"); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override $deprecation$public boolean " "${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_builder$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - if (SupportUnknownEnumValue(descriptor_->file())) { + } + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override $deprecation$public int " "${$get$capitalized_name$Value$}$() {\n" " return $name$_;\n" @@ -230,7 +230,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$Value$}$(int value) {\n" " $set_has_field_bit_builder$\n" @@ -239,9 +239,9 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " @SuppressWarnings(\"deprecation\")\n" @@ -251,7 +251,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " if (value == null) {\n" @@ -274,8 +274,8 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -306,59 +306,59 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( void ImmutableEnumFieldGenerator::GenerateFieldBuilderInitializationCode( io::Printer* printer) const { - // noop for enums -} - + // noop for enums +} + void ImmutableEnumFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = $default_number$;\n"); -} - + printer->Print(variables_, "$name$_ = $default_number$;\n"); +} + void ImmutableEnumFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "$name$_ = $default_number$;\n" "$clear_has_field_bit_builder$\n"); -} - +} + void ImmutableEnumFieldGenerator::GenerateMergingCode( io::Printer* printer) const { if (HasHazzer(descriptor_)) { - printer->Print(variables_, + printer->Print(variables_, "if (other.has$capitalized_name$()) {\n" " set$capitalized_name$(other.get$capitalized_name$());\n" "}\n"); - } else if (SupportUnknownEnumValue(descriptor_->file())) { + } else if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, "if (other.$name$_ != $default_number$) {\n" " set$capitalized_name$Value(other.get$capitalized_name$Value());\n" "}\n"); - } else { - GOOGLE_LOG(FATAL) << "Can't reach here."; - } -} - + } else { + GOOGLE_LOG(FATAL) << "Can't reach here."; + } +} + void ImmutableEnumFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { if (HasHazzer(descriptor_)) { - printer->Print(variables_, + printer->Print(variables_, "if ($get_has_field_bit_from_local$) {\n" " $set_has_field_bit_to_local$;\n" "}\n"); - } + } printer->Print(variables_, "result.$name$_ = $name$_;\n"); -} - +} + void ImmutableEnumFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print(variables_, + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print(variables_, "int rawValue = input.readEnum();\n" "$set_has_field_bit_message$\n" "$name$_ = rawValue;\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "int rawValue = input.readEnum();\n" " @SuppressWarnings(\"deprecation\")\n" "$type$ value = $type$.$for_number$(rawValue);\n" @@ -368,63 +368,63 @@ void ImmutableEnumFieldGenerator::GenerateParsingCode( " $set_has_field_bit_message$\n" " $name$_ = rawValue;\n" "}\n"); - } -} - + } +} + void ImmutableEnumFieldGenerator::GenerateParsingDoneCode( io::Printer* printer) const { - // noop for enums -} - + // noop for enums +} + void ImmutableEnumFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($is_field_present_message$) {\n" " output.writeEnum($number$, $name$_);\n" "}\n"); -} - +} + void ImmutableEnumFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($is_field_present_message$) {\n" " size += com.google.protobuf.CodedOutputStream\n" " .computeEnumSize($number$, $name$_);\n" "}\n"); -} - +} + void ImmutableEnumFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { printer->Print(variables_, "if ($name$_ != other.$name$_) return false;\n"); -} - +} + void ImmutableEnumFieldGenerator::GenerateHashCode(io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "hash = (37 * hash) + $constant_name$;\n" "hash = (53 * hash) + $name$_;\n"); -} - +} + TProtoStringType ImmutableEnumFieldGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); -} - -// =================================================================== - + return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); +} + +// =================================================================== + ImmutableEnumOneofFieldGenerator::ImmutableEnumOneofFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : ImmutableEnumFieldGenerator(descriptor, messageBitIndex, builderBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + ImmutableEnumOneofFieldGenerator::~ImmutableEnumOneofFieldGenerator() {} - + void ImmutableEnumOneofFieldGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, @@ -433,7 +433,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -444,9 +444,9 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers( " return $default_number$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " @SuppressWarnings(\"deprecation\")\n" @@ -457,8 +457,8 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers( " return $default$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { GOOGLE_DCHECK(HasHazzer(descriptor_)); @@ -470,7 +470,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -484,7 +484,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$Value$}$(int value) {\n" " $set_oneof_case_message$;\n" @@ -493,9 +493,9 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" @@ -509,7 +509,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " if (value == null) {\n" @@ -534,37 +534,37 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableEnumOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($has_oneof_case_message$) {\n" " result.$oneof_name$_ = $oneof_name$_;\n" "}\n"); -} - +} + void ImmutableEnumOneofFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, "set$capitalized_name$Value(other.get$capitalized_name$Value());\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "set$capitalized_name$(other.get$capitalized_name$());\n"); - } -} - + } +} + void ImmutableEnumOneofFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print(variables_, + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print(variables_, "int rawValue = input.readEnum();\n" "$set_oneof_case_message$;\n" "$oneof_name$_ = rawValue;\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "int rawValue = input.readEnum();\n" "@SuppressWarnings(\"deprecation\")\n" "$type$ value = $type$.$for_number$(rawValue);\n" @@ -574,9 +574,9 @@ void ImmutableEnumOneofFieldGenerator::GenerateParsingCode( " $set_oneof_case_message$;\n" " $oneof_name$_ = rawValue;\n" "}\n"); - } -} - + } +} + void ImmutableEnumOneofFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { printer->Print( @@ -584,8 +584,8 @@ void ImmutableEnumOneofFieldGenerator::GenerateSerializationCode( "if ($has_oneof_case_message$) {\n" " output.writeEnum($number$, ((java.lang.Integer) $oneof_name$_));\n" "}\n"); -} - +} + void ImmutableEnumOneofFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { printer->Print( @@ -594,58 +594,58 @@ void ImmutableEnumOneofFieldGenerator::GenerateSerializedSizeCode( " size += com.google.protobuf.CodedOutputStream\n" " .computeEnumSize($number$, ((java.lang.Integer) $oneof_name$_));\n" "}\n"); -} - +} + void ImmutableEnumOneofFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, "if (get$capitalized_name$Value()\n" " != other.get$capitalized_name$Value()) return false;\n"); - } else { + } else { printer->Print( variables_, "if (!get$capitalized_name$()\n" " .equals(other.get$capitalized_name$())) return false;\n"); - } -} - + } +} + void ImmutableEnumOneofFieldGenerator::GenerateHashCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print(variables_, + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print(variables_, "hash = (37 * hash) + $constant_name$;\n" "hash = (53 * hash) + get$capitalized_name$Value();\n"); - } else { + } else { printer->Print( variables_, "hash = (37 * hash) + $constant_name$;\n" "hash = (53 * hash) + get$capitalized_name$().getNumber();\n"); - } -} - -// =================================================================== - + } +} + +// =================================================================== + RepeatedImmutableEnumFieldGenerator::RepeatedImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, + SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); -} - -RepeatedImmutableEnumFieldGenerator::~RepeatedImmutableEnumFieldGenerator() {} - -int RepeatedImmutableEnumFieldGenerator::GetNumBitsForMessage() const { - return 0; -} - -int RepeatedImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { - return 1; -} - +} + +RepeatedImmutableEnumFieldGenerator::~RepeatedImmutableEnumFieldGenerator() {} + +int RepeatedImmutableEnumFieldGenerator::GetNumBitsForMessage() const { + return 0; +} + +int RepeatedImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { + return 1; +} + void RepeatedImmutableEnumFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); @@ -653,23 +653,23 @@ void RepeatedImmutableEnumFieldGenerator::GenerateInterfaceMembers( variables_, "$deprecation$java.util.List<$type$> get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$(int index);\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$java.util.List<java.lang.Integer>\n" "get$capitalized_name$ValueList();\n"); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Value(int index);\n"); - } -} - + } +} + void RepeatedImmutableEnumFieldGenerator::GenerateMembers( io::Printer* printer) const { printer->Print( @@ -686,7 +686,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers( " return result == null ? $unknown$ : result;\n" " }\n" " };\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print( variables_, @@ -713,9 +713,9 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers( " return $name$_converter_.convert($name$_.get(index));\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<java.lang.Integer>\n" "${$get$capitalized_name$ValueList$}$() {\n" @@ -724,20 +724,20 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public int " "${$get$capitalized_name$Value$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + if (descriptor_->is_packed()) { printer->Print(variables_, "private int $name$MemoizedSerializedSize;\n"); - } -} - + } +} + void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { printer->Print( @@ -753,14 +753,14 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( // list can never be modified. "private java.util.List<java.lang.Integer> $name$_ =\n" " java.util.Collections.emptyList();\n" - + "private void ensure$capitalized_name$IsMutable() {\n" " if (!$get_mutable_bit_builder$) {\n" " $name$_ = new java.util.ArrayList<java.lang.Integer>($name$_);\n" " $set_mutable_bit_builder$;\n" " }\n" "}\n"); - + WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print( variables_, @@ -790,7 +790,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " if (value == null) {\n" @@ -804,7 +804,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$$}$($type$ value) {\n" " if (value == null) {\n" @@ -818,7 +818,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -840,10 +840,10 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - if (SupportUnknownEnumValue(descriptor_->file())) { + + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public java.util.List<java.lang.Integer>\n" "${$get$capitalized_name$ValueList$}$() {\n" " return java.util.Collections.unmodifiableList($name$_);\n" @@ -851,7 +851,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public int " "${$get$capitalized_name$Value$}$(int index) {\n" " return $name$_.get(index);\n" @@ -872,7 +872,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$Value$}$(int value) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -895,34 +895,34 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } -} - -void RepeatedImmutableEnumFieldGenerator:: + } +} + +void RepeatedImmutableEnumFieldGenerator:: GenerateFieldBuilderInitializationCode(io::Printer* printer) const { - // noop for enums -} - + // noop for enums +} + void RepeatedImmutableEnumFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = java.util.Collections.emptyList();\n"); -} - + printer->Print(variables_, "$name$_ = java.util.Collections.emptyList();\n"); +} + void RepeatedImmutableEnumFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "$name$_ = java.util.Collections.emptyList();\n" "$clear_mutable_bit_builder$;\n"); -} - +} + void RepeatedImmutableEnumFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - // The code below does two optimizations: - // 1. If the other list is empty, there's nothing to do. This ensures we - // don't allocate a new array if we already have an immutable one. - // 2. If the other list is non-empty and our current list is empty, we can - // reuse the other list which is guaranteed to be immutable. - printer->Print(variables_, + // The code below does two optimizations: + // 1. If the other list is empty, there's nothing to do. This ensures we + // don't allocate a new array if we already have an immutable one. + // 2. If the other list is non-empty and our current list is empty, we can + // reuse the other list which is guaranteed to be immutable. + printer->Print(variables_, "if (!other.$name$_.isEmpty()) {\n" " if ($name$_.isEmpty()) {\n" " $name$_ = other.$name$_;\n" @@ -933,12 +933,12 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMergingCode( " }\n" " $on_changed$\n" "}\n"); -} - +} + void RepeatedImmutableEnumFieldGenerator::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. + // 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" @@ -946,20 +946,20 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuildingCode( " $clear_mutable_bit_builder$;\n" "}\n" "result.$name$_ = $name$_;\n"); -} - +} + void RepeatedImmutableEnumFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - // Read and store the enum - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print(variables_, + // 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"); - } else { + } else { printer->Print( variables_, "int rawValue = input.readEnum();\n" @@ -974,27 +974,27 @@ void RepeatedImmutableEnumFieldGenerator::GenerateParsingCode( " }\n" " $name$_.add(rawValue);\n" "}\n"); - } -} - + } +} + void RepeatedImmutableEnumFieldGenerator::GenerateParsingCodeFromPacked( io::Printer* printer) const { - // Wrap GenerateParsingCode's contents with a while loop. - - printer->Print(variables_, + // Wrap GenerateParsingCode's contents with a while loop. + + printer->Print(variables_, "int length = input.readRawVarint32();\n" "int oldLimit = input.pushLimit(length);\n" "while(input.getBytesUntilLimit() > 0) {\n"); - printer->Indent(); - - GenerateParsingCode(printer); - - printer->Outdent(); - printer->Print(variables_, + printer->Indent(); + + GenerateParsingCode(printer); + + printer->Outdent(); + printer->Print(variables_, "}\n" "input.popLimit(oldLimit);\n"); -} - +} + void RepeatedImmutableEnumFieldGenerator::GenerateParsingDoneCode( io::Printer* printer) const { printer->Print( @@ -1002,12 +1002,12 @@ void RepeatedImmutableEnumFieldGenerator::GenerateParsingDoneCode( "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()) { - printer->Print(variables_, + if (descriptor_->is_packed()) { + printer->Print(variables_, "if (get$capitalized_name$List().size() > 0) {\n" " output.writeUInt32NoTag($tag$);\n" " output.writeUInt32NoTag($name$MemoizedSerializedSize);\n" @@ -1015,62 +1015,62 @@ void RepeatedImmutableEnumFieldGenerator::GenerateSerializationCode( "for (int i = 0; i < $name$_.size(); i++) {\n" " output.writeEnumNoTag($name$_.get(i));\n" "}\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "for (int i = 0; i < $name$_.size(); i++) {\n" " output.writeEnum($number$, $name$_.get(i));\n" "}\n"); - } -} - + } +} + void RepeatedImmutableEnumFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "{\n" " int dataSize = 0;\n"); - printer->Indent(); - - printer->Print(variables_, + printer->Indent(); + + printer->Print(variables_, "for (int i = 0; i < $name$_.size(); i++) {\n" " dataSize += com.google.protobuf.CodedOutputStream\n" " .computeEnumSizeNoTag($name$_.get(i));\n" "}\n"); printer->Print("size += dataSize;\n"); - if (descriptor_->is_packed()) { - printer->Print(variables_, + if (descriptor_->is_packed()) { + printer->Print(variables_, "if (!get$capitalized_name$List().isEmpty()) {" " size += $tag_size$;\n" " size += com.google.protobuf.CodedOutputStream\n" " .computeUInt32SizeNoTag(dataSize);\n" "}"); - } else { + } else { printer->Print(variables_, "size += $tag_size$ * $name$_.size();\n"); - } - - // cache the data size for packed fields. - if (descriptor_->is_packed()) { + } + + // cache the data size for packed fields. + if (descriptor_->is_packed()) { printer->Print(variables_, "$name$MemoizedSerializedSize = dataSize;\n"); - } - - printer->Outdent(); - printer->Print("}\n"); -} - + } + + printer->Outdent(); + printer->Print("}\n"); +} + void RepeatedImmutableEnumFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if (!$name$_.equals(other.$name$_)) return false;\n"); -} - +} + void RepeatedImmutableEnumFieldGenerator::GenerateHashCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if (get$capitalized_name$Count() > 0) {\n" " hash = (37 * hash) + $constant_name$;\n" " hash = (53 * hash) + $name$_.hashCode();\n" "}\n"); -} - +} + void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -1164,10 +1164,10 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( } TProtoStringType RepeatedImmutableEnumFieldGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.h index 13414bd8db..27108d7ff1 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field.h @@ -1,46 +1,46 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ - -#include <map> +// 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. + +#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/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,19 +49,19 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { - public: +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { + public: explicit ImmutableEnumFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); ~ImmutableEnumFieldGenerator() override; - + // implements ImmutableFieldGenerator // --------------------------------------- int GetNumBitsForMessage() const override; @@ -82,47 +82,47 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const override; void GenerateHashCode(io::Printer* printer) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - protected: - const FieldDescriptor* descriptor_; + + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldGenerator); -}; - -class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator { - public: + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldGenerator); +}; + +class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator { + public: ImmutableEnumOneofFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); - ~ImmutableEnumOneofFieldGenerator(); - - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldGenerator); -}; - -class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { - public: - explicit RepeatedImmutableEnumFieldGenerator( - const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, Context* context); + ~ImmutableEnumOneofFieldGenerator(); + + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldGenerator); +}; + +class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { + public: + explicit RepeatedImmutableEnumFieldGenerator( + const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, Context* context); ~RepeatedImmutableEnumFieldGenerator() override; - - // implements ImmutableFieldGenerator --------------------------------------- + + // implements ImmutableFieldGenerator --------------------------------------- int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -142,20 +142,20 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const override; void GenerateHashCode(io::Printer* printer) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; + + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.cc index e94f70289b..f96915d57a 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.cc @@ -1,43 +1,43 @@ -// 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. - +// 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/java_enum_field_lite.h> #include <cstdint> -#include <map> +#include <map> #include <string> - + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_context.h> @@ -47,13 +47,13 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { bool EnableExperimentalRuntimeForLite() { #ifdef PROTOBUF_EXPERIMENT return PROTOBUF_EXPERIMENT; @@ -61,27 +61,27 @@ bool EnableExperimentalRuntimeForLite() { return false; #endif // !PROTOBUF_EXPERIMENT } - + void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - - (*variables)["type"] = - name_resolver->GetImmutableClassName(descriptor->enum_type()); + SetCommonFieldVariables(descriptor, info, variables); + + (*variables)["type"] = + name_resolver->GetImmutableClassName(descriptor->enum_type()); (*variables)["kt_type"] = (*variables)["type"]; - (*variables)["mutable_type"] = - name_resolver->GetMutableClassName(descriptor->enum_type()); - (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); + (*variables)["mutable_type"] = + name_resolver->GetMutableClassName(descriptor->enum_type()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_number"] = StrCat(descriptor->default_value_enum()->number()); (*variables)["tag"] = StrCat( static_cast<int32_t>(internal::WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( - internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + 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"] = @@ -90,47 +90,47 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, " is deprecated\") " : ""; (*variables)["required"] = descriptor->is_required() ? "true" : "false"; - + if (HasHasbit(descriptor)) { - // 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) + ";"; - (*variables)["clear_has_field_bit_message"] = - 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"] = + // 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) + ";"; + (*variables)["clear_has_field_bit_message"] = + 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)["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"; - } else { - (*variables)["unknown"] = (*variables)["default"]; - } + } + + (*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"; + } else { + (*variables)["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"; -} - -} // namespace - -// =================================================================== - +} + +} // namespace + +// =================================================================== + ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), @@ -140,34 +140,34 @@ ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator( SetEnumVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); -} - -ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator() {} - -int ImmutableEnumFieldLiteGenerator::GetNumBitsForMessage() const { +} + +ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator() {} + +int ImmutableEnumFieldLiteGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; -} - +} + void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); - } - if (SupportUnknownEnumValue(descriptor_->file())) { + } + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Value();\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); -} - +} + void ImmutableEnumFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private int $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -177,8 +177,8 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - if (SupportUnknownEnumValue(descriptor_->file())) { + } + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -187,39 +187,39 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers( " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " $type$ result = $type$.forNumber($name$_);\n" " return result == null ? $unknown$ : result;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Generate private setters for the builder to proxy into. - if (SupportUnknownEnumValue(descriptor_->file())) { + + // Generate private setters for the builder to proxy into. + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$Value(int value) {\n" " $set_has_field_bit_message$" " $name$_ = value;\n" "}\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$($type$ value) {\n" " $name$_ = value.getNumber();\n" " $set_has_field_bit_message$\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " $clear_has_field_bit_message$\n" " $name$_ = $default_number$;\n" "}\n"); -} - +} + void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { @@ -231,8 +231,8 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( " return instance.has$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - if (SupportUnknownEnumValue(descriptor_->file())) { + } + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -243,7 +243,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$Value$}$(int value) {\n" " copyOnWrite();\n" @@ -251,9 +251,9 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" @@ -261,7 +261,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -279,8 +279,8 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -311,11 +311,11 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( void ImmutableEnumFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - if (!IsDefaultValueJavaDefault(descriptor_)) { - printer->Print(variables_, "$name$_ = $default_number$;\n"); - } -} - + if (!IsDefaultValueJavaDefault(descriptor_)) { + printer->Print(variables_, "$name$_ = $default_number$;\n"); + } +} + void ImmutableEnumFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); @@ -323,35 +323,35 @@ void ImmutableEnumFieldLiteGenerator::GenerateFieldInfo( output); if (HasHasbit(descriptor_)) { WriteIntToUtf16CharSequence(messageBitIndex_, output); - } + } printer->Print(variables_, "\"$name$_\",\n"); if (!SupportUnknownEnumValue((descriptor_))) { PrintEnumVerifierLogic(printer, descriptor_, variables_, /*var_name=*/"$type$", /*terminating_string=*/",\n", /*enforce_lite=*/context_->EnforceLite()); - } -} - + } +} + TProtoStringType ImmutableEnumFieldLiteGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); -} - -// =================================================================== - + return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); +} + +// =================================================================== + ImmutableEnumOneofFieldLiteGenerator::ImmutableEnumOneofFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : ImmutableEnumFieldLiteGenerator(descriptor, messageBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + ImmutableEnumOneofFieldLiteGenerator::~ImmutableEnumOneofFieldLiteGenerator() {} - + void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, @@ -361,7 +361,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -373,9 +373,9 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( " return $default_number$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" @@ -386,32 +386,32 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( " return $default$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Generate private setters for the builder to proxy into. - if (SupportUnknownEnumValue(descriptor_->file())) { + + // Generate private setters for the builder to proxy into. + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$Value(int value) {\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" "}\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$($type$ value) {\n" " $oneof_name$_ = value.getNumber();\n" " $set_oneof_case_message$;\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" " }\n" "}\n"); -} - +} + void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); @@ -437,7 +437,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -448,7 +448,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$Value$}$(int value) {\n" " copyOnWrite();\n" @@ -456,9 +456,9 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" @@ -466,7 +466,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -484,11 +484,11 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - -// =================================================================== - -RepeatedImmutableEnumFieldLiteGenerator:: +} + +// =================================================================== + +RepeatedImmutableEnumFieldLiteGenerator:: RepeatedImmutableEnumFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context) @@ -498,15 +498,15 @@ RepeatedImmutableEnumFieldLiteGenerator:: SetEnumVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); -} - -RepeatedImmutableEnumFieldLiteGenerator:: +} + +RepeatedImmutableEnumFieldLiteGenerator:: ~RepeatedImmutableEnumFieldLiteGenerator() {} - -int RepeatedImmutableEnumFieldLiteGenerator::GetNumBitsForMessage() const { - return 0; -} - + +int RepeatedImmutableEnumFieldLiteGenerator::GetNumBitsForMessage() const { + return 0; +} + void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); @@ -514,23 +514,23 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers( variables_, "$deprecation$java.util.List<$type$> get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$(int index);\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$java.util.List<java.lang.Integer>\n" "get$capitalized_name$ValueList();\n"); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Value(int index);\n"); - } -} - + } +} + void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { printer->Print( @@ -547,7 +547,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " return result == null ? $unknown$ : result;\n" " }\n" " };\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print( variables_, @@ -574,9 +574,9 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " return $name$_converter_.convert($name$_.getInt(index));\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<java.lang.Integer>\n" "${$get$capitalized_name$ValueList$}$() {\n" @@ -585,21 +585,21 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public int " "${$get$capitalized_name$Value$}$(int index) {\n" " return $name$_.getInt(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + if (!EnableExperimentalRuntimeForLite() && descriptor_->is_packed() && - context_->HasGeneratedMethods(descriptor_->containing_type())) { + context_->HasGeneratedMethods(descriptor_->containing_type())) { printer->Print(variables_, "private int $name$MemoizedSerializedSize;\n"); - } - - // Generate private setters for the builder to proxy into. + } + + // Generate private setters for the builder to proxy into. printer->Print( variables_, "private void ensure$capitalized_name$IsMutable() {\n" @@ -611,7 +611,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " }\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$(\n" " int index, $type$ value) {\n" " $null_check$" @@ -619,14 +619,14 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " $name$_.setInt(index, value.getNumber());\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void add$capitalized_name$($type$ value) {\n" " $null_check$" " ensure$capitalized_name$IsMutable();\n" " $name$_.addInt(value.getNumber());\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void addAll$capitalized_name$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -635,28 +635,28 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " }\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " $name$_ = emptyIntList();\n" "}\n"); - - if (SupportUnknownEnumValue(descriptor_->file())) { + + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$Value(\n" " int index, int value) {\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.setInt(index, value);\n" "}\n"); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void add$capitalized_name$Value(int value) {\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.addInt(value);\n" "}\n"); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void addAll$capitalized_name$Value(\n" " java.lang.Iterable<java.lang.Integer> values) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -664,9 +664,9 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " $name$_.addInt(value);\n" " }\n" "}\n"); - } -} - + } +} + void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); @@ -684,7 +684,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo( void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<$type$> " "${$get$capitalized_name$List$}$() {\n" @@ -709,7 +709,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" @@ -719,7 +719,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -729,7 +729,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " copyOnWrite();\n" @@ -747,10 +747,10 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - if (SupportUnknownEnumValue(descriptor_->file())) { + + if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<java.lang.Integer>\n" "${$get$capitalized_name$ValueList$}$() {\n" @@ -760,7 +760,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public int " "${$get$capitalized_name$Value$}$(int index) {\n" @@ -781,7 +781,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$Value$}$(int value) {\n" " instance.add$capitalized_name$Value(value);\n" @@ -800,14 +800,14 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } -} - + } +} + void RepeatedImmutableEnumFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = emptyIntList();\n"); -} - + printer->Print(variables_, "$name$_ = emptyIntList();\n"); +} + void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -901,10 +901,10 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( } TProtoStringType RepeatedImmutableEnumFieldLiteGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.h index eb8e8cd313..3b856b0c60 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_field_lite.h @@ -1,48 +1,48 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ + #include <cstdint> -#include <map> +#include <map> #include <string> #include <google/protobuf/compiler/java/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -51,19 +51,19 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { - public: +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { + public: explicit ImmutableEnumFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~ImmutableEnumFieldLiteGenerator() override; - + // implements ImmutableFieldLiteGenerator // ------------------------------------ int GetNumBitsForMessage() const override; @@ -74,44 +74,44 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - protected: - const FieldDescriptor* descriptor_; + + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - const int messageBitIndex_; - Context* context_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldLiteGenerator); -}; - -class ImmutableEnumOneofFieldLiteGenerator - : public ImmutableEnumFieldLiteGenerator { - public: + const int messageBitIndex_; + Context* context_; + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldLiteGenerator); +}; + +class ImmutableEnumOneofFieldLiteGenerator + : public ImmutableEnumFieldLiteGenerator { + public: ImmutableEnumOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~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 - : public ImmutableFieldLiteGenerator { - public: - explicit RepeatedImmutableEnumFieldLiteGenerator( + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldLiteGenerator); +}; + +class RepeatedImmutableEnumFieldLiteGenerator + : public ImmutableFieldLiteGenerator { + public: + explicit RepeatedImmutableEnumFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~RepeatedImmutableEnumFieldLiteGenerator() override; - - // implements ImmutableFieldLiteGenerator ------------------------------------ + + // implements ImmutableFieldLiteGenerator ------------------------------------ int GetNumBitsForMessage() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; void GenerateMembers(io::Printer* printer) const override; @@ -120,21 +120,21 @@ class RepeatedImmutableEnumFieldLiteGenerator void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; + + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - Context* context_; - ClassNameResolver* name_resolver_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + Context* context_; + ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.cc index bf84607aac..f8e5943969 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.cc @@ -1,40 +1,40 @@ -// 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 <map> +// 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 <map> #include <string> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_enum_lite.h> @@ -44,101 +44,101 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/map_util.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -EnumLiteGenerator::EnumLiteGenerator(const EnumDescriptor* descriptor, - bool immutable_api, Context* context) - : descriptor_(descriptor), - immutable_api_(immutable_api), - context_(context), - name_resolver_(context->GetNameResolver()) { - for (int i = 0; i < descriptor_->value_count(); i++) { - const EnumValueDescriptor* value = descriptor_->value(i); - const EnumValueDescriptor* canonical_value = + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +EnumLiteGenerator::EnumLiteGenerator(const EnumDescriptor* descriptor, + bool immutable_api, Context* context) + : descriptor_(descriptor), + immutable_api_(immutable_api), + context_(context), + name_resolver_(context->GetNameResolver()) { + for (int i = 0; i < descriptor_->value_count(); i++) { + const EnumValueDescriptor* value = descriptor_->value(i); + const EnumValueDescriptor* canonical_value = descriptor_->FindValueByNumber(value->number()); - - if (value == canonical_value) { - canonical_values_.push_back(value); - } else { - Alias alias; - alias.value = value; - alias.canonical_value = canonical_value; - aliases_.push_back(alias); - } - } -} - -EnumLiteGenerator::~EnumLiteGenerator() {} - -void EnumLiteGenerator::Generate(io::Printer* printer) { - WriteEnumDocComment(printer, descriptor_); - MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_); - printer->Print( + + if (value == canonical_value) { + canonical_values_.push_back(value); + } else { + Alias alias; + alias.value = value; + alias.canonical_value = canonical_value; + aliases_.push_back(alias); + } + } +} + +EnumLiteGenerator::~EnumLiteGenerator() {} + +void EnumLiteGenerator::Generate(io::Printer* printer) { + WriteEnumDocComment(printer, descriptor_); + MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_); + printer->Print( "$deprecation$public enum $classname$\n" - " implements com.google.protobuf.Internal.EnumLite {\n", + " implements com.google.protobuf.Internal.EnumLite {\n", "classname", descriptor_->name(), "deprecation", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""); - printer->Annotate("classname", descriptor_); - printer->Indent(); - - for (int i = 0; i < canonical_values_.size(); i++) { + printer->Annotate("classname", descriptor_); + printer->Indent(); + + for (int i = 0; i < canonical_values_.size(); i++) { std::map<TProtoStringType, TProtoStringType> vars; - vars["name"] = canonical_values_[i]->name(); + vars["name"] = canonical_values_[i]->name(); vars["number"] = StrCat(canonical_values_[i]->number()); - WriteEnumValueDocComment(printer, canonical_values_[i]); - if (canonical_values_[i]->options().deprecated()) { - printer->Print("@java.lang.Deprecated\n"); - } + WriteEnumValueDocComment(printer, canonical_values_[i]); + if (canonical_values_[i]->options().deprecated()) { + printer->Print("@java.lang.Deprecated\n"); + } printer->Print(vars, "$name$($number$),\n"); printer->Annotate("name", canonical_values_[i]); - } - - if (SupportUnknownEnumValue(descriptor_->file())) { + } + + if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", ""); printer->Annotate("{", "}", descriptor_); - } - - printer->Print( + } + + printer->Print( ";\n" "\n"); - - // ----------------------------------------------------------------- - - for (int i = 0; i < aliases_.size(); i++) { + + // ----------------------------------------------------------------- + + for (int i = 0; i < aliases_.size(); i++) { std::map<TProtoStringType, TProtoStringType> vars; - vars["classname"] = descriptor_->name(); - vars["name"] = aliases_[i].value->name(); - vars["canonical_name"] = aliases_[i].canonical_value->name(); - WriteEnumValueDocComment(printer, aliases_[i].value); + vars["classname"] = descriptor_->name(); + vars["name"] = aliases_[i].value->name(); + vars["canonical_name"] = aliases_[i].canonical_value->name(); + WriteEnumValueDocComment(printer, aliases_[i].value); printer->Print( vars, "public static final $classname$ $name$ = $canonical_name$;\n"); printer->Annotate("name", aliases_[i].value); - } - - for (int i = 0; i < descriptor_->value_count(); i++) { + } + + for (int i = 0; i < descriptor_->value_count(); i++) { std::map<TProtoStringType, TProtoStringType> vars; - vars["name"] = descriptor_->value(i)->name(); + vars["name"] = descriptor_->value(i)->name(); vars["number"] = StrCat(descriptor_->value(i)->number()); vars["{"] = ""; vars["}"] = ""; vars["deprecation"] = descriptor_->value(i)->options().deprecated() ? "@java.lang.Deprecated " : ""; - WriteEnumValueDocComment(printer, descriptor_->value(i)); - printer->Print(vars, + WriteEnumValueDocComment(printer, descriptor_->value(i)); + printer->Print(vars, "$deprecation$public static final int ${$$name$_VALUE$}$ = " "$number$;\n"); printer->Annotate("{", "}", descriptor_->value(i)); - } - printer->Print("\n"); - - // ----------------------------------------------------------------- - - printer->Print( + } + printer->Print("\n"); + + // ----------------------------------------------------------------- + + printer->Print( "\n" "@java.lang.Override\n" "public final int getNumber() {\n"); @@ -166,18 +166,18 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { "public static $classname$ forNumber(int value) {\n" " switch (value) {\n", "classname", descriptor_->name()); - printer->Indent(); - printer->Indent(); - - for (int i = 0; i < canonical_values_.size(); i++) { + printer->Indent(); + printer->Indent(); + + 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())); - } - - printer->Outdent(); - printer->Outdent(); - printer->Print( + } + + printer->Outdent(); + printer->Outdent(); + printer->Print( " default: return null;\n" " }\n" "}\n" @@ -211,25 +211,25 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { " };\n" "\n", "classname", descriptor_->name()); - - printer->Print( + + printer->Print( "private final int value;\n\n" "private $classname$(int value) {\n", "classname", descriptor_->name()); - printer->Print( + printer->Print( " this.value = value;\n" "}\n"); - - printer->Print( + + printer->Print( "\n" "// @@protoc_insertion_point(enum_scope:$full_name$)\n", "full_name", descriptor_->full_name()); - - printer->Outdent(); - printer->Print("}\n\n"); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + + printer->Outdent(); + printer->Print("}\n\n"); +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.h index 50f3fe7b1a..c1d1b26efc 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_enum_lite.h @@ -1,46 +1,46 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ + #include <string> -#include <vector> +#include <vector> #include <google/protobuf/descriptor.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,50 +49,50 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class EnumLiteGenerator { - public: - EnumLiteGenerator(const EnumDescriptor* descriptor, bool immutable_api, - Context* context); - ~EnumLiteGenerator(); - - void Generate(io::Printer* printer); - - private: - const EnumDescriptor* descriptor_; - +namespace protobuf { +namespace compiler { +namespace java { + +class EnumLiteGenerator { + public: + EnumLiteGenerator(const EnumDescriptor* descriptor, bool immutable_api, + Context* context); + ~EnumLiteGenerator(); + + void Generate(io::Printer* printer); + + private: + const EnumDescriptor* descriptor_; + // The proto language allows multiple enum constants to have the same // numeric value. Java, however, does not allow multiple enum constants to // be considered equivalent. We treat the first defined constant for any - // given numeric value as "canonical" and the rest as aliases of that - // canonical value. + // given numeric value as "canonical" and the rest as aliases of that + // canonical value. std::vector<const EnumValueDescriptor*> canonical_values_; - - struct Alias { - const EnumValueDescriptor* value; - const EnumValueDescriptor* canonical_value; - }; + + struct Alias { + const EnumValueDescriptor* value; + const EnumValueDescriptor* canonical_value; + }; std::vector<Alias> aliases_; - - bool immutable_api_; - - Context* context_; - ClassNameResolver* name_resolver_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + bool immutable_api_; + + Context* context_; + ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.cc index 9602780c49..fb51d1ef86 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.cc @@ -1,172 +1,172 @@ -// 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. - +// 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/java_extension.h> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -ImmutableExtensionGenerator::ImmutableExtensionGenerator( - const FieldDescriptor* descriptor, Context* context) + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +ImmutableExtensionGenerator::ImmutableExtensionGenerator( + const FieldDescriptor* descriptor, Context* context) : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - if (descriptor_->extension_scope() != NULL) { + if (descriptor_->extension_scope() != NULL) { scope_ = name_resolver_->GetImmutableClassName(descriptor_->extension_scope()); - } else { - scope_ = name_resolver_->GetImmutableClassName(descriptor_->file()); - } -} - -ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {} - -// Initializes the vars referenced in the generated code templates. + } else { + scope_ = name_resolver_->GetImmutableClassName(descriptor_->file()); + } +} + +ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {} + +// Initializes the vars referenced in the generated code templates. 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; - vars["scope"] = scope; + vars["scope"] = scope; vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor); - vars["containing_type"] = - name_resolver->GetClassName(descriptor->containing_type(), immutable); + vars["containing_type"] = + name_resolver->GetClassName(descriptor->containing_type(), immutable); vars["number"] = StrCat(descriptor->number()); - vars["constant_name"] = FieldConstantName(descriptor); + vars["constant_name"] = FieldConstantName(descriptor); vars["index"] = StrCat(descriptor->index()); vars["default"] = descriptor->is_repeated() ? "" : DefaultValue(descriptor, immutable, name_resolver); - vars["type_constant"] = FieldTypeName(GetType(descriptor)); + vars["type_constant"] = FieldTypeName(GetType(descriptor)); vars["packed"] = descriptor->is_packed() ? "true" : "false"; - vars["enum_map"] = "null"; - vars["prototype"] = "null"; - - JavaType java_type = GetJavaType(descriptor); + vars["enum_map"] = "null"; + vars["prototype"] = "null"; + + JavaType java_type = GetJavaType(descriptor); TProtoStringType singular_type; - switch (java_type) { - case JAVATYPE_MESSAGE: + switch (java_type) { + case JAVATYPE_MESSAGE: singular_type = name_resolver->GetClassName(descriptor->message_type(), immutable); - vars["prototype"] = singular_type + ".getDefaultInstance()"; - break; - case JAVATYPE_ENUM: + vars["prototype"] = singular_type + ".getDefaultInstance()"; + break; + case JAVATYPE_ENUM: singular_type = name_resolver->GetClassName(descriptor->enum_type(), immutable); - vars["enum_map"] = singular_type + ".internalGetValueMap()"; - break; - case JAVATYPE_STRING: - singular_type = "java.lang.String"; - break; - case JAVATYPE_BYTES: - singular_type = immutable ? "com.google.protobuf.ByteString" : "byte[]"; - break; - default: - singular_type = BoxedPrimitiveTypeName(java_type); - break; - } + vars["enum_map"] = singular_type + ".internalGetValueMap()"; + break; + case JAVATYPE_STRING: + singular_type = "java.lang.String"; + break; + case JAVATYPE_BYTES: + singular_type = immutable ? "com.google.protobuf.ByteString" : "byte[]"; + break; + default: + singular_type = BoxedPrimitiveTypeName(java_type); + break; + } vars["type"] = descriptor->is_repeated() ? "java.util.List<" + singular_type + ">" : singular_type; - vars["singular_type"] = singular_type; -} - -void ImmutableExtensionGenerator::Generate(io::Printer* printer) { + vars["singular_type"] = singular_type; +} + +void ImmutableExtensionGenerator::Generate(io::Printer* printer) { std::map<TProtoStringType, TProtoStringType> vars; - const bool kUseImmutableNames = true; - InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, - &vars); + const bool kUseImmutableNames = true; + InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, + &vars); printer->Print(vars, "public static final int $constant_name$ = $number$;\n"); - - WriteFieldDocComment(printer, descriptor_); - if (descriptor_->extension_scope() == NULL) { - // Non-nested - printer->Print( - vars, - "public static final\n" - " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" - " $containing_type$,\n" - " $type$> $name$ = com.google.protobuf.GeneratedMessage\n" - " .newFileScopedGeneratedExtension(\n" - " $singular_type$.class,\n" - " $prototype$);\n"); - } else { - // Nested - printer->Print( - vars, - "public static final\n" - " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" - " $containing_type$,\n" - " $type$> $name$ = com.google.protobuf.GeneratedMessage\n" - " .newMessageScopedGeneratedExtension(\n" - " $scope$.getDefaultInstance(),\n" - " $index$,\n" - " $singular_type$.class,\n" - " $prototype$);\n"); - } + + WriteFieldDocComment(printer, descriptor_); + if (descriptor_->extension_scope() == NULL) { + // Non-nested + printer->Print( + vars, + "public static final\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $containing_type$,\n" + " $type$> $name$ = com.google.protobuf.GeneratedMessage\n" + " .newFileScopedGeneratedExtension(\n" + " $singular_type$.class,\n" + " $prototype$);\n"); + } else { + // Nested + printer->Print( + vars, + "public static final\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $containing_type$,\n" + " $type$> $name$ = com.google.protobuf.GeneratedMessage\n" + " .newMessageScopedGeneratedExtension(\n" + " $scope$.getDefaultInstance(),\n" + " $index$,\n" + " $singular_type$.class,\n" + " $prototype$);\n"); + } printer->Annotate("name", descriptor_); -} - -int ImmutableExtensionGenerator::GenerateNonNestedInitializationCode( - io::Printer* printer) { - int bytecode_estimate = 0; - if (descriptor_->extension_scope() == NULL) { - // Only applies to non-nested extensions. - printer->Print( - "$name$.internalInit(descriptor.getExtensions().get($index$));\n", +} + +int ImmutableExtensionGenerator::GenerateNonNestedInitializationCode( + io::Printer* printer) { + int bytecode_estimate = 0; + if (descriptor_->extension_scope() == NULL) { + // Only applies to non-nested extensions. + printer->Print( + "$name$.internalInit(descriptor.getExtensions().get($index$));\n", "name", UnderscoresToCamelCaseCheckReserved(descriptor_), "index", StrCat(descriptor_->index())); - bytecode_estimate += 21; - } - return bytecode_estimate; -} - -int ImmutableExtensionGenerator::GenerateRegistrationCode( - io::Printer* printer) { + bytecode_estimate += 21; + } + return bytecode_estimate; +} + +int ImmutableExtensionGenerator::GenerateRegistrationCode( + io::Printer* printer) { printer->Print("registry.add($scope$.$name$);\n", "scope", scope_, "name", UnderscoresToCamelCaseCheckReserved(descriptor_)); - return 7; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return 7; +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.h index 76defbb8cb..cf9ae4f2f5 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension.h @@ -1,47 +1,47 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ - -#include <map> +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ + +#include <map> #include <string> - + #include <google/protobuf/stubs/common.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { class FieldDescriptor; // descriptor.h namespace compiler { namespace java { @@ -51,65 +51,65 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// Generates code for an extension, which may be within the scope of some -// message or may be at file scope. This is much simpler than FieldGenerator -// since extensions are just simple identifiers with interesting types. -class ExtensionGenerator { - public: - explicit ExtensionGenerator() {} - virtual ~ExtensionGenerator() {} - - virtual void Generate(io::Printer* printer) = 0; - +namespace protobuf { +namespace compiler { +namespace java { + +// Generates code for an extension, which may be within the scope of some +// message or may be at file scope. This is much simpler than FieldGenerator +// since extensions are just simple identifiers with interesting types. +class ExtensionGenerator { + public: + explicit ExtensionGenerator() {} + virtual ~ExtensionGenerator() {} + + virtual void Generate(io::Printer* printer) = 0; + // Returns an estimate of the number of bytes the printed code will compile // to - virtual int GenerateNonNestedInitializationCode(io::Printer* printer) = 0; - + virtual int GenerateNonNestedInitializationCode(io::Printer* printer) = 0; + // Returns an estimate of the number of bytes the printed code will compile // to - virtual int GenerateRegistrationCode(io::Printer* printer) = 0; - - protected: + virtual int GenerateRegistrationCode(io::Printer* printer) = 0; + + protected: 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); -}; - -class ImmutableExtensionGenerator : public ExtensionGenerator { - public: - explicit ImmutableExtensionGenerator(const FieldDescriptor* descriptor, - Context* context); - virtual ~ImmutableExtensionGenerator(); - - virtual void Generate(io::Printer* printer); - virtual int GenerateNonNestedInitializationCode(io::Printer* printer); - virtual int GenerateRegistrationCode(io::Printer* printer); - - protected: - const FieldDescriptor* descriptor_; - ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); +}; + +class ImmutableExtensionGenerator : public ExtensionGenerator { + public: + explicit ImmutableExtensionGenerator(const FieldDescriptor* descriptor, + Context* context); + virtual ~ImmutableExtensionGenerator(); + + virtual void Generate(io::Printer* printer); + virtual int GenerateNonNestedInitializationCode(io::Printer* printer); + virtual int GenerateRegistrationCode(io::Printer* printer); + + protected: + const FieldDescriptor* descriptor_; + ClassNameResolver* name_resolver_; TProtoStringType scope_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.cc index 3f12f20a57..22ce3ba92e 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.cc @@ -1,115 +1,115 @@ -// 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. - +// 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/java_extension_lite.h> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator( - const FieldDescriptor* descriptor, Context* context) + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator( + const FieldDescriptor* descriptor, Context* context) : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - if (descriptor_->extension_scope() != NULL) { + if (descriptor_->extension_scope() != NULL) { scope_ = name_resolver_->GetImmutableClassName(descriptor_->extension_scope()); - } else { - scope_ = name_resolver_->GetImmutableClassName(descriptor_->file()); - } -} - -ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {} - -void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) { + } else { + scope_ = name_resolver_->GetImmutableClassName(descriptor_->file()); + } +} + +ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {} + +void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) { std::map<TProtoStringType, TProtoStringType> vars; - const bool kUseImmutableNames = true; - InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, - &vars); + const bool kUseImmutableNames = true; + InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, + &vars); printer->Print(vars, "public static final int $constant_name$ = $number$;\n"); - - WriteFieldDocComment(printer, descriptor_); - if (descriptor_->is_repeated()) { - printer->Print( - vars, - "public static final\n" - " com.google.protobuf.GeneratedMessageLite.GeneratedExtension<\n" - " $containing_type$,\n" - " $type$> $name$ = com.google.protobuf.GeneratedMessageLite\n" - " .newRepeatedGeneratedExtension(\n" - " $containing_type$.getDefaultInstance(),\n" - " $prototype$,\n" - " $enum_map$,\n" - " $number$,\n" - " com.google.protobuf.WireFormat.FieldType.$type_constant$,\n" - " $packed$,\n" - " $singular_type$.class);\n"); - } else { - printer->Print( - vars, - "public static final\n" - " com.google.protobuf.GeneratedMessageLite.GeneratedExtension<\n" - " $containing_type$,\n" - " $type$> $name$ = com.google.protobuf.GeneratedMessageLite\n" - " .newSingularGeneratedExtension(\n" - " $containing_type$.getDefaultInstance(),\n" - " $default$,\n" - " $prototype$,\n" - " $enum_map$,\n" - " $number$,\n" - " com.google.protobuf.WireFormat.FieldType.$type_constant$,\n" - " $singular_type$.class);\n"); - } + + WriteFieldDocComment(printer, descriptor_); + if (descriptor_->is_repeated()) { + printer->Print( + vars, + "public static final\n" + " com.google.protobuf.GeneratedMessageLite.GeneratedExtension<\n" + " $containing_type$,\n" + " $type$> $name$ = com.google.protobuf.GeneratedMessageLite\n" + " .newRepeatedGeneratedExtension(\n" + " $containing_type$.getDefaultInstance(),\n" + " $prototype$,\n" + " $enum_map$,\n" + " $number$,\n" + " com.google.protobuf.WireFormat.FieldType.$type_constant$,\n" + " $packed$,\n" + " $singular_type$.class);\n"); + } else { + printer->Print( + vars, + "public static final\n" + " com.google.protobuf.GeneratedMessageLite.GeneratedExtension<\n" + " $containing_type$,\n" + " $type$> $name$ = com.google.protobuf.GeneratedMessageLite\n" + " .newSingularGeneratedExtension(\n" + " $containing_type$.getDefaultInstance(),\n" + " $default$,\n" + " $prototype$,\n" + " $enum_map$,\n" + " $number$,\n" + " com.google.protobuf.WireFormat.FieldType.$type_constant$,\n" + " $singular_type$.class);\n"); + } printer->Annotate("name", descriptor_); -} - -int ImmutableExtensionLiteGenerator::GenerateNonNestedInitializationCode( - io::Printer* printer) { - return 0; -} - -int ImmutableExtensionLiteGenerator::GenerateRegistrationCode( - io::Printer* printer) { +} + +int ImmutableExtensionLiteGenerator::GenerateNonNestedInitializationCode( + io::Printer* printer) { + return 0; +} + +int ImmutableExtensionLiteGenerator::GenerateRegistrationCode( + io::Printer* printer) { printer->Print("registry.add($scope$.$name$);\n", "scope", scope_, "name", UnderscoresToCamelCaseCheckReserved(descriptor_)); - return 7; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return 7; +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.h index 8912d4ea56..20bc041a7d 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_extension_lite.h @@ -1,75 +1,75 @@ -// 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_EXTENSION_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_LITE_H__ - -#include <map> +// 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_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/java_extension.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// Generates code for a lite extension, which may be within the scope of some -// message or may be at file scope. This is much simpler than FieldGenerator -// since extensions are just simple identifiers with interesting types. -class ImmutableExtensionLiteGenerator : public ExtensionGenerator { - public: - explicit ImmutableExtensionLiteGenerator(const FieldDescriptor* descriptor, - Context* context); - virtual ~ImmutableExtensionLiteGenerator(); - - virtual void Generate(io::Printer* printer); - - // Returns an estimate of the number of bytes the printed code will compile to - virtual int GenerateNonNestedInitializationCode(io::Printer* printer); - - // Returns an estimate of the number of bytes the printed code will compile to - virtual int GenerateRegistrationCode(io::Printer* printer); - - private: - const FieldDescriptor* descriptor_; - ClassNameResolver* name_resolver_; + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +// Generates code for a lite extension, which may be within the scope of some +// message or may be at file scope. This is much simpler than FieldGenerator +// since extensions are just simple identifiers with interesting types. +class ImmutableExtensionLiteGenerator : public ExtensionGenerator { + public: + explicit ImmutableExtensionLiteGenerator(const FieldDescriptor* descriptor, + Context* context); + virtual ~ImmutableExtensionLiteGenerator(); + + virtual void Generate(io::Printer* printer); + + // Returns an estimate of the number of bytes the printed code will compile to + virtual int GenerateNonNestedInitializationCode(io::Printer* printer); + + // Returns an estimate of the number of bytes the printed code will compile to + virtual int GenerateRegistrationCode(io::Printer* printer); + + private: + const FieldDescriptor* descriptor_; + ClassNameResolver* name_resolver_; TProtoStringType scope_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.cc index 15283e1083..e082fd1150 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.cc @@ -1,41 +1,41 @@ -// 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. - +// 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/java_field.h> - -#include <memory> - + +#include <memory> + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_context.h> @@ -53,203 +53,203 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> - - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { - + + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { + ImmutableFieldGenerator* MakeImmutableGenerator(const FieldDescriptor* field, int messageBitIndex, int builderBitIndex, Context* context) { - if (field->is_repeated()) { - switch (GetJavaType(field)) { - case JAVATYPE_MESSAGE: - if (IsMapEntry(field->message_type())) { + if (field->is_repeated()) { + switch (GetJavaType(field)) { + case JAVATYPE_MESSAGE: + if (IsMapEntry(field->message_type())) { return new ImmutableMapFieldGenerator(field, messageBitIndex, builderBitIndex, context); - } else { + } else { return new RepeatedImmutableMessageFieldGenerator( field, messageBitIndex, builderBitIndex, context); - } - case JAVATYPE_ENUM: - return new RepeatedImmutableEnumFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - case JAVATYPE_STRING: - return new RepeatedImmutableStringFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - default: - return new RepeatedImmutablePrimitiveFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } - } else { + } + case JAVATYPE_ENUM: + return new RepeatedImmutableEnumFieldGenerator( + field, messageBitIndex, builderBitIndex, context); + case JAVATYPE_STRING: + return new RepeatedImmutableStringFieldGenerator( + field, messageBitIndex, builderBitIndex, context); + default: + return new RepeatedImmutablePrimitiveFieldGenerator( + field, messageBitIndex, builderBitIndex, context); + } + } else { if (IsRealOneof(field)) { - switch (GetJavaType(field)) { - case JAVATYPE_MESSAGE: + switch (GetJavaType(field)) { + case JAVATYPE_MESSAGE: return new ImmutableMessageOneofFieldGenerator( field, messageBitIndex, builderBitIndex, context); - case JAVATYPE_ENUM: + case JAVATYPE_ENUM: return new ImmutableEnumOneofFieldGenerator(field, messageBitIndex, builderBitIndex, context); - case JAVATYPE_STRING: - return new ImmutableStringOneofFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - default: - return new ImmutablePrimitiveOneofFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } - } else { - switch (GetJavaType(field)) { - case JAVATYPE_MESSAGE: + case JAVATYPE_STRING: + return new ImmutableStringOneofFieldGenerator( + field, messageBitIndex, builderBitIndex, context); + default: + return new ImmutablePrimitiveOneofFieldGenerator( + field, messageBitIndex, builderBitIndex, context); + } + } else { + switch (GetJavaType(field)) { + case JAVATYPE_MESSAGE: return new ImmutableMessageFieldGenerator(field, messageBitIndex, builderBitIndex, context); - case JAVATYPE_ENUM: + case JAVATYPE_ENUM: return new ImmutableEnumFieldGenerator(field, messageBitIndex, builderBitIndex, context); - case JAVATYPE_STRING: + case JAVATYPE_STRING: return new ImmutableStringFieldGenerator(field, messageBitIndex, builderBitIndex, context); - default: + default: return new ImmutablePrimitiveFieldGenerator(field, messageBitIndex, builderBitIndex, context); - } - } - } -} - -ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator( + } + } + } +} + +ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator( const FieldDescriptor* field, int messageBitIndex, Context* context) { - if (field->is_repeated()) { - switch (GetJavaType(field)) { - case JAVATYPE_MESSAGE: - if (IsMapEntry(field->message_type())) { + if (field->is_repeated()) { + switch (GetJavaType(field)) { + case JAVATYPE_MESSAGE: + if (IsMapEntry(field->message_type())) { return new ImmutableMapFieldLiteGenerator(field, messageBitIndex, context); - } else { + } else { return new RepeatedImmutableMessageFieldLiteGenerator( field, messageBitIndex, context); - } - case JAVATYPE_ENUM: - return new RepeatedImmutableEnumFieldLiteGenerator( + } + case JAVATYPE_ENUM: + return new RepeatedImmutableEnumFieldLiteGenerator( field, messageBitIndex, context); - case JAVATYPE_STRING: - return new RepeatedImmutableStringFieldLiteGenerator( + case JAVATYPE_STRING: + return new RepeatedImmutableStringFieldLiteGenerator( field, messageBitIndex, context); - default: - return new RepeatedImmutablePrimitiveFieldLiteGenerator( + default: + return new RepeatedImmutablePrimitiveFieldLiteGenerator( field, messageBitIndex, context); - } - } else { + } + } else { if (IsRealOneof(field)) { - switch (GetJavaType(field)) { - case JAVATYPE_MESSAGE: + switch (GetJavaType(field)) { + case JAVATYPE_MESSAGE: return new ImmutableMessageOneofFieldLiteGenerator( field, messageBitIndex, context); - case JAVATYPE_ENUM: - return new ImmutableEnumOneofFieldLiteGenerator( + case JAVATYPE_ENUM: + return new ImmutableEnumOneofFieldLiteGenerator( field, messageBitIndex, context); - case JAVATYPE_STRING: - return new ImmutableStringOneofFieldLiteGenerator( + case JAVATYPE_STRING: + return new ImmutableStringOneofFieldLiteGenerator( field, messageBitIndex, context); - default: - return new ImmutablePrimitiveOneofFieldLiteGenerator( + default: + return new ImmutablePrimitiveOneofFieldLiteGenerator( field, messageBitIndex, context); - } - } else { - switch (GetJavaType(field)) { - case JAVATYPE_MESSAGE: + } + } else { + switch (GetJavaType(field)) { + case JAVATYPE_MESSAGE: return new ImmutableMessageFieldLiteGenerator(field, messageBitIndex, context); - case JAVATYPE_ENUM: + case JAVATYPE_ENUM: return new ImmutableEnumFieldLiteGenerator(field, messageBitIndex, context); - case JAVATYPE_STRING: + case JAVATYPE_STRING: return new ImmutableStringFieldLiteGenerator(field, messageBitIndex, context); - default: - return new ImmutablePrimitiveFieldLiteGenerator( + default: + return new ImmutablePrimitiveFieldLiteGenerator( field, messageBitIndex, context); - } - } - } -} - - -static inline void ReportUnexpectedPackedFieldsCall(io::Printer* printer) { - // Reaching here indicates a bug. Cases are: - // - This FieldGenerator should support packing, - // 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."; -} - -} // namespace - -ImmutableFieldGenerator::~ImmutableFieldGenerator() {} - + } + } + } +} + + +static inline void ReportUnexpectedPackedFieldsCall(io::Printer* printer) { + // Reaching here indicates a bug. Cases are: + // - This FieldGenerator should support packing, + // 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."; +} + +} // namespace + +ImmutableFieldGenerator::~ImmutableFieldGenerator() {} + void ImmutableFieldGenerator::GenerateParsingCodeFromPacked( io::Printer* printer) const { - ReportUnexpectedPackedFieldsCall(printer); -} - -ImmutableFieldLiteGenerator::~ImmutableFieldLiteGenerator() {} - -// =================================================================== - -template <> -FieldGeneratorMap<ImmutableFieldGenerator>::FieldGeneratorMap( - const Descriptor* descriptor, Context* context) + ReportUnexpectedPackedFieldsCall(printer); +} + +ImmutableFieldLiteGenerator::~ImmutableFieldLiteGenerator() {} + +// =================================================================== + +template <> +FieldGeneratorMap<ImmutableFieldGenerator>::FieldGeneratorMap( + const Descriptor* descriptor, Context* context) : descriptor_(descriptor), field_generators_(descriptor->field_count()) { - // Construct all the FieldGenerators and assign them bit indices for their - // bit fields. - int messageBitIndex = 0; - int builderBitIndex = 0; - for (int i = 0; i < descriptor->field_count(); i++) { - ImmutableFieldGenerator* generator = MakeImmutableGenerator( - descriptor->field(i), messageBitIndex, builderBitIndex, context); - field_generators_[i].reset(generator); - messageBitIndex += generator->GetNumBitsForMessage(); - builderBitIndex += generator->GetNumBitsForBuilder(); - } -} - + // Construct all the FieldGenerators and assign them bit indices for their + // bit fields. + int messageBitIndex = 0; + int builderBitIndex = 0; + for (int i = 0; i < descriptor->field_count(); i++) { + ImmutableFieldGenerator* generator = MakeImmutableGenerator( + descriptor->field(i), messageBitIndex, builderBitIndex, context); + field_generators_[i].reset(generator); + messageBitIndex += generator->GetNumBitsForMessage(); + builderBitIndex += generator->GetNumBitsForBuilder(); + } +} + template <> -FieldGeneratorMap<ImmutableFieldGenerator>::~FieldGeneratorMap() {} - -template <> -FieldGeneratorMap<ImmutableFieldLiteGenerator>::FieldGeneratorMap( - const Descriptor* descriptor, Context* context) +FieldGeneratorMap<ImmutableFieldGenerator>::~FieldGeneratorMap() {} + +template <> +FieldGeneratorMap<ImmutableFieldLiteGenerator>::FieldGeneratorMap( + const Descriptor* descriptor, Context* context) : descriptor_(descriptor), field_generators_(descriptor->field_count()) { - // Construct all the FieldGenerators and assign them bit indices for their - // bit fields. - int messageBitIndex = 0; - for (int i = 0; i < descriptor->field_count(); i++) { - ImmutableFieldLiteGenerator* generator = MakeImmutableLiteGenerator( + // Construct all the FieldGenerators and assign them bit indices for their + // bit fields. + int messageBitIndex = 0; + for (int i = 0; i < descriptor->field_count(); i++) { + ImmutableFieldLiteGenerator* generator = MakeImmutableLiteGenerator( descriptor->field(i), messageBitIndex, context); - field_generators_[i].reset(generator); - messageBitIndex += generator->GetNumBitsForMessage(); - } -} - + field_generators_[i].reset(generator); + messageBitIndex += generator->GetNumBitsForMessage(); + } +} + template <> -FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap() {} - - -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - const FieldGeneratorInfo* info, +FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap() {} + + +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + const FieldGeneratorInfo* info, std::map<TProtoStringType, TProtoStringType>* variables) { - (*variables)["field_name"] = descriptor->name(); - (*variables)["name"] = info->name; + (*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)["capitalized_name"] = info->capitalized_name; + (*variables)["disambiguated_reason"] = info->disambiguated_reason; + (*variables)["constant_name"] = FieldConstantName(descriptor); (*variables)["number"] = StrCat(descriptor->number()); (*variables)["kt_dsl_builder"] = "_builder"; // These variables are placeholders to pick out the beginning and ends of @@ -277,14 +277,14 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["annotation_field_type"] + "_PACKED"; } } -} - -void SetCommonOneofVariables(const FieldDescriptor* descriptor, - const OneofGeneratorInfo* info, +} + +void SetCommonOneofVariables(const FieldDescriptor* descriptor, + const OneofGeneratorInfo* info, std::map<TProtoStringType, TProtoStringType>* variables) { - (*variables)["oneof_name"] = info->name; - (*variables)["oneof_capitalized_name"] = info->capitalized_name; - (*variables)["oneof_index"] = + (*variables)["oneof_name"] = info->name; + (*variables)["oneof_capitalized_name"] = info->capitalized_name; + (*variables)["oneof_index"] = StrCat(descriptor->containing_oneof()->index()); (*variables)["oneof_stored_type"] = GetOneofStoredType(descriptor); (*variables)["set_oneof_case_message"] = @@ -292,21 +292,21 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor, (*variables)["clear_oneof_case_message"] = info->name + "Case_ = 0"; (*variables)["has_oneof_case_message"] = info->name + "Case_ == " + StrCat(descriptor->number()); -} - +} + void PrintExtraFieldInfo(const std::map<TProtoStringType, TProtoStringType>& variables, - io::Printer* printer) { + io::Printer* printer) { const std::map<TProtoStringType, TProtoStringType>::const_iterator it = - variables.find("disambiguated_reason"); - if (it != variables.end() && !it->second.empty()) { - printer->Print( - variables, - "// An alternative name is used for field \"$field_name$\" because:\n" - "// $disambiguated_reason$\n"); - } -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + variables.find("disambiguated_reason"); + if (it != variables.end() && !it->second.empty()) { + printer->Print( + variables, + "// An alternative name is used for field \"$field_name$\" because:\n" + "// $disambiguated_reason$\n"); + } +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.h index 09384c483a..4c6e278176 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_field.h @@ -1,51 +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. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ + #include <cstdint> -#include <map> -#include <memory> +#include <map> +#include <memory> #include <string> - + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/descriptor.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -54,100 +54,100 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableFieldGenerator { - public: - ImmutableFieldGenerator() {} - virtual ~ImmutableFieldGenerator(); - - virtual int GetNumBitsForMessage() const = 0; - virtual int GetNumBitsForBuilder() const = 0; - virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; - virtual void GenerateMembers(io::Printer* printer) const = 0; - virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; - virtual void GenerateInitializationCode(io::Printer* printer) const = 0; - 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 GenerateSerializationCode(io::Printer* printer) const = 0; - virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0; +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableFieldGenerator { + public: + ImmutableFieldGenerator() {} + virtual ~ImmutableFieldGenerator(); + + virtual int GetNumBitsForMessage() const = 0; + virtual int GetNumBitsForBuilder() const = 0; + virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; + virtual void GenerateMembers(io::Printer* printer) const = 0; + virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; + virtual void GenerateInitializationCode(io::Printer* printer) const = 0; + 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 GenerateSerializationCode(io::Printer* printer) const = 0; + virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0; virtual void GenerateFieldBuilderInitializationCode( io::Printer* printer) const = 0; virtual void GenerateKotlinDslMembers(io::Printer* printer) const = 0; - - virtual void GenerateEqualsCode(io::Printer* printer) const = 0; - virtual void GenerateHashCode(io::Printer* printer) const = 0; - + + virtual void GenerateEqualsCode(io::Printer* printer) const = 0; + virtual void GenerateHashCode(io::Printer* printer) const = 0; + virtual TProtoStringType GetBoxedType() const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator); -}; - -class ImmutableFieldLiteGenerator { - public: - ImmutableFieldLiteGenerator() {} - virtual ~ImmutableFieldLiteGenerator(); - - virtual int GetNumBitsForMessage() const = 0; - virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; - virtual void GenerateMembers(io::Printer* printer) const = 0; - virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; - virtual void GenerateInitializationCode(io::Printer* printer) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator); +}; + +class ImmutableFieldLiteGenerator { + public: + ImmutableFieldLiteGenerator() {} + virtual ~ImmutableFieldLiteGenerator(); + + virtual int GetNumBitsForMessage() const = 0; + virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; + virtual void GenerateMembers(io::Printer* printer) const = 0; + virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; + virtual void GenerateInitializationCode(io::Printer* printer) const = 0; virtual void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const = 0; virtual void GenerateKotlinDslMembers(io::Printer* printer) const = 0; - + virtual TProtoStringType GetBoxedType() const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldLiteGenerator); -}; - - -// Convenience class which constructs FieldGenerators for a Descriptor. + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldLiteGenerator); +}; + + +// Convenience class which constructs FieldGenerators for a Descriptor. template <typename FieldGeneratorType> -class FieldGeneratorMap { - public: +class FieldGeneratorMap { + public: explicit FieldGeneratorMap(const Descriptor* descriptor, Context* context); - ~FieldGeneratorMap(); - - const FieldGeneratorType& get(const FieldDescriptor* field) const; - - private: - const Descriptor* descriptor_; + ~FieldGeneratorMap(); + + const FieldGeneratorType& get(const FieldDescriptor* field) const; + + private: + const Descriptor* descriptor_; std::vector<std::unique_ptr<FieldGeneratorType>> field_generators_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); -}; - + + 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_); - return *field_generators_[field->index()]; -} - -// Instantiate template for mutable and immutable maps. + GOOGLE_CHECK_EQ(field->containing_type(), descriptor_); + return *field_generators_[field->index()]; +} + +// Instantiate template for mutable and immutable maps. template <> FieldGeneratorMap<ImmutableFieldGenerator>::FieldGeneratorMap( const Descriptor* descriptor, Context* context); - + template <> -FieldGeneratorMap<ImmutableFieldGenerator>::~FieldGeneratorMap(); - - +FieldGeneratorMap<ImmutableFieldGenerator>::~FieldGeneratorMap(); + + template <> FieldGeneratorMap<ImmutableFieldLiteGenerator>::FieldGeneratorMap( const Descriptor* descriptor, Context* context); @@ -156,36 +156,36 @@ template <> FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap(); -// Field information used in FieldGeneartors. -struct FieldGeneratorInfo { +// Field information used in FieldGeneartors. +struct FieldGeneratorInfo { TProtoStringType name; TProtoStringType capitalized_name; TProtoStringType disambiguated_reason; -}; - +}; + // Oneof information used in OneofFieldGenerators. -struct OneofGeneratorInfo { +struct OneofGeneratorInfo { TProtoStringType name; TProtoStringType capitalized_name; -}; - -// Set some common variables used in variable FieldGenerators. -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - const FieldGeneratorInfo* info, +}; + +// Set some common variables used in variable FieldGenerators. +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + const FieldGeneratorInfo* info, std::map<TProtoStringType, TProtoStringType>* variables); - -// Set some common oneof variables used in OneofFieldGenerators. -void SetCommonOneofVariables(const FieldDescriptor* descriptor, - const OneofGeneratorInfo* info, + +// Set some common oneof variables used in OneofFieldGenerators. +void SetCommonOneofVariables(const FieldDescriptor* descriptor, + const OneofGeneratorInfo* info, std::map<TProtoStringType, TProtoStringType>* variables); - -// Print useful comments before a field's accessors. + +// Print useful comments before a field's accessors. void PrintExtraFieldInfo(const std::map<TProtoStringType, TProtoStringType>& variables, - io::Printer* printer); - -} // namespace java -} // namespace compiler -} // namespace protobuf + io::Printer* printer); + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.cc index 0809febb8b..ddefc543d7 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.cc @@ -1,42 +1,42 @@ -// 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. - +// 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/java_file.h> - -#include <memory> -#include <set> - + +#include <memory> +#include <set> + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_enum.h> #include <google/protobuf/compiler/java/java_enum_lite.h> @@ -53,177 +53,177 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/dynamic_message.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { - -struct FieldDescriptorCompare { + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { + +struct FieldDescriptorCompare { bool operator()(const FieldDescriptor* f1, const FieldDescriptor* f2) const { if (f1 == NULL) { - return false; - } + return false; + } if (f2 == NULL) { - return true; - } - return f1->full_name() < f2->full_name(); - } -}; - + return true; + } + return f1->full_name() < f2->full_name(); + } +}; + typedef std::set<const FieldDescriptor*, FieldDescriptorCompare> FieldDescriptorSet; - -// Recursively searches the given message to collect extensions. -// Returns true if all the extensions can be recognized. The extensions will be -// appended in to the extensions parameter. -// Returns false when there are unknown fields, in which case the data in the -// extensions output parameter is not reliable and should be discarded. + +// Recursively searches the given message to collect extensions. +// Returns true if all the extensions can be recognized. The extensions will be +// appended in to the extensions parameter. +// Returns false when there are unknown fields, in which case the data in the +// extensions output parameter is not reliable and should be discarded. bool CollectExtensions(const Message& message, FieldDescriptorSet* extensions) { - const Reflection* reflection = message.GetReflection(); - - // There are unknown fields that could be extensions, thus this call fails. - if (reflection->GetUnknownFields(message).field_count() > 0) return false; - + const Reflection* reflection = message.GetReflection(); + + // There are unknown fields that could be extensions, thus this call fails. + if (reflection->GetUnknownFields(message).field_count() > 0) return false; + std::vector<const FieldDescriptor*> fields; - reflection->ListFields(message, &fields); - - for (int i = 0; i < fields.size(); i++) { + reflection->ListFields(message, &fields); + + for (int i = 0; i < fields.size(); i++) { if (fields[i]->is_extension()) { extensions->insert(fields[i]); } - - if (GetJavaType(fields[i]) == JAVATYPE_MESSAGE) { - if (fields[i]->is_repeated()) { - int size = reflection->FieldSize(message, fields[i]); - for (int j = 0; j < size; j++) { - const Message& sub_message = + + if (GetJavaType(fields[i]) == JAVATYPE_MESSAGE) { + if (fields[i]->is_repeated()) { + int size = reflection->FieldSize(message, fields[i]); + for (int j = 0; j < size; j++) { + const Message& sub_message = reflection->GetRepeatedMessage(message, fields[i], j); - if (!CollectExtensions(sub_message, extensions)) return false; - } - } else { - const Message& sub_message = reflection->GetMessage(message, fields[i]); - if (!CollectExtensions(sub_message, extensions)) return false; - } - } - } - - return true; -} - -// Finds all extensions in the given message and its sub-messages. If the -// message contains unknown fields (which could be extensions), then those -// extensions are defined in alternate_pool. -// The message will be converted to a DynamicMessage backed by alternate_pool -// in order to handle this case. -void CollectExtensions(const FileDescriptorProto& file_proto, - const DescriptorPool& alternate_pool, - FieldDescriptorSet* extensions, + if (!CollectExtensions(sub_message, extensions)) return false; + } + } else { + const Message& sub_message = reflection->GetMessage(message, fields[i]); + if (!CollectExtensions(sub_message, extensions)) return false; + } + } + } + + return true; +} + +// Finds all extensions in the given message and its sub-messages. If the +// message contains unknown fields (which could be extensions), then those +// extensions are defined in alternate_pool. +// The message will be converted to a DynamicMessage backed by alternate_pool +// in order to handle this case. +void CollectExtensions(const FileDescriptorProto& file_proto, + const DescriptorPool& alternate_pool, + FieldDescriptorSet* extensions, const TProtoStringType& file_data) { - if (!CollectExtensions(file_proto, extensions)) { - // There are unknown fields in the file_proto, which are probably - // extensions. We need to parse the data into a dynamic message based on the - // 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) - << "Find unknown fields in FileDescriptorProto when building " - << file_proto.name() - << ". It's likely that those fields are custom options, however, " - "descriptor.proto is not in the transitive dependencies. " - "This normally should not happen. Please report a bug."; - DynamicMessageFactory factory; + if (!CollectExtensions(file_proto, extensions)) { + // There are unknown fields in the file_proto, which are probably + // extensions. We need to parse the data into a dynamic message based on the + // 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) + << "Find unknown fields in FileDescriptorProto when building " + << file_proto.name() + << ". It's likely that those fields are custom options, however, " + "descriptor.proto is not in the transitive dependencies. " + "This normally should not happen. Please report a bug."; + 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)); - - // 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)) - << "Find unknown fields in FileDescriptorProto when building " - << file_proto.name() - << ". It's likely that those fields are custom options, however, " - "those options cannot be recognized in the builder pool. " - "This normally should not happen. Please report a bug."; - } -} - -// Our static initialization methods can become very, very large. -// So large that if we aren't careful we end up blowing the JVM's -// 64K bytes of bytecode/method. Fortunately, since these static -// methods are executed only once near the beginning of a program, -// there's usually plenty of stack space available and we can -// extend our methods by simply chaining them to another method -// with a tail call. This inserts the sequence call-next-method, -// end this one, begin-next-method as needed. + factory.GetPrototype(file_proto_desc)->New()); + GOOGLE_CHECK(dynamic_file_proto.get() != NULL); + GOOGLE_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)) + << "Find unknown fields in FileDescriptorProto when building " + << file_proto.name() + << ". It's likely that those fields are custom options, however, " + "those options cannot be recognized in the builder pool. " + "This normally should not happen. Please report a bug."; + } +} + +// Our static initialization methods can become very, very large. +// So large that if we aren't careful we end up blowing the JVM's +// 64K bytes of bytecode/method. Fortunately, since these static +// methods are executed only once near the beginning of a program, +// there's usually plenty of stack space available and we can +// extend our methods by simply chaining them to another method +// with a tail call. This inserts the sequence call-next-method, +// end this one, begin-next-method as needed. void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate, int* method_num, const char* chain_statement, const char* method_decl) { - // The goal here is to stay under 64K bytes of jvm bytecode/method, - // since otherwise we hit a hardcoded limit in the jvm and javac will - // then fail with the error "code too large". This limit lets our - // estimates be off by a factor of two and still we're okay. - static const int bytesPerMethod = kMaxStaticSize; - - if ((*bytecode_estimate) > bytesPerMethod) { - ++(*method_num); + // The goal here is to stay under 64K bytes of jvm bytecode/method, + // since otherwise we hit a hardcoded limit in the jvm and javac will + // then fail with the error "code too large". This limit lets our + // estimates be off by a factor of two and still we're okay. + static const int bytesPerMethod = kMaxStaticSize; + + if ((*bytecode_estimate) > bytesPerMethod) { + ++(*method_num); printer->Print(chain_statement, "method_num", StrCat(*method_num)); - printer->Outdent(); - printer->Print("}\n"); + printer->Outdent(); + printer->Print("}\n"); printer->Print(method_decl, "method_num", StrCat(*method_num)); - printer->Indent(); - *bytecode_estimate = 0; - } -} -} // namespace - -FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options, - bool immutable_api) - : file_(file), - java_package_(FileJavaPackage(file, immutable_api)), + printer->Indent(); + *bytecode_estimate = 0; + } +} +} // namespace + +FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options, + bool immutable_api) + : file_(file), + java_package_(FileJavaPackage(file, immutable_api)), message_generators_(file->message_type_count()), extension_generators_(file->extension_count()), - context_(new Context(file, options)), - name_resolver_(context_->GetNameResolver()), - options_(options), - immutable_api_(immutable_api) { - classname_ = name_resolver_->GetFileClassName(file, immutable_api); + context_(new Context(file, options)), + name_resolver_(context_->GetNameResolver()), + options_(options), + immutable_api_(immutable_api) { + classname_ = name_resolver_->GetFileClassName(file, immutable_api); 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))); - } - for (int i = 0; i < file_->extension_count(); ++i) { - extension_generators_[i].reset( - generator_factory_->NewExtensionGenerator(file_->extension(i))); - } -} - -FileGenerator::~FileGenerator() {} - + for (int i = 0; i < file_->message_type_count(); ++i) { + message_generators_[i].reset( + generator_factory_->NewMessageGenerator(file_->message_type(i))); + } + for (int i = 0; i < file_->extension_count(); ++i) { + extension_generators_[i].reset( + generator_factory_->NewExtensionGenerator(file_->extension(i))); + } +} + +FileGenerator::~FileGenerator() {} + bool FileGenerator::Validate(TProtoStringType* error) { - // Check that no class name matches the file's class name. This is a common - // problem that leads to Java compile errors that can be hard to understand. - // It's especially bad when using the java_multiple_files, since we would - // end up overwriting the outer class with one of the inner ones. + // Check that no class name matches the file's class name. This is a common + // problem that leads to Java compile errors that can be hard to understand. + // It's especially bad when using the java_multiple_files, since we would + // end up overwriting the outer class with one of the inner ones. if (name_resolver_->HasConflictingClassName(file_, classname_, NameEquality::EXACT_EQUAL)) { - error->assign(file_->name()); - error->append( + error->assign(file_->name()); + error->append( ": Cannot generate Java output because the file's outer class name, " "\""); - error->append(classname_); - error->append( + error->append(classname_); + error->append( "\", matches the name of one of the types declared inside it. " "Please either rename the type or use the java_outer_classname " "option to specify a different outer class name for the .proto file."); - return false; - } + return false; + } // Similar to the check above, but ignore the case this time. This is not a // problem on Linux, but will lead to Java compile errors on Windows / Mac // because filenames are case-insensitive on those platforms. @@ -250,146 +250,146 @@ bool FileGenerator::Validate(TProtoStringType* error) { "https://github.com/protocolbuffers/protobuf/blob/master/java/" "lite.md"; } - return true; -} - -void FileGenerator::Generate(io::Printer* printer) { - // We don't import anything because we refer to all classes by their - // fully-qualified names in the generated source. - printer->Print( + return true; +} + +void FileGenerator::Generate(io::Printer* printer) { + // We don't import anything because we refer to all classes by their + // fully-qualified names in the generated source. + printer->Print( "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" "// source: $filename$\n" "\n", "filename", file_->name()); - if (!java_package_.empty()) { - printer->Print( + if (!java_package_.empty()) { + printer->Print( "package $package$;\n" "\n", "package", java_package_); - } - PrintGeneratedAnnotation( - printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : ""); + } + PrintGeneratedAnnotation( + printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : ""); - printer->Print( + printer->Print( "$deprecation$public final class $classname$ {\n" - " private $ctor$() {}\n", + " private $ctor$() {}\n", "deprecation", file_->options().deprecated() ? "@java.lang.Deprecated " : "", - "classname", classname_, "ctor", classname_); - printer->Annotate("classname", file_->name()); - printer->Indent(); - - // ----------------------------------------------------------------- - - printer->Print( + "classname", classname_, "ctor", classname_); + printer->Annotate("classname", file_->name()); + printer->Indent(); + + // ----------------------------------------------------------------- + + printer->Print( "public static void registerAllExtensions(\n" " com.google.protobuf.ExtensionRegistryLite registry) {\n"); - - printer->Indent(); - - for (int i = 0; i < file_->extension_count(); i++) { - extension_generators_[i]->GenerateRegistrationCode(printer); - } - - for (int i = 0; i < file_->message_type_count(); i++) { - message_generators_[i]->GenerateExtensionRegistrationCode(printer); - } - - printer->Outdent(); + + printer->Indent(); + + for (int i = 0; i < file_->extension_count(); i++) { + extension_generators_[i]->GenerateRegistrationCode(printer); + } + + for (int i = 0; i < file_->message_type_count(); i++) { + message_generators_[i]->GenerateExtensionRegistrationCode(printer); + } + + printer->Outdent(); printer->Print("}\n"); - if (HasDescriptorMethods(file_, context_->EnforceLite())) { - // Overload registerAllExtensions for the non-lite usage to - // redundantly maintain the original signature (this is - // redundant because ExtensionRegistryLite now invokes - // ExtensionRegistry in the non-lite usage). Intent is - // to remove this in the future. - printer->Print( + if (HasDescriptorMethods(file_, context_->EnforceLite())) { + // Overload registerAllExtensions for the non-lite usage to + // redundantly maintain the original signature (this is + // redundant because ExtensionRegistryLite now invokes + // ExtensionRegistry in the non-lite usage). Intent is + // to remove this in the future. + printer->Print( "\n" "public static void registerAllExtensions(\n" " com.google.protobuf.ExtensionRegistry registry) {\n" " registerAllExtensions(\n" " (com.google.protobuf.ExtensionRegistryLite) registry);\n" "}\n"); - } - - // ----------------------------------------------------------------- - - if (!MultipleJavaFiles(file_, immutable_api_)) { - for (int i = 0; i < file_->enum_type_count(); i++) { - if (HasDescriptorMethods(file_, context_->EnforceLite())) { - EnumGenerator(file_->enum_type(i), immutable_api_, context_.get()) - .Generate(printer); - } else { - EnumLiteGenerator(file_->enum_type(i), immutable_api_, context_.get()) - .Generate(printer); - } - } - for (int i = 0; i < file_->message_type_count(); i++) { - message_generators_[i]->GenerateInterface(printer); - message_generators_[i]->Generate(printer); - } - if (HasGenericServices(file_, context_->EnforceLite())) { - for (int i = 0; i < file_->service_count(); i++) { + } + + // ----------------------------------------------------------------- + + if (!MultipleJavaFiles(file_, immutable_api_)) { + for (int i = 0; i < file_->enum_type_count(); i++) { + if (HasDescriptorMethods(file_, context_->EnforceLite())) { + EnumGenerator(file_->enum_type(i), immutable_api_, context_.get()) + .Generate(printer); + } else { + EnumLiteGenerator(file_->enum_type(i), immutable_api_, context_.get()) + .Generate(printer); + } + } + for (int i = 0; i < file_->message_type_count(); i++) { + message_generators_[i]->GenerateInterface(printer); + message_generators_[i]->Generate(printer); + } + if (HasGenericServices(file_, context_->EnforceLite())) { + for (int i = 0; i < file_->service_count(); i++) { std::unique_ptr<ServiceGenerator> generator( - generator_factory_->NewServiceGenerator(file_->service(i))); - generator->Generate(printer); - } - } - } - - // Extensions must be generated in the outer class since they are values, - // not classes. - for (int i = 0; i < file_->extension_count(); i++) { - extension_generators_[i]->Generate(printer); - } - - // Static variables. We'd like them to be final if possible, but due to - // the JVM's 64k size limit on static blocks, we have to initialize some - // of them in methods; thus they cannot be final. - int static_block_bytecode_estimate = 0; - for (int i = 0; i < file_->message_type_count(); i++) { - message_generators_[i]->GenerateStaticVariables( - printer, &static_block_bytecode_estimate); - } - - printer->Print("\n"); - - if (HasDescriptorMethods(file_, context_->EnforceLite())) { - if (immutable_api_) { - GenerateDescriptorInitializationCodeForImmutable(printer); - } else { - GenerateDescriptorInitializationCodeForMutable(printer); - } - } else { + generator_factory_->NewServiceGenerator(file_->service(i))); + generator->Generate(printer); + } + } + } + + // Extensions must be generated in the outer class since they are values, + // not classes. + for (int i = 0; i < file_->extension_count(); i++) { + extension_generators_[i]->Generate(printer); + } + + // Static variables. We'd like them to be final if possible, but due to + // the JVM's 64k size limit on static blocks, we have to initialize some + // of them in methods; thus they cannot be final. + int static_block_bytecode_estimate = 0; + for (int i = 0; i < file_->message_type_count(); i++) { + message_generators_[i]->GenerateStaticVariables( + printer, &static_block_bytecode_estimate); + } + + printer->Print("\n"); + + if (HasDescriptorMethods(file_, context_->EnforceLite())) { + if (immutable_api_) { + GenerateDescriptorInitializationCodeForImmutable(printer); + } else { + GenerateDescriptorInitializationCodeForMutable(printer); + } + } else { printer->Print("static {\n"); - printer->Indent(); - int bytecode_estimate = 0; - int method_num = 0; - - for (int i = 0; i < file_->message_type_count(); i++) { + printer->Indent(); + int bytecode_estimate = 0; + int method_num = 0; + + for (int i = 0; i < file_->message_type_count(); i++) { bytecode_estimate += message_generators_[i]->GenerateStaticVariableInitializers(printer); - MaybeRestartJavaMethod( + MaybeRestartJavaMethod( printer, &bytecode_estimate, &method_num, "_clinit_autosplit_$method_num$();\n", "private static void _clinit_autosplit_$method_num$() {\n"); - } - - printer->Outdent(); + } + + printer->Outdent(); printer->Print("}\n"); - } - - printer->Print( + } + + printer->Print( "\n" "// @@protoc_insertion_point(outer_class_scope)\n"); - - printer->Outdent(); - printer->Print("}\n"); -} - -void FileGenerator::GenerateDescriptorInitializationCodeForImmutable( - io::Printer* printer) { - printer->Print( + + printer->Outdent(); + printer->Print("}\n"); +} + +void FileGenerator::GenerateDescriptorInitializationCodeForImmutable( + io::Printer* printer) { + printer->Print( "public static com.google.protobuf.Descriptors.FileDescriptor\n" " getDescriptor() {\n" " return descriptor;\n" @@ -399,92 +399,92 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable( "static {\n", // TODO(dweis): Mark this as final. "final", ""); - printer->Indent(); - - SharedCodeGenerator shared_code_generator(file_, options_); - shared_code_generator.GenerateDescriptors(printer); - - int bytecode_estimate = 0; - int method_num = 0; - - for (int i = 0; i < file_->message_type_count(); i++) { + printer->Indent(); + + SharedCodeGenerator shared_code_generator(file_, options_); + shared_code_generator.GenerateDescriptors(printer); + + int bytecode_estimate = 0; + int method_num = 0; + + for (int i = 0; i < file_->message_type_count(); i++) { bytecode_estimate += message_generators_[i]->GenerateStaticVariableInitializers(printer); - MaybeRestartJavaMethod( + MaybeRestartJavaMethod( printer, &bytecode_estimate, &method_num, "_clinit_autosplit_dinit_$method_num$();\n", "private static void _clinit_autosplit_dinit_$method_num$() {\n"); - } - for (int i = 0; i < file_->extension_count(); i++) { + } + for (int i = 0; i < file_->extension_count(); i++) { bytecode_estimate += extension_generators_[i]->GenerateNonNestedInitializationCode(printer); - MaybeRestartJavaMethod( + MaybeRestartJavaMethod( printer, &bytecode_estimate, &method_num, "_clinit_autosplit_dinit_$method_num$();\n", "private static void _clinit_autosplit_dinit_$method_num$() {\n"); - } - - // Proto compiler builds a DescriptorPool, which holds all the descriptors to - // generate, when processing the ".proto" files. We call this DescriptorPool - // the parsed pool (a.k.a. file_->pool()). - // - // Note that when users try to extend the (.*)DescriptorProto in their - // ".proto" files, it does not affect the pre-built FileDescriptorProto class - // in proto compiler. When we put the descriptor data in the file_proto, those - // extensions become unknown fields. - // - // Now we need to find out all the extension value to the (.*)DescriptorProto - // in the file_proto message, and prepare an ExtensionRegistry to return. - // - // To find those extensions, we need to parse the data into a dynamic message - // of the FileDescriptor based on the builder-pool, then we can use - // reflections to find all extension fields - FileDescriptorProto file_proto; - file_->CopyTo(&file_proto); + } + + // Proto compiler builds a DescriptorPool, which holds all the descriptors to + // generate, when processing the ".proto" files. We call this DescriptorPool + // the parsed pool (a.k.a. file_->pool()). + // + // Note that when users try to extend the (.*)DescriptorProto in their + // ".proto" files, it does not affect the pre-built FileDescriptorProto class + // in proto compiler. When we put the descriptor data in the file_proto, those + // extensions become unknown fields. + // + // Now we need to find out all the extension value to the (.*)DescriptorProto + // in the file_proto message, and prepare an ExtensionRegistry to return. + // + // To find those extensions, we need to parse the data into a dynamic message + // of the FileDescriptor based on the builder-pool, then we can use + // reflections to find all extension fields + FileDescriptorProto file_proto; + file_->CopyTo(&file_proto); TProtoStringType file_data; - file_proto.SerializeToString(&file_data); - FieldDescriptorSet extensions; - CollectExtensions(file_proto, *file_->pool(), &extensions, file_data); - - if (extensions.size() > 0) { - // Must construct an ExtensionRegistry containing all existing extensions - // and use it to parse the descriptor data again to recognize extensions. - printer->Print( + file_proto.SerializeToString(&file_data); + FieldDescriptorSet extensions; + CollectExtensions(file_proto, *file_->pool(), &extensions, file_data); + + if (extensions.size() > 0) { + // 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++) { + FieldDescriptorSet::iterator it; + for (it = extensions.begin(); it != extensions.end(); it++) { std::unique_ptr<ExtensionGenerator> generator( - generator_factory_->NewExtensionGenerator(*it)); - bytecode_estimate += generator->GenerateRegistrationCode(printer); - MaybeRestartJavaMethod( + generator_factory_->NewExtensionGenerator(*it)); + bytecode_estimate += generator->GenerateRegistrationCode(printer); + MaybeRestartJavaMethod( printer, &bytecode_estimate, &method_num, "_clinit_autosplit_dinit_$method_num$(registry);\n", "private static void _clinit_autosplit_dinit_$method_num$(\n" " com.google.protobuf.ExtensionRegistry registry) {\n"); - } - printer->Print( + } + printer->Print( "com.google.protobuf.Descriptors.FileDescriptor\n" " .internalUpdateFileDescriptor(descriptor, registry);\n"); - } - - // Force descriptor initialization of all dependencies. - for (int i = 0; i < file_->dependency_count(); i++) { - if (ShouldIncludeDependency(file_->dependency(i), true)) { + } + + // Force descriptor initialization of all dependencies. + for (int i = 0; i < file_->dependency_count(); i++) { + if (ShouldIncludeDependency(file_->dependency(i), true)) { TProtoStringType dependency = - name_resolver_->GetImmutableClassName(file_->dependency(i)); + name_resolver_->GetImmutableClassName(file_->dependency(i)); printer->Print("$dependency$.getDescriptor();\n", "dependency", dependency); - } - } - - printer->Outdent(); + } + } + + printer->Outdent(); printer->Print("}\n"); -} - +} + void FileGenerator::GenerateDescriptorInitializationCodeForMutable( io::Printer* printer) { - printer->Print( + printer->Print( "public static com.google.protobuf.Descriptors.FileDescriptor\n" " getDescriptor() {\n" " return descriptor;\n" @@ -492,33 +492,33 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable( "private static final com.google.protobuf.Descriptors.FileDescriptor\n" " descriptor;\n" "static {\n"); - printer->Indent(); - - printer->Print( + printer->Indent(); + + printer->Print( "descriptor = $immutable_package$.$descriptor_classname$.descriptor;\n", "immutable_package", FileJavaPackage(file_, true), "descriptor_classname", name_resolver_->GetDescriptorClassName(file_)); - - for (int i = 0; i < file_->message_type_count(); i++) { - message_generators_[i]->GenerateStaticVariableInitializers(printer); - } - for (int i = 0; i < file_->extension_count(); i++) { - extension_generators_[i]->GenerateNonNestedInitializationCode(printer); - } - - // Check if custom options exist. If any, try to load immutable classes since - // custom options are only represented with immutable messages. - FileDescriptorProto file_proto; - file_->CopyTo(&file_proto); + + for (int i = 0; i < file_->message_type_count(); i++) { + message_generators_[i]->GenerateStaticVariableInitializers(printer); + } + for (int i = 0; i < file_->extension_count(); i++) { + extension_generators_[i]->GenerateNonNestedInitializationCode(printer); + } + + // Check if custom options exist. If any, try to load immutable classes since + // custom options are only represented with immutable messages. + FileDescriptorProto file_proto; + file_->CopyTo(&file_proto); TProtoStringType file_data; - file_proto.SerializeToString(&file_data); - FieldDescriptorSet extensions; - CollectExtensions(file_proto, *file_->pool(), &extensions, file_data); - - if (extensions.size() > 0) { - // Try to load immutable messages' outer class. Its initialization code - // will take care of interpreting custom options. - printer->Print( + file_proto.SerializeToString(&file_data); + FieldDescriptorSet extensions; + CollectExtensions(file_proto, *file_->pool(), &extensions, file_data); + + if (extensions.size() > 0) { + // Try to load immutable messages' outer class. Its initialization code + // will take care of interpreting custom options. + printer->Print( "try {\n" // Note that we have to load the immutable class dynamically here as // we want the mutable code to be independent from the immutable code @@ -570,23 +570,23 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable( printer->Outdent(); printer->Print("}\n"); - } - - // Force descriptor initialization of all dependencies. - for (int i = 0; i < file_->dependency_count(); i++) { - if (ShouldIncludeDependency(file_->dependency(i), false)) { + } + + // Force descriptor initialization of all dependencies. + for (int i = 0; i < file_->dependency_count(); i++) { + if (ShouldIncludeDependency(file_->dependency(i), false)) { TProtoStringType dependency = name_resolver_->GetMutableClassName(file_->dependency(i)); printer->Print("$dependency$.getDescriptor();\n", "dependency", dependency); - } - } - - printer->Outdent(); + } + } + + printer->Outdent(); printer->Print("}\n"); -} - -template <typename GeneratorClass, typename DescriptorClass> +} + +template <typename GeneratorClass, typename DescriptorClass> static void GenerateSibling( const TProtoStringType& package_dir, const TProtoStringType& java_package, const DescriptorClass* descriptor, GeneratorContext* context, @@ -596,85 +596,85 @@ static void GenerateSibling( void (GeneratorClass::*pfn)(io::Printer* printer)) { TProtoStringType filename = package_dir + descriptor->name() + name_suffix + ".java"; - file_list->push_back(filename); + file_list->push_back(filename); TProtoStringType info_full_path = filename + ".pb.meta"; - GeneratedCodeInfo annotations; - io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( - &annotations); - + GeneratedCodeInfo annotations; + io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( + &annotations); + std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename)); - io::Printer printer(output.get(), '$', - annotate_code ? &annotation_collector : NULL); - - printer.Print( + io::Printer printer(output.get(), '$', + annotate_code ? &annotation_collector : NULL); + + printer.Print( "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" "// source: $filename$\n" "\n", "filename", descriptor->file()->name()); - if (!java_package.empty()) { - printer.Print( + if (!java_package.empty()) { + printer.Print( "package $package$;\n" "\n", "package", java_package); - } - - (generator->*pfn)(&printer); - - if (annotate_code) { + } + + (generator->*pfn)(&printer); + + if (annotate_code) { std::unique_ptr<io::ZeroCopyOutputStream> info_output( - context->Open(info_full_path)); - annotations.SerializeToZeroCopyStream(info_output.get()); - annotation_list->push_back(info_full_path); - } -} - + context->Open(info_full_path)); + annotations.SerializeToZeroCopyStream(info_output.get()); + annotation_list->push_back(info_full_path); + } +} + void FileGenerator::GenerateSiblings( const TProtoStringType& package_dir, GeneratorContext* context, std::vector<TProtoStringType>* file_list, std::vector<TProtoStringType>* annotation_list) { - if (MultipleJavaFiles(file_, immutable_api_)) { - for (int i = 0; i < file_->enum_type_count(); i++) { - if (HasDescriptorMethods(file_, context_->EnforceLite())) { - EnumGenerator generator(file_->enum_type(i), immutable_api_, - context_.get()); - GenerateSibling<EnumGenerator>( - package_dir, java_package_, file_->enum_type(i), context, file_list, - options_.annotate_code, annotation_list, "", &generator, - &EnumGenerator::Generate); - } else { - EnumLiteGenerator generator(file_->enum_type(i), immutable_api_, - context_.get()); - GenerateSibling<EnumLiteGenerator>( - package_dir, java_package_, file_->enum_type(i), context, file_list, - options_.annotate_code, annotation_list, "", &generator, - &EnumLiteGenerator::Generate); - } - } - for (int i = 0; i < file_->message_type_count(); i++) { - if (immutable_api_) { - GenerateSibling<MessageGenerator>( - package_dir, java_package_, file_->message_type(i), context, - file_list, options_.annotate_code, annotation_list, "OrBuilder", - message_generators_[i].get(), &MessageGenerator::GenerateInterface); - } - GenerateSibling<MessageGenerator>( - package_dir, java_package_, file_->message_type(i), context, - file_list, options_.annotate_code, annotation_list, "", - message_generators_[i].get(), &MessageGenerator::Generate); - } - if (HasGenericServices(file_, context_->EnforceLite())) { - for (int i = 0; i < file_->service_count(); i++) { + if (MultipleJavaFiles(file_, immutable_api_)) { + for (int i = 0; i < file_->enum_type_count(); i++) { + if (HasDescriptorMethods(file_, context_->EnforceLite())) { + EnumGenerator generator(file_->enum_type(i), immutable_api_, + context_.get()); + GenerateSibling<EnumGenerator>( + package_dir, java_package_, file_->enum_type(i), context, file_list, + options_.annotate_code, annotation_list, "", &generator, + &EnumGenerator::Generate); + } else { + EnumLiteGenerator generator(file_->enum_type(i), immutable_api_, + context_.get()); + GenerateSibling<EnumLiteGenerator>( + package_dir, java_package_, file_->enum_type(i), context, file_list, + options_.annotate_code, annotation_list, "", &generator, + &EnumLiteGenerator::Generate); + } + } + for (int i = 0; i < file_->message_type_count(); i++) { + if (immutable_api_) { + GenerateSibling<MessageGenerator>( + package_dir, java_package_, file_->message_type(i), context, + file_list, options_.annotate_code, annotation_list, "OrBuilder", + message_generators_[i].get(), &MessageGenerator::GenerateInterface); + } + GenerateSibling<MessageGenerator>( + package_dir, java_package_, file_->message_type(i), context, + file_list, options_.annotate_code, annotation_list, "", + message_generators_[i].get(), &MessageGenerator::Generate); + } + if (HasGenericServices(file_, context_->EnforceLite())) { + for (int i = 0; i < file_->service_count(); i++) { std::unique_ptr<ServiceGenerator> generator( - generator_factory_->NewServiceGenerator(file_->service(i))); - GenerateSibling<ServiceGenerator>( - package_dir, java_package_, file_->service(i), context, file_list, - options_.annotate_code, annotation_list, "", generator.get(), - &ServiceGenerator::Generate); - } - } - } -} - + generator_factory_->NewServiceGenerator(file_->service(i))); + GenerateSibling<ServiceGenerator>( + package_dir, java_package_, file_->service(i), context, file_list, + options_.annotate_code, annotation_list, "", generator.get(), + &ServiceGenerator::Generate); + } + } + } +} + TProtoStringType FileGenerator::GetKotlinClassname() { return name_resolver_->GetFileClassName(file_, immutable_api_, true); } @@ -725,10 +725,10 @@ void FileGenerator::GenerateKotlinSiblings( bool FileGenerator::ShouldIncludeDependency(const FileDescriptor* descriptor, bool immutable_api) { - return true; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return true; +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.h index b567b62fd9..b182dd06a2 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_file.h @@ -1,52 +1,52 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ - -#include <memory> +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ + +#include <memory> #include <string> -#include <vector> +#include <vector> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_options.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { class FileDescriptor; // descriptor.h namespace io { class Printer; // printer.h -} +} namespace compiler { class GeneratorContext; // code_generator.h namespace java { @@ -59,67 +59,67 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class FileGenerator { - public: - FileGenerator(const FileDescriptor* file, const Options& options, - bool immutable_api = true); - ~FileGenerator(); - - // Checks for problems that would otherwise lead to cryptic compile errors. - // Returns true if there are no problems, or writes an error description to - // the given string and returns false otherwise. +namespace protobuf { +namespace compiler { +namespace java { + +class FileGenerator { + public: + FileGenerator(const FileDescriptor* file, const Options& options, + bool immutable_api = true); + ~FileGenerator(); + + // Checks for problems that would otherwise lead to cryptic compile errors. + // Returns true if there are no problems, or writes an error description to + // the given string and returns false otherwise. bool Validate(TProtoStringType* error); - - void Generate(io::Printer* printer); - + + void Generate(io::Printer* printer); + TProtoStringType GetKotlinClassname(); void GenerateKotlinSiblings(const TProtoStringType& package_dir, GeneratorContext* generator_context, std::vector<TProtoStringType>* file_list, std::vector<TProtoStringType>* annotation_list); - // If we aren't putting everything into one file, this will write all the - // files other than the outer file (i.e. one for each message, enum, and - // service type). + // If we aren't putting everything into one file, this will write all the + // files other than the outer file (i.e. one for each message, enum, and + // service type). void GenerateSiblings(const TProtoStringType& package_dir, - GeneratorContext* generator_context, + GeneratorContext* generator_context, std::vector<TProtoStringType>* file_list, std::vector<TProtoStringType>* annotation_list); - + const TProtoStringType& java_package() { return java_package_; } const TProtoStringType& classname() { return classname_; } - - private: - void GenerateDescriptorInitializationCodeForImmutable(io::Printer* printer); - void GenerateDescriptorInitializationCodeForMutable(io::Printer* printer); - - bool ShouldIncludeDependency(const FileDescriptor* descriptor, - bool immutable_api_); - - const FileDescriptor* file_; + + private: + void GenerateDescriptorInitializationCodeForImmutable(io::Printer* printer); + void GenerateDescriptorInitializationCodeForMutable(io::Printer* printer); + + bool ShouldIncludeDependency(const FileDescriptor* descriptor, + bool immutable_api_); + + const FileDescriptor* file_; TProtoStringType java_package_; TProtoStringType classname_; - + std::vector<std::unique_ptr<MessageGenerator>> message_generators_; std::vector<std::unique_ptr<ExtensionGenerator>> extension_generators_; std::unique_ptr<GeneratorFactory> generator_factory_; std::unique_ptr<Context> context_; - ClassNameResolver* name_resolver_; - const Options options_; - bool immutable_api_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; + const Options options_; + bool immutable_api_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.cc index 2b5728579e..985700e5a8 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.cc @@ -1,42 +1,42 @@ -// 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. - +// 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/java_generator.h> + - -#include <memory> - +#include <memory> + #include <google/protobuf/compiler/java/java_file.h> #include <google/protobuf/compiler/java/java_generator_factory.h> #include <google/protobuf/compiler/java/java_helpers.h> @@ -48,164 +48,164 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - - -JavaGenerator::JavaGenerator() {} -JavaGenerator::~JavaGenerator() {} - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + + +JavaGenerator::JavaGenerator() {} +JavaGenerator::~JavaGenerator() {} + uint64_t JavaGenerator::GetSupportedFeatures() const { return CodeGenerator::Feature::FEATURE_PROTO3_OPTIONAL; } -bool JavaGenerator::Generate(const FileDescriptor* file, +bool JavaGenerator::Generate(const FileDescriptor* file, const TProtoStringType& parameter, - GeneratorContext* context, + GeneratorContext* context, TProtoStringType* error) const { - // ----------------------------------------------------------------- - // parse generator options - + // ----------------------------------------------------------------- + // parse generator options + std::vector<std::pair<TProtoStringType, TProtoStringType> > options; - 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.generate_immutable_code = true; - } else if (options[i].first == "mutable") { - file_options.generate_mutable_code = true; - } else if (options[i].first == "shared") { - file_options.generate_shared_code = true; + 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.generate_immutable_code = true; + } else if (options[i].first == "mutable") { + file_options.generate_mutable_code = true; + } else if (options[i].first == "shared") { + file_options.generate_shared_code = true; } else if (options[i].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") { - file_options.annotate_code = true; - } else if (options[i].first == "annotation_list_file") { - file_options.annotation_list_file = options[i].second; - } else { - *error = "Unknown generator option: " + options[i].first; - return false; - } - } - - if (file_options.enforce_lite && file_options.generate_mutable_code) { - *error = "lite runtime generator option cannot be used with mutable API."; - return false; - } - - // By default we generate immutable code and shared code for immutable API. - if (!file_options.generate_immutable_code && - !file_options.generate_mutable_code && - !file_options.generate_shared_code) { - file_options.generate_immutable_code = true; - file_options.generate_shared_code = true; - } - - // ----------------------------------------------------------------- - - + } else if (options[i].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 { + *error = "Unknown generator option: " + options[i].first; + return false; + } + } + + if (file_options.enforce_lite && file_options.generate_mutable_code) { + *error = "lite runtime generator option cannot be used with mutable API."; + return false; + } + + // By default we generate immutable code and shared code for immutable API. + if (!file_options.generate_immutable_code && + !file_options.generate_mutable_code && + !file_options.generate_shared_code) { + file_options.generate_immutable_code = true; + file_options.generate_shared_code = true; + } + + // ----------------------------------------------------------------- + + std::vector<TProtoStringType> all_files; std::vector<TProtoStringType> all_annotations; - - + + std::vector<FileGenerator*> file_generators; - if (file_options.generate_immutable_code) { - file_generators.push_back(new FileGenerator(file, file_options, - /* immutable = */ true)); - } - if (file_options.generate_mutable_code) { - file_generators.push_back(new 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]; - } - return false; - } - } - - for (int i = 0; i < file_generators.size(); ++i) { - FileGenerator* file_generator = file_generators[i]; - + if (file_options.generate_immutable_code) { + file_generators.push_back(new FileGenerator(file, file_options, + /* immutable = */ true)); + } + if (file_options.generate_mutable_code) { + file_generators.push_back(new 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]; + } + return false; + } + } + + for (int i = 0; i < file_generators.size(); ++i) { + FileGenerator* file_generator = file_generators[i]; + TProtoStringType package_dir = JavaPackageToDir(file_generator->java_package()); - + TProtoStringType java_filename = package_dir; - java_filename += file_generator->classname(); - java_filename += ".java"; - all_files.push_back(java_filename); + java_filename += file_generator->classname(); + java_filename += ".java"; + all_files.push_back(java_filename); TProtoStringType info_full_path = java_filename + ".pb.meta"; - if (file_options.annotate_code) { - all_annotations.push_back(info_full_path); - } - - // Generate main java file. + if (file_options.annotate_code) { + all_annotations.push_back(info_full_path); + } + + // Generate main java file. std::unique_ptr<io::ZeroCopyOutputStream> output( - context->Open(java_filename)); - GeneratedCodeInfo annotations; - io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( - &annotations); + context->Open(java_filename)); + GeneratedCodeInfo annotations; + io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( + &annotations); io::Printer printer( output.get(), '$', file_options.annotate_code ? &annotation_collector : NULL); - - file_generator->Generate(&printer); - - // Generate sibling files. - file_generator->GenerateSiblings(package_dir, context, &all_files, - &all_annotations); - - if (file_options.annotate_code) { + + file_generator->Generate(&printer); + + // Generate sibling files. + file_generator->GenerateSiblings(package_dir, context, &all_files, + &all_annotations); + + if (file_options.annotate_code) { std::unique_ptr<io::ZeroCopyOutputStream> info_output( - context->Open(info_full_path)); - annotations.SerializeToZeroCopyStream(info_output.get()); - } - } - - - for (int i = 0; i < file_generators.size(); ++i) { - delete file_generators[i]; - } - file_generators.clear(); - - // Generate output list if requested. - if (!file_options.output_list_file.empty()) { - // Generate output list. This is just a simple text file placed in a - // deterministic location which lists the .java files being generated. + context->Open(info_full_path)); + annotations.SerializeToZeroCopyStream(info_output.get()); + } + } + + + for (int i = 0; i < file_generators.size(); ++i) { + delete file_generators[i]; + } + file_generators.clear(); + + // Generate output list if requested. + if (!file_options.output_list_file.empty()) { + // Generate output list. This is just a simple text file placed in a + // deterministic location which lists the .java files being generated. std::unique_ptr<io::ZeroCopyOutputStream> srclist_raw_output( - context->Open(file_options.output_list_file)); - io::Printer srclist_printer(srclist_raw_output.get(), '$'); - for (int i = 0; i < all_files.size(); i++) { - srclist_printer.Print("$filename$\n", "filename", all_files[i]); - } - } - - if (!file_options.annotation_list_file.empty()) { - // Generate output list. This is just a simple text file placed in a - // deterministic location which lists the .java files being generated. + context->Open(file_options.output_list_file)); + io::Printer srclist_printer(srclist_raw_output.get(), '$'); + for (int i = 0; i < all_files.size(); i++) { + srclist_printer.Print("$filename$\n", "filename", all_files[i]); + } + } + + if (!file_options.annotation_list_file.empty()) { + // Generate output list. This is just a simple text file placed in a + // deterministic location which lists the .java files being generated. std::unique_ptr<io::ZeroCopyOutputStream> annotation_list_raw_output( - context->Open(file_options.annotation_list_file)); - io::Printer annotation_list_printer(annotation_list_raw_output.get(), '$'); - for (int i = 0; i < all_annotations.size(); i++) { - annotation_list_printer.Print("$filename$\n", "filename", - all_annotations[i]); - } - } - - return true; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + context->Open(file_options.annotation_list_file)); + io::Printer annotation_list_printer(annotation_list_raw_output.get(), '$'); + for (int i = 0; i < all_annotations.size(); i++) { + annotation_list_printer.Print("$filename$\n", "filename", + all_annotations[i]); + } + } + + return true; +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.h index 90d2610550..fda70afb50 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator.h @@ -1,76 +1,76 @@ -// 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. -// -// Generates Java code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ - +// 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. +// +// Generates Java code for a given .proto file. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ + #include <string> #include <google/protobuf/compiler/code_generator.h> - + #include <google/protobuf/port_def.inc> -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// CodeGenerator implementation which generates Java code. If you create your -// own protocol compiler binary and you want it to support Java output, you -// can do so by registering an instance of this CodeGenerator with the -// CommandLineInterface in your main() function. +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +// CodeGenerator implementation which generates Java code. If you create your +// own protocol compiler binary and you want it to support Java output, you +// can do so by registering an instance of this CodeGenerator with the +// CommandLineInterface in your main() function. class PROTOC_EXPORT JavaGenerator : public CodeGenerator { - public: - JavaGenerator(); - ~JavaGenerator(); - - // implements CodeGenerator ---------------------------------------- + public: + JavaGenerator(); + ~JavaGenerator(); + + // implements CodeGenerator ---------------------------------------- bool Generate(const FileDescriptor* file, const TProtoStringType& parameter, GeneratorContext* context, TProtoStringType* error) const override; - + uint64_t GetSupportedFeatures() const override; - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - + #include <google/protobuf/port_undef.inc> -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.cc index 3a62adb103..549df0114b 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.cc @@ -1,37 +1,37 @@ -// 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: liujisi@google.com (Pherl Liu) - +// 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: liujisi@google.com (Pherl Liu) + #include <google/protobuf/compiler/java/java_generator_factory.h> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_enum_field.h> #include <google/protobuf/compiler/java/java_extension.h> @@ -41,46 +41,46 @@ #include <google/protobuf/compiler/java/java_message.h> #include <google/protobuf/compiler/java/java_message_lite.h> #include <google/protobuf/compiler/java/java_service.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -GeneratorFactory::GeneratorFactory() {} -GeneratorFactory::~GeneratorFactory() {} - -// =================================================================== - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +GeneratorFactory::GeneratorFactory() {} +GeneratorFactory::~GeneratorFactory() {} + +// =================================================================== + ImmutableGeneratorFactory::ImmutableGeneratorFactory(Context* context) : context_(context) {} -ImmutableGeneratorFactory::~ImmutableGeneratorFactory() {} - -MessageGenerator* ImmutableGeneratorFactory::NewMessageGenerator( - const Descriptor* descriptor) const { - if (HasDescriptorMethods(descriptor, context_->EnforceLite())) { - return new ImmutableMessageGenerator(descriptor, context_); - } else { - return new ImmutableMessageLiteGenerator(descriptor, context_); - } -} - -ExtensionGenerator* ImmutableGeneratorFactory::NewExtensionGenerator( - const FieldDescriptor* descriptor) const { - if (HasDescriptorMethods(descriptor->file(), context_->EnforceLite())) { - return new ImmutableExtensionGenerator(descriptor, context_); - } else { - return new ImmutableExtensionLiteGenerator(descriptor, context_); - } -} - -ServiceGenerator* ImmutableGeneratorFactory::NewServiceGenerator( - const ServiceDescriptor* descriptor) const { - return new ImmutableServiceGenerator(descriptor, context_); -} - - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +ImmutableGeneratorFactory::~ImmutableGeneratorFactory() {} + +MessageGenerator* ImmutableGeneratorFactory::NewMessageGenerator( + const Descriptor* descriptor) const { + if (HasDescriptorMethods(descriptor, context_->EnforceLite())) { + return new ImmutableMessageGenerator(descriptor, context_); + } else { + return new ImmutableMessageLiteGenerator(descriptor, context_); + } +} + +ExtensionGenerator* ImmutableGeneratorFactory::NewExtensionGenerator( + const FieldDescriptor* descriptor) const { + if (HasDescriptorMethods(descriptor->file(), context_->EnforceLite())) { + return new ImmutableExtensionGenerator(descriptor, context_); + } else { + return new ImmutableExtensionLiteGenerator(descriptor, context_); + } +} + +ServiceGenerator* ImmutableGeneratorFactory::NewServiceGenerator( + const ServiceDescriptor* descriptor) const { + return new ImmutableServiceGenerator(descriptor, context_); +} + + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.h index 16688a56d0..557f4e30b9 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_generator_factory.h @@ -1,42 +1,42 @@ -// 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: liujisi@google.com (Pherl Liu) - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ - +// 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: liujisi@google.com (Pherl Liu) + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ + #include <google/protobuf/stubs/common.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { class FieldDescriptor; // descriptor.h class Descriptor; // descriptor.h class ServiceDescriptor; // descriptor.h @@ -50,54 +50,54 @@ class Context; // context.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class GeneratorFactory { - public: - GeneratorFactory(); - virtual ~GeneratorFactory(); - - virtual MessageGenerator* NewMessageGenerator( - const Descriptor* descriptor) const = 0; - - virtual ExtensionGenerator* NewExtensionGenerator( - const FieldDescriptor* descriptor) const = 0; - - 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); - virtual ~ImmutableGeneratorFactory(); - - virtual MessageGenerator* NewMessageGenerator( - const Descriptor* descriptor) const; - - virtual ExtensionGenerator* NewExtensionGenerator( - const FieldDescriptor* descriptor) const; - - virtual ServiceGenerator* NewServiceGenerator( - const ServiceDescriptor* descriptor) const; - - private: - Context* context_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableGeneratorFactory); -}; - - -} // namespace java -} // namespace compiler -} // namespace protobuf +namespace protobuf { +namespace compiler { +namespace java { + +class GeneratorFactory { + public: + GeneratorFactory(); + virtual ~GeneratorFactory(); + + virtual MessageGenerator* NewMessageGenerator( + const Descriptor* descriptor) const = 0; + + virtual ExtensionGenerator* NewExtensionGenerator( + const FieldDescriptor* descriptor) const = 0; + + 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); + virtual ~ImmutableGeneratorFactory(); + + virtual MessageGenerator* NewMessageGenerator( + const Descriptor* descriptor) const; + + virtual ExtensionGenerator* NewExtensionGenerator( + const FieldDescriptor* descriptor) const; + + virtual ServiceGenerator* NewServiceGenerator( + const ServiceDescriptor* descriptor) const; + + private: + Context* context_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableGeneratorFactory); +}; + + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.cc index a498388ade..adb62daccc 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.cc @@ -1,45 +1,45 @@ -// 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. - +// 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/java_helpers.h> -#include <algorithm> +#include <algorithm> #include <cstdint> -#include <limits> +#include <limits> #include <unordered_set> -#include <vector> - +#include <vector> + #include <google/protobuf/stubs/stringprintf.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/compiler/java/java_names.h> @@ -48,35 +48,35 @@ #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> #include <google/protobuf/stubs/hash.h> // for hash<T *> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -using internal::WireFormat; -using internal::WireFormatLite; - -const char kThickSeparator[] = + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +using internal::WireFormat; +using internal::WireFormatLite; + +const char kThickSeparator[] = "// ===================================================================\n"; -const char kThinSeparator[] = +const char kThinSeparator[] = "// -------------------------------------------------------------------\n"; - -namespace { - -const char* kDefaultPackage = ""; - -// Names that should be avoided as field names. -// Using them will cause the compiler to generate accessors whose names are -// colliding with methods defined in base classes. -const char* kForbiddenWordList[] = { + +namespace { + +const char* kDefaultPackage = ""; + +// Names that should be avoided as field names. +// Using them will cause the compiler to generate accessors whose names are +// colliding with methods defined in base classes. +const char* kForbiddenWordList[] = { // message base class: "cached_size", "serialized_size", // java.lang.Object: "class", -}; - +}; + const std::unordered_set<TProtoStringType>* kReservedNames = new std::unordered_set<TProtoStringType>({ "abstract", "assert", "boolean", "break", "byte", @@ -92,49 +92,49 @@ const std::unordered_set<TProtoStringType>* kReservedNames = }); bool IsForbidden(const TProtoStringType& field_name) { - for (int i = 0; i < GOOGLE_ARRAYSIZE(kForbiddenWordList); ++i) { - if (field_name == kForbiddenWordList[i]) { - return true; - } - } - return false; -} - + for (int i = 0; i < GOOGLE_ARRAYSIZE(kForbiddenWordList); ++i) { + if (field_name == 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, + // 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) { - if (annotation_file.empty()) { - return; - } + if (annotation_file.empty()) { + return; + } TProtoStringType ptemplate = - "@javax.annotation.Generated(value=\"protoc\", comments=\"annotations:"; - ptemplate.push_back(delimiter); - ptemplate.append("annotation_file"); - ptemplate.push_back(delimiter); - ptemplate.append("\")\n"); - printer->Print(ptemplate.c_str(), "annotation_file", annotation_file); -} - + "@javax.annotation.Generated(value=\"protoc\", comments=\"annotations:"; + ptemplate.push_back(delimiter); + ptemplate.append("annotation_file"); + ptemplate.push_back(delimiter); + ptemplate.append("\")\n"); + printer->Print(ptemplate.c_str(), "annotation_file", annotation_file); +} + void PrintEnumVerifierLogic(io::Printer* printer, const FieldDescriptor* descriptor, const std::map<TProtoStringType, TProtoStringType>& variables, @@ -160,39 +160,39 @@ TProtoStringType UnderscoresToCamelCase(const TProtoStringType& input, bool cap_next_letter) { GOOGLE_CHECK(!input.empty()); TProtoStringType result; - // Note: I distrust ctype.h due to locales. - for (int i = 0; i < input.size(); i++) { - if ('a' <= input[i] && input[i] <= 'z') { - if (cap_next_letter) { - result += input[i] + ('A' - 'a'); - } else { - result += input[i]; - } - cap_next_letter = false; - } else if ('A' <= input[i] && input[i] <= 'Z') { - if (i == 0 && !cap_next_letter) { - // Force first letter to lower-case unless explicitly told to - // capitalize it. - result += input[i] + ('a' - 'A'); - } else { - // Capital letters after the first are left as-is. - result += input[i]; - } - cap_next_letter = false; - } else if ('0' <= input[i] && input[i] <= '9') { - result += input[i]; - cap_next_letter = true; - } else { - cap_next_letter = true; - } - } - // Add a trailing "_" if the name should be altered. - if (input[input.size() - 1] == '#') { - result += '_'; - } - return result; -} - + // Note: I distrust ctype.h due to locales. + for (int i = 0; i < input.size(); i++) { + if ('a' <= input[i] && input[i] <= 'z') { + if (cap_next_letter) { + result += input[i] + ('A' - 'a'); + } else { + result += input[i]; + } + cap_next_letter = false; + } else if ('A' <= input[i] && input[i] <= 'Z') { + if (i == 0 && !cap_next_letter) { + // Force first letter to lower-case unless explicitly told to + // capitalize it. + result += input[i] + ('a' - 'A'); + } else { + // Capital letters after the first are left as-is. + result += input[i]; + } + cap_next_letter = false; + } else if ('0' <= input[i] && input[i] <= '9') { + result += input[i]; + cap_next_letter = true; + } else { + cap_next_letter = true; + } + } + // Add a trailing "_" if the name should be altered. + if (input[input.size() - 1] == '#') { + result += '_'; + } + return result; +} + TProtoStringType ToCamelCase(const TProtoStringType& input, bool lower_first) { bool capitalize_next = !lower_first; TProtoStringType result; @@ -226,21 +226,21 @@ char ToLowerCh(char ch) { } TProtoStringType UnderscoresToCamelCase(const FieldDescriptor* field) { - return UnderscoresToCamelCase(FieldName(field), false); -} - + return UnderscoresToCamelCase(FieldName(field), false); +} + TProtoStringType UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) { - return UnderscoresToCamelCase(FieldName(field), true); -} - + return UnderscoresToCamelCase(FieldName(field), true); +} + TProtoStringType CapitalizedFieldName(const FieldDescriptor* field) { return UnderscoresToCapitalizedCamelCase(field); } TProtoStringType UnderscoresToCamelCase(const MethodDescriptor* method) { - return UnderscoresToCamelCase(method->name(), false); -} - + return UnderscoresToCamelCase(method->name(), false); +} + TProtoStringType UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) { TProtoStringType name = UnderscoresToCamelCase(field); if (kReservedNames->find(name) != kReservedNames->end()) { @@ -266,9 +266,9 @@ bool IsForbiddenKotlin(const TProtoStringType& field_name) { } TProtoStringType UniqueFileScopeIdentifier(const Descriptor* descriptor) { - return "static_" + StringReplace(descriptor->full_name(), ".", "_", true); -} - + return "static_" + StringReplace(descriptor->full_name(), ".", "_", true); +} + TProtoStringType CamelCaseFieldName(const FieldDescriptor* field) { TProtoStringType fieldName = UnderscoresToCamelCase(field); if ('0' <= fieldName[0] && fieldName[0] <= '9') { @@ -278,134 +278,134 @@ TProtoStringType CamelCaseFieldName(const FieldDescriptor* field) { } TProtoStringType FileClassName(const FileDescriptor* file, bool immutable) { - ClassNameResolver name_resolver; - return name_resolver.GetFileClassName(file, 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; -} - + + 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 */); } TProtoStringType JavaPackageToDir(TProtoStringType package_name) { TProtoStringType package_dir = StringReplace(package_name, ".", "/", true); - if (!package_dir.empty()) package_dir += "/"; - return package_dir; -} - + if (!package_dir.empty()) package_dir += "/"; + return package_dir; +} + TProtoStringType ClassName(const Descriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - + ClassNameResolver name_resolver; + return name_resolver.GetClassName(descriptor, true); +} + TProtoStringType ClassName(const EnumDescriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - + ClassNameResolver name_resolver; + return name_resolver.GetClassName(descriptor, true); +} + TProtoStringType ClassName(const ServiceDescriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - + ClassNameResolver name_resolver; + return name_resolver.GetClassName(descriptor, true); +} + TProtoStringType ClassName(const FileDescriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - + 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 interfaces; +} + + TProtoStringType ExtraBuilderInterfaces(const Descriptor* descriptor) { TProtoStringType interfaces = "// @@protoc_insertion_point(builder_implements:" + descriptor->full_name() + ")"; - return interfaces; -} - + return interfaces; +} + TProtoStringType ExtraMessageOrBuilderInterfaces(const Descriptor* descriptor) { TProtoStringType interfaces = "// @@protoc_insertion_point(interface_extends:" + descriptor->full_name() + ")"; - return interfaces; -} - + return interfaces; +} + TProtoStringType FieldConstantName(const FieldDescriptor* field) { TProtoStringType name = field->name() + "_FIELD_NUMBER"; ToUpper(&name); - return name; -} - -FieldDescriptor::Type GetType(const FieldDescriptor* field) { - return field->type(); -} - -JavaType GetJavaType(const FieldDescriptor* field) { - switch (GetType(field)) { - case FieldDescriptor::TYPE_INT32: - case FieldDescriptor::TYPE_UINT32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_SFIXED32: - return JAVATYPE_INT; - - case FieldDescriptor::TYPE_INT64: - case FieldDescriptor::TYPE_UINT64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_SFIXED64: - return JAVATYPE_LONG; - - case FieldDescriptor::TYPE_FLOAT: - return JAVATYPE_FLOAT; - - case FieldDescriptor::TYPE_DOUBLE: - return JAVATYPE_DOUBLE; - - case FieldDescriptor::TYPE_BOOL: - return JAVATYPE_BOOLEAN; - - case FieldDescriptor::TYPE_STRING: - return JAVATYPE_STRING; - - case FieldDescriptor::TYPE_BYTES: - return JAVATYPE_BYTES; - - case FieldDescriptor::TYPE_ENUM: - return JAVATYPE_ENUM; - - case FieldDescriptor::TYPE_GROUP: - case FieldDescriptor::TYPE_MESSAGE: - return JAVATYPE_MESSAGE; - + return name; +} + +FieldDescriptor::Type GetType(const FieldDescriptor* field) { + return field->type(); +} + +JavaType GetJavaType(const FieldDescriptor* field) { + switch (GetType(field)) { + case FieldDescriptor::TYPE_INT32: + case FieldDescriptor::TYPE_UINT32: + case FieldDescriptor::TYPE_SINT32: + case FieldDescriptor::TYPE_FIXED32: + case FieldDescriptor::TYPE_SFIXED32: + return JAVATYPE_INT; + + case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_UINT64: + case FieldDescriptor::TYPE_SINT64: + case FieldDescriptor::TYPE_FIXED64: + case FieldDescriptor::TYPE_SFIXED64: + return JAVATYPE_LONG; + + case FieldDescriptor::TYPE_FLOAT: + return JAVATYPE_FLOAT; + + case FieldDescriptor::TYPE_DOUBLE: + return JAVATYPE_DOUBLE; + + case FieldDescriptor::TYPE_BOOL: + return JAVATYPE_BOOLEAN; + + case FieldDescriptor::TYPE_STRING: + return JAVATYPE_STRING; + + case FieldDescriptor::TYPE_BYTES: + return JAVATYPE_BYTES; + + case FieldDescriptor::TYPE_ENUM: + return JAVATYPE_ENUM; + + case FieldDescriptor::TYPE_GROUP: + case FieldDescriptor::TYPE_MESSAGE: + return JAVATYPE_MESSAGE; + // No default because we want the compiler to complain if any new // types are added. - } - - GOOGLE_LOG(FATAL) << "Can't get here."; - return JAVATYPE_INT; -} - -const char* PrimitiveTypeName(JavaType type) { - switch (type) { + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return JAVATYPE_INT; +} + +const char* PrimitiveTypeName(JavaType type) { + switch (type) { case JAVATYPE_INT: return "int"; case JAVATYPE_LONG: @@ -424,21 +424,21 @@ const char* PrimitiveTypeName(JavaType type) { return NULL; case JAVATYPE_MESSAGE: return NULL; - + // No default because we want the compiler to complain if any new // JavaTypes are added. - } - - GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; -} - + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return NULL; +} + const char* PrimitiveTypeName(const FieldDescriptor* descriptor) { return PrimitiveTypeName(GetJavaType(descriptor)); } -const char* BoxedPrimitiveTypeName(JavaType type) { - switch (type) { +const char* BoxedPrimitiveTypeName(JavaType type) { + switch (type) { case JAVATYPE_INT: return "java.lang.Integer"; case JAVATYPE_LONG: @@ -457,15 +457,15 @@ const char* BoxedPrimitiveTypeName(JavaType type) { return NULL; case JAVATYPE_MESSAGE: return NULL; - + // No default because we want the compiler to complain if any new // JavaTypes are added. - } - - GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; -} - + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return NULL; +} + const char* BoxedPrimitiveTypeName(const FieldDescriptor* descriptor) { return BoxedPrimitiveTypeName(GetJavaType(descriptor)); } @@ -511,8 +511,8 @@ TProtoStringType GetOneofStoredType(const FieldDescriptor* field) { } } -const char* FieldTypeName(FieldDescriptor::Type field_type) { - switch (field_type) { +const char* FieldTypeName(FieldDescriptor::Type field_type) { + switch (field_type) { case FieldDescriptor::TYPE_INT32: return "INT32"; case FieldDescriptor::TYPE_UINT32: @@ -549,222 +549,222 @@ const char* FieldTypeName(FieldDescriptor::Type field_type) { return "GROUP"; case FieldDescriptor::TYPE_MESSAGE: return "MESSAGE"; - + // No default because we want the compiler to complain if any new // types are added. - } - - GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; -} - + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return NULL; +} + bool AllAscii(const TProtoStringType& text) { - for (int i = 0; i < text.size(); i++) { - if ((text[i] & 0x80) != 0) { - return false; - } - } - return true; -} - + for (int i = 0; i < text.size(); i++) { + if ((text[i] & 0x80) != 0) { + return false; + } + } + return true; +} + TProtoStringType DefaultValue(const FieldDescriptor* field, bool immutable, ClassNameResolver* name_resolver) { - // Switch on CppType since we need to know which default_value_* method - // of FieldDescriptor to call. - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_INT32: + // 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()); - case FieldDescriptor::CPPTYPE_UINT32: - // Need to print as a signed int since Java has no unsigned. + case FieldDescriptor::CPPTYPE_UINT32: + // Need to print as a signed int since Java has no unsigned. return StrCat(static_cast<int32_t>(field->default_value_uint32())); - case FieldDescriptor::CPPTYPE_INT64: + case FieldDescriptor::CPPTYPE_INT64: return StrCat(field->default_value_int64()) + "L"; - case FieldDescriptor::CPPTYPE_UINT64: + case FieldDescriptor::CPPTYPE_UINT64: return StrCat(static_cast<int64_t>(field->default_value_uint64())) + - "L"; - case FieldDescriptor::CPPTYPE_DOUBLE: { - double value = field->default_value_double(); + "L"; + case FieldDescriptor::CPPTYPE_DOUBLE: { + double value = field->default_value_double(); if (value == std::numeric_limits<double>::infinity()) { - return "Double.POSITIVE_INFINITY"; + return "Double.POSITIVE_INFINITY"; } else if (value == -std::numeric_limits<double>::infinity()) { - return "Double.NEGATIVE_INFINITY"; - } else if (value != value) { - return "Double.NaN"; - } else { - return SimpleDtoa(value) + "D"; - } - } - case FieldDescriptor::CPPTYPE_FLOAT: { - float value = field->default_value_float(); + return "Double.NEGATIVE_INFINITY"; + } else if (value != value) { + return "Double.NaN"; + } else { + return SimpleDtoa(value) + "D"; + } + } + case FieldDescriptor::CPPTYPE_FLOAT: { + float value = field->default_value_float(); if (value == std::numeric_limits<float>::infinity()) { - return "Float.POSITIVE_INFINITY"; + return "Float.POSITIVE_INFINITY"; } else if (value == -std::numeric_limits<float>::infinity()) { - return "Float.NEGATIVE_INFINITY"; - } else if (value != value) { - return "Float.NaN"; - } else { - return SimpleFtoa(value) + "F"; - } - } - case FieldDescriptor::CPPTYPE_BOOL: - return field->default_value_bool() ? "true" : "false"; - case FieldDescriptor::CPPTYPE_STRING: - if (GetType(field) == FieldDescriptor::TYPE_BYTES) { - if (field->has_default_value()) { - // See comments in Internal.java for gory details. - return strings::Substitute( + return "Float.NEGATIVE_INFINITY"; + } else if (value != value) { + return "Float.NaN"; + } else { + return SimpleFtoa(value) + "F"; + } + } + case FieldDescriptor::CPPTYPE_BOOL: + return field->default_value_bool() ? "true" : "false"; + case FieldDescriptor::CPPTYPE_STRING: + if (GetType(field) == FieldDescriptor::TYPE_BYTES) { + if (field->has_default_value()) { + // See comments in Internal.java for gory details. + return strings::Substitute( "com.google.protobuf.Internal.bytesDefaultValue(\"$0\")", 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()) + "\""; - } else { - // See comments in Internal.java for gory details. - return strings::Substitute( - "com.google.protobuf.Internal.stringDefaultValue(\"$0\")", - CEscape(field->default_value_string())); - } - } - - case FieldDescriptor::CPPTYPE_ENUM: - return name_resolver->GetClassName(field->enum_type(), immutable) + "." + + } 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()) + "\""; + } else { + // See comments in Internal.java for gory details. + return strings::Substitute( + "com.google.protobuf.Internal.stringDefaultValue(\"$0\")", + CEscape(field->default_value_string())); + } + } + + case FieldDescriptor::CPPTYPE_ENUM: + return name_resolver->GetClassName(field->enum_type(), immutable) + "." + field->default_value_enum()->name(); - - case FieldDescriptor::CPPTYPE_MESSAGE: - return name_resolver->GetClassName(field->message_type(), immutable) + + + case FieldDescriptor::CPPTYPE_MESSAGE: + return 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."; - return ""; -} - -bool IsDefaultValueJavaDefault(const FieldDescriptor* field) { - // 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 field->default_value_int32() == 0; - case FieldDescriptor::CPPTYPE_UINT32: - return field->default_value_uint32() == 0; - case FieldDescriptor::CPPTYPE_INT64: - return field->default_value_int64() == 0L; - case FieldDescriptor::CPPTYPE_UINT64: - return field->default_value_uint64() == 0L; - case FieldDescriptor::CPPTYPE_DOUBLE: - return field->default_value_double() == 0.0; - case FieldDescriptor::CPPTYPE_FLOAT: - return field->default_value_float() == 0.0; - case FieldDescriptor::CPPTYPE_BOOL: - return field->default_value_bool() == false; - case FieldDescriptor::CPPTYPE_ENUM: - return field->default_value_enum()->number() == 0; - case FieldDescriptor::CPPTYPE_STRING: - case FieldDescriptor::CPPTYPE_MESSAGE: - return false; - + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return ""; +} + +bool IsDefaultValueJavaDefault(const FieldDescriptor* field) { + // 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 field->default_value_int32() == 0; + case FieldDescriptor::CPPTYPE_UINT32: + return field->default_value_uint32() == 0; + case FieldDescriptor::CPPTYPE_INT64: + return field->default_value_int64() == 0L; + case FieldDescriptor::CPPTYPE_UINT64: + return field->default_value_uint64() == 0L; + case FieldDescriptor::CPPTYPE_DOUBLE: + return field->default_value_double() == 0.0; + case FieldDescriptor::CPPTYPE_FLOAT: + return field->default_value_float() == 0.0; + case FieldDescriptor::CPPTYPE_BOOL: + return field->default_value_bool() == false; + case FieldDescriptor::CPPTYPE_ENUM: + return field->default_value_enum()->number() == 0; + case FieldDescriptor::CPPTYPE_STRING: + case FieldDescriptor::CPPTYPE_MESSAGE: + return false; + // No default because we want the compiler to complain if any new // types are added. - } - - GOOGLE_LOG(FATAL) << "Can't get here."; - return false; -} - -bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field) { - return GetJavaType(field) == JAVATYPE_BYTES && - field->default_value_string() != ""; -} - -const char* bit_masks[] = { + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return false; +} + +bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field) { + return GetJavaType(field) == JAVATYPE_BYTES && + field->default_value_string() != ""; +} + +const char* bit_masks[] = { "0x00000001", "0x00000002", "0x00000004", "0x00000008", "0x00000010", "0x00000020", "0x00000040", "0x00000080", - + "0x00000100", "0x00000200", "0x00000400", "0x00000800", "0x00001000", "0x00002000", "0x00004000", "0x00008000", - + "0x00010000", "0x00020000", "0x00040000", "0x00080000", "0x00100000", "0x00200000", "0x00400000", "0x00800000", - + "0x01000000", "0x02000000", "0x04000000", "0x08000000", "0x10000000", "0x20000000", "0x40000000", "0x80000000", -}; - +}; + TProtoStringType GetBitFieldName(int index) { TProtoStringType varName = "bitField"; varName += StrCat(index); - varName += "_"; - return varName; -} - + varName += "_"; + return varName; +} + TProtoStringType GetBitFieldNameForBit(int bitIndex) { - return GetBitFieldName(bitIndex / 32); -} - -namespace { - + return GetBitFieldName(bitIndex / 32); +} + +namespace { + TProtoStringType GenerateGetBitInternal(const TProtoStringType& prefix, int bitIndex) { TProtoStringType varName = prefix + GetBitFieldNameForBit(bitIndex); - int bitInVarIndex = bitIndex % 32; - + int bitInVarIndex = bitIndex % 32; + TProtoStringType mask = bit_masks[bitInVarIndex]; TProtoStringType result = "((" + varName + " & " + mask + ") != 0)"; - return result; -} - + return result; +} + TProtoStringType GenerateSetBitInternal(const TProtoStringType& prefix, int bitIndex) { TProtoStringType varName = prefix + GetBitFieldNameForBit(bitIndex); - int bitInVarIndex = bitIndex % 32; - + int bitInVarIndex = bitIndex % 32; + TProtoStringType mask = bit_masks[bitInVarIndex]; TProtoStringType result = varName + " |= " + mask; - return result; -} - -} // namespace - + return result; +} + +} // namespace + TProtoStringType GenerateGetBit(int bitIndex) { - return GenerateGetBitInternal("", bitIndex); -} - + return GenerateGetBitInternal("", bitIndex); +} + TProtoStringType GenerateSetBit(int bitIndex) { - return GenerateSetBitInternal("", bitIndex); -} - + return GenerateSetBitInternal("", bitIndex); +} + TProtoStringType GenerateClearBit(int bitIndex) { TProtoStringType varName = GetBitFieldNameForBit(bitIndex); - int bitInVarIndex = bitIndex % 32; - + int bitInVarIndex = bitIndex % 32; + TProtoStringType mask = bit_masks[bitInVarIndex]; TProtoStringType result = varName + " = (" + varName + " & ~" + mask + ")"; - return result; -} - + return result; +} + TProtoStringType GenerateGetBitFromLocal(int bitIndex) { - return GenerateGetBitInternal("from_", bitIndex); -} - + return GenerateGetBitInternal("from_", bitIndex); +} + TProtoStringType GenerateSetBitToLocal(int bitIndex) { - return GenerateSetBitInternal("to_", bitIndex); -} - + return GenerateSetBitInternal("to_", bitIndex); +} + TProtoStringType GenerateGetBitMutableLocal(int bitIndex) { - return GenerateGetBitInternal("mutable_", bitIndex); -} - + return GenerateGetBitInternal("mutable_", bitIndex); +} + TProtoStringType GenerateSetBitMutableLocal(int bitIndex) { - return GenerateSetBitInternal("mutable_", bitIndex); -} - -bool IsReferenceType(JavaType type) { - switch (type) { + return GenerateSetBitInternal("mutable_", bitIndex); +} + +bool IsReferenceType(JavaType type) { + switch (type) { case JAVATYPE_INT: return false; case JAVATYPE_LONG: @@ -783,17 +783,17 @@ bool IsReferenceType(JavaType type) { return true; case JAVATYPE_MESSAGE: return true; - + // No default because we want the compiler to complain if any new // JavaTypes are added. - } - - GOOGLE_LOG(FATAL) << "Can't get here."; - return false; -} - -const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) { - switch (GetType(field)) { + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return false; +} + +const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) { + switch (GetType(field)) { case FieldDescriptor::TYPE_INT32: return "Int32"; case FieldDescriptor::TYPE_UINT32: @@ -823,27 +823,27 @@ const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) { case FieldDescriptor::TYPE_STRING: return "String"; case FieldDescriptor::TYPE_BYTES: { - return "Bytes"; - } + return "Bytes"; + } case FieldDescriptor::TYPE_ENUM: return "Enum"; case FieldDescriptor::TYPE_GROUP: return "Group"; case FieldDescriptor::TYPE_MESSAGE: return "Message"; - + // No default because we want the compiler to complain if any new // types are added. - } - - GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; -} - -// For encodings with fixed sizes, returns that size in bytes. Otherwise -// returns -1. -int FixedSize(FieldDescriptor::Type type) { - switch (type) { + } + + GOOGLE_LOG(FATAL) << "Can't get here."; + return NULL; +} + +// For encodings with fixed sizes, returns that size in bytes. Otherwise +// returns -1. +int FixedSize(FieldDescriptor::Type type) { + switch (type) { case FieldDescriptor::TYPE_INT32: return -1; case FieldDescriptor::TYPE_INT64: @@ -868,12 +868,12 @@ int FixedSize(FieldDescriptor::Type type) { return WireFormatLite::kFloatSize; case FieldDescriptor::TYPE_DOUBLE: return WireFormatLite::kDoubleSize; - + case FieldDescriptor::TYPE_BOOL: return WireFormatLite::kBoolSize; case FieldDescriptor::TYPE_ENUM: return -1; - + case FieldDescriptor::TYPE_STRING: return -1; case FieldDescriptor::TYPE_BYTES: @@ -882,82 +882,82 @@ int FixedSize(FieldDescriptor::Type type) { return -1; case FieldDescriptor::TYPE_MESSAGE: return -1; - + // No default because we want the compiler to complain if any new // types are added. - } - GOOGLE_LOG(FATAL) << "Can't get here."; - return -1; -} - -// Sort the fields of the given Descriptor by number into a new[]'d array -// and return it. The caller should delete the returned array. -const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { - const FieldDescriptor** fields = + } + GOOGLE_LOG(FATAL) << "Can't get here."; + return -1; +} + +// Sort the fields of the given Descriptor by number into a new[]'d array +// and return it. The caller should delete the returned array. +const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { + const FieldDescriptor** fields = new const FieldDescriptor*[descriptor->field_count()]; - for (int i = 0; i < descriptor->field_count(); i++) { - fields[i] = descriptor->field(i); - } - std::sort(fields, fields + descriptor->field_count(), - FieldOrderingByNumber()); - return fields; -} - -// Returns true if the message type has any required fields. If it doesn't, -// we can optimize out calls to its isInitialized() method. -// -// already_seen is used to avoid checking the same type multiple times -// (and also to protect against recursion). + for (int i = 0; i < descriptor->field_count(); i++) { + fields[i] = descriptor->field(i); + } + std::sort(fields, fields + descriptor->field_count(), + FieldOrderingByNumber()); + return fields; +} + +// Returns true if the message type has any required fields. If it doesn't, +// we can optimize out calls to its isInitialized() method. +// +// 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) { - if (already_seen->count(type) > 0) { - // The type is already in cache. This means that either: - // a. The type has no required fields. - // b. We are in the midst of checking if the type has required fields, - // somewhere up the stack. In this case, we know that if the type - // has any required fields, they'll be found when we return to it, - // and the whole call to HasRequiredFields() will return true. - // Therefore, we don't have to check if this type has required fields - // here. - return false; - } - already_seen->insert(type); - - // If the type has extensions, an extension with message type could contain - // required fields, so we have to be conservative and assume such an - // extension exists. - if (type->extension_range_count() > 0) return true; - - for (int i = 0; i < type->field_count(); i++) { - const FieldDescriptor* field = type->field(i); - if (field->is_required()) { - return true; - } - if (GetJavaType(field) == JAVATYPE_MESSAGE) { - if (HasRequiredFields(field->message_type(), already_seen)) { - return true; - } - } - } - - return false; -} - -bool HasRequiredFields(const Descriptor* type) { + if (already_seen->count(type) > 0) { + // The type is already in cache. This means that either: + // a. The type has no required fields. + // b. We are in the midst of checking if the type has required fields, + // somewhere up the stack. In this case, we know that if the type + // has any required fields, they'll be found when we return to it, + // and the whole call to HasRequiredFields() will return true. + // Therefore, we don't have to check if this type has required fields + // here. + return false; + } + already_seen->insert(type); + + // If the type has extensions, an extension with message type could contain + // required fields, so we have to be conservative and assume such an + // extension exists. + if (type->extension_range_count() > 0) return true; + + for (int i = 0; i < type->field_count(); i++) { + const FieldDescriptor* field = type->field(i); + if (field->is_required()) { + return true; + } + if (GetJavaType(field) == JAVATYPE_MESSAGE) { + if (HasRequiredFields(field->message_type(), already_seen)) { + return true; + } + } + } + + return false; +} + +bool HasRequiredFields(const Descriptor* type) { std::unordered_set<const Descriptor*> already_seen; - return HasRequiredFields(type, &already_seen); -} - -bool HasRepeatedFields(const Descriptor* descriptor) { - for (int i = 0; i < descriptor->field_count(); ++i) { - const FieldDescriptor* field = descriptor->field(i); - if (field->is_repeated()) { - return true; - } - } - return false; -} - + return HasRequiredFields(type, &already_seen); +} + +bool HasRepeatedFields(const Descriptor* descriptor) { + for (int i = 0; i < descriptor->field_count(); ++i) { + const FieldDescriptor* field = descriptor->field(i); + if (field->is_repeated()) { + return true; + } + } + return false; +} + // Encode an unsigned 32-bit value into a sequence of UTF-16 characters. // // If the value is in [0x0000, 0xD7FF], we encode it with a single character @@ -1094,7 +1094,7 @@ void EscapeUtf16ToString(uint16_t code, TProtoStringType* output) { } } -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.h index 5acc729c1d..1d099a37c9 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_helpers.h @@ -1,40 +1,40 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ + #include <cstdint> #include <string> @@ -42,30 +42,30 @@ #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// Commonly-used separator comments. Thick is a line of '=', thin is a line -// of '-'. -extern const char kThickSeparator[]; -extern const char kThinSeparator[]; - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +// Commonly-used separator comments. Thick is a line of '=', thin is a line +// of '-'. +extern const char kThickSeparator[]; +extern const char kThinSeparator[]; + bool IsForbiddenKotlin(const TProtoStringType& 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 -// annotation's comments field. delimiter should be the Printer's delimiter -// character. annotation_file will be included verbatim into a Java literal -// string, so it should not contain quotes or invalid Java escape sequences; -// however, these are unlikely to appear in practice, as the value of -// 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 = '$', +// If annotation_file is non-empty, prints a javax.annotation.Generated +// annotation to the given Printer. annotation_file will be referenced in the +// annotation's comments field. delimiter should be the Printer's delimiter +// character. annotation_file will be included verbatim into a Java literal +// string, so it should not contain quotes or invalid Java escape sequences; +// however, these are unlikely to appear in practice, as the value of +// 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 = ""); - + // 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, @@ -74,8 +74,8 @@ void PrintEnumVerifierLogic(io::Printer* printer, 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. +// 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); @@ -85,15 +85,15 @@ char ToLowerCh(char ch); // 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. +// 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.) + +// 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); @@ -101,44 +101,44 @@ TProtoStringType UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* fiel // complete Java identifier by adding a _ if needed. TProtoStringType CamelCaseFieldName(const FieldDescriptor* field); -// Get an identifier that uniquely identifies this type within the file. -// This is used to declare static variables related to this type at the -// outermost file scope. +// Get an identifier that uniquely identifies this type within the file. +// This is used to declare static variables related to this type at the +// outermost file scope. TProtoStringType UniqueFileScopeIdentifier(const Descriptor* descriptor); - -// Gets the unqualified class name for the file. For each .proto file, there -// will be one Java class containing all the immutable messages and another -// Java class containing all the mutable messages. -// TODO(xiaofeng): remove the default value after updating client code. + +// Gets the unqualified class name for the file. For each .proto file, there +// will be one Java class containing all the immutable messages and another +// Java class containing all the mutable messages. +// TODO(xiaofeng): remove the default value after updating client code. TProtoStringType FileClassName(const FileDescriptor* file, bool immutable = true); - -// Returns the file's Java package name. + +// Returns the file's Java package name. TProtoStringType FileJavaPackage(const FileDescriptor* file, bool immutable); - -// Returns output directory for the given package name. + +// Returns output directory for the given package name. TProtoStringType JavaPackageToDir(TProtoStringType package_name); - -// Comma-separate list of option-specified interfaces implemented by the -// Message, to follow the "implements" declaration of the Message definition. + +// 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); -// Comma-separate list of option-specified interfaces implemented by the -// MutableMessage, to follow the "implements" declaration of the MutableMessage -// definition. +// Comma-separate list of option-specified interfaces implemented by the +// MutableMessage, to follow the "implements" declaration of the MutableMessage +// definition. TProtoStringType ExtraMutableMessageInterfaces(const Descriptor* descriptor); -// Comma-separate list of option-specified interfaces implemented by the -// Builder, to follow the "implements" declaration of the Builder definition. +// Comma-separate list of option-specified interfaces implemented by the +// Builder, to follow the "implements" declaration of the Builder definition. TProtoStringType ExtraBuilderInterfaces(const Descriptor* descriptor); -// Comma-separate list of option-specified interfaces extended by the -// MessageOrBuilder, to follow the "extends" declaration of the -// MessageOrBuilder definition. +// Comma-separate list of option-specified interfaces extended by the +// MessageOrBuilder, to follow the "extends" declaration of the +// MessageOrBuilder definition. TProtoStringType ExtraMessageOrBuilderInterfaces(const Descriptor* descriptor); - -// Get the unqualified Java class name for mutable messages. i.e. without -// package or outer classnames. + +// Get the unqualified Java class name for mutable messages. i.e. without +// package or outer classnames. inline TProtoStringType ShortMutableJavaClassName(const Descriptor* descriptor) { - return descriptor->name(); -} - + return descriptor->name(); +} + // Whether the given descriptor is for one of the core descriptor protos. We // cannot currently use the new runtime with core protos since there is a // bootstrapping problem with obtaining their descriptors. @@ -146,221 +146,221 @@ inline bool IsDescriptorProto(const Descriptor* descriptor) { return descriptor->file()->name() == "net/proto2/proto/descriptor.proto" || descriptor->file()->name() == "google/protobuf/descriptor.proto"; } - + // Returns the stored type string used by the experimental runtime for oneof // fields. TProtoStringType GetOneofStoredType(const FieldDescriptor* field); -// Whether we should generate multiple java files for messages. +// Whether we should generate multiple java files for messages. inline bool MultipleJavaFiles(const FileDescriptor* descriptor, bool immutable) { (void) immutable; - return descriptor->options().java_multiple_files(); -} - - -// Returns true if `descriptor` will be written to its own .java file. -// `immutable` should be set to true if we're generating for the immutable API. -template <typename Descriptor> -bool IsOwnFile(const Descriptor* descriptor, bool immutable) { - return descriptor->containing_type() == NULL && - MultipleJavaFiles(descriptor->file(), immutable); -} - -template <> -inline bool IsOwnFile(const ServiceDescriptor* descriptor, bool immutable) { - return MultipleJavaFiles(descriptor->file(), immutable); -} - -// If `descriptor` describes an object with its own .java file, -// returns the name (relative to that .java file) of the file that stores -// annotation data for that descriptor. `suffix` is usually empty, but may -// (e.g.) be "OrBuilder" for some generated interfaces. -template <typename Descriptor> + return descriptor->options().java_multiple_files(); +} + + +// Returns true if `descriptor` will be written to its own .java file. +// `immutable` should be set to true if we're generating for the immutable API. +template <typename Descriptor> +bool IsOwnFile(const Descriptor* descriptor, bool immutable) { + return descriptor->containing_type() == NULL && + MultipleJavaFiles(descriptor->file(), immutable); +} + +template <> +inline bool IsOwnFile(const ServiceDescriptor* descriptor, bool immutable) { + return MultipleJavaFiles(descriptor->file(), immutable); +} + +// If `descriptor` describes an object with its own .java file, +// returns the name (relative to that .java file) of the file that stores +// annotation data for that descriptor. `suffix` is usually empty, but may +// (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, + 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, '$', + PrintGeneratedAnnotation(printer, '$', context->options().annotate_code ? AnnotationFileName(descriptor, suffix) : ""); - } -} - -// Get the unqualified name that should be used for a field's field -// number constant. + } +} + +// Get the unqualified name that should be used for a field's field +// number constant. TProtoStringType FieldConstantName(const FieldDescriptor* field); - -// Returns the type of the FieldDescriptor. -// This does nothing interesting for the open source release, but is used for -// hacks that improve compatibility with version 1 protocol buffers at Google. -FieldDescriptor::Type GetType(const FieldDescriptor* field); - -enum JavaType { - JAVATYPE_INT, - JAVATYPE_LONG, - JAVATYPE_FLOAT, - JAVATYPE_DOUBLE, - JAVATYPE_BOOLEAN, - JAVATYPE_STRING, - JAVATYPE_BYTES, - JAVATYPE_ENUM, - JAVATYPE_MESSAGE -}; - -JavaType GetJavaType(const FieldDescriptor* field); - -const char* 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); - + +// Returns the type of the FieldDescriptor. +// This does nothing interesting for the open source release, but is used for +// hacks that improve compatibility with version 1 protocol buffers at Google. +FieldDescriptor::Type GetType(const FieldDescriptor* field); + +enum JavaType { + JAVATYPE_INT, + JAVATYPE_LONG, + JAVATYPE_FLOAT, + JAVATYPE_DOUBLE, + JAVATYPE_BOOLEAN, + JAVATYPE_STRING, + JAVATYPE_BYTES, + JAVATYPE_ENUM, + JAVATYPE_MESSAGE +}; + +JavaType GetJavaType(const FieldDescriptor* field); + +const char* 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); + // Kotlin source does not distinguish between primitives and non-primitives, // but does use Kotlin-specific qualified types for them. const char* 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); - -class ClassNameResolver; +// 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); + +class ClassNameResolver; TProtoStringType DefaultValue(const FieldDescriptor* field, bool immutable, ClassNameResolver* name_resolver); inline TProtoStringType ImmutableDefaultValue(const FieldDescriptor* field, ClassNameResolver* name_resolver) { - return DefaultValue(field, true, name_resolver); -} -bool IsDefaultValueJavaDefault(const FieldDescriptor* field); -bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field); - -// Does this message class have descriptor and reflection methods? + return DefaultValue(field, true, name_resolver); +} +bool IsDefaultValueJavaDefault(const FieldDescriptor* field); +bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field); + +// Does this message class have descriptor and reflection methods? inline bool HasDescriptorMethods(const Descriptor* /* descriptor */, - bool enforce_lite) { + bool enforce_lite) { return !enforce_lite; -} +} inline bool HasDescriptorMethods(const EnumDescriptor* /* descriptor */, - bool enforce_lite) { + bool enforce_lite) { return !enforce_lite; -} +} inline bool HasDescriptorMethods(const FileDescriptor* /* descriptor */, - bool enforce_lite) { + bool enforce_lite) { return !enforce_lite; -} - -// Should we generate generic services for this file? +} + +// Should we generate generic services for this file? inline bool HasGenericServices(const FileDescriptor* file, bool enforce_lite) { - return file->service_count() > 0 && - HasDescriptorMethods(file, enforce_lite) && - file->options().java_generic_services(); -} - -// Methods for shared bitfields. - -// Gets the name of the shared bitfield for the given index. + return file->service_count() > 0 && + HasDescriptorMethods(file, enforce_lite) && + file->options().java_generic_services(); +} + +// Methods for shared bitfields. + +// Gets the name of the shared bitfield for the given index. TProtoStringType GetBitFieldName(int index); - -// Gets the name of the shared bitfield for the given bit index. -// Effectively, GetBitFieldName(bitIndex / 32) + +// Gets the name of the shared bitfield for the given bit index. +// Effectively, GetBitFieldName(bitIndex / 32) TProtoStringType GetBitFieldNameForBit(int bitIndex); - -// Generates the java code for the expression that returns the boolean value -// of the bit of the shared bitfields for the given bit index. -// Example: "((bitField1_ & 0x04) == 0x04)" + +// Generates the java code for the expression that returns the boolean value +// of the bit of the shared bitfields for the given bit index. +// Example: "((bitField1_ & 0x04) == 0x04)" TProtoStringType GenerateGetBit(int bitIndex); - -// Generates the java code for the expression that sets the bit of the shared -// bitfields for the given bit index. -// Example: "bitField1_ = (bitField1_ | 0x04)" + +// Generates the java code for the expression that sets the bit of the shared +// bitfields for the given bit index. +// Example: "bitField1_ = (bitField1_ | 0x04)" TProtoStringType GenerateSetBit(int bitIndex); - -// Generates the java code for the expression that clears the bit of the shared -// bitfields for the given bit index. -// Example: "bitField1_ = (bitField1_ & ~0x04)" + +// Generates the java code for the expression that clears the bit of the shared +// bitfields for the given bit index. +// Example: "bitField1_ = (bitField1_ & ~0x04)" TProtoStringType GenerateClearBit(int bitIndex); - -// Does the same as GenerateGetBit but operates on the bit field on a local -// variable. This is used by the builder to copy the value in the builder to -// the message. -// Example: "((from_bitField1_ & 0x04) == 0x04)" + +// Does the same as GenerateGetBit but operates on the bit field on a local +// variable. This is used by the builder to copy the value in the builder to +// the message. +// Example: "((from_bitField1_ & 0x04) == 0x04)" TProtoStringType GenerateGetBitFromLocal(int bitIndex); - -// Does the same as GenerateSetBit but operates on the bit field on a local -// variable. This is used by the builder to copy the value in the builder to -// the message. -// Example: "to_bitField1_ = (to_bitField1_ | 0x04)" + +// Does the same as GenerateSetBit but operates on the bit field on a local +// variable. This is used by the builder to copy the value in the builder to +// the message. +// Example: "to_bitField1_ = (to_bitField1_ | 0x04)" TProtoStringType GenerateSetBitToLocal(int bitIndex); - -// Does the same as GenerateGetBit but operates on the bit field on a local -// variable. This is used by the parsing constructor to record if a repeated -// field is mutable. -// Example: "((mutable_bitField1_ & 0x04) == 0x04)" + +// Does the same as GenerateGetBit but operates on the bit field on a local +// variable. This is used by the parsing constructor to record if a repeated +// field is mutable. +// Example: "((mutable_bitField1_ & 0x04) == 0x04)" TProtoStringType GenerateGetBitMutableLocal(int bitIndex); - -// Does the same as GenerateSetBit but operates on the bit field on a local -// variable. This is used by the parsing constructor to record if a repeated -// field is mutable. -// Example: "mutable_bitField1_ = (mutable_bitField1_ | 0x04)" + +// Does the same as GenerateSetBit but operates on the bit field on a local +// variable. This is used by the parsing constructor to record if a repeated +// field is mutable. +// Example: "mutable_bitField1_ = (mutable_bitField1_ | 0x04)" TProtoStringType GenerateSetBitMutableLocal(int bitIndex); - -// Returns whether the JavaType is a reference type. -bool IsReferenceType(JavaType type); - -// Returns the capitalized name for calling relative functions in -// CodedInputStream -const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable); - -// For encodings with fixed sizes, returns that size in bytes. Otherwise -// returns -1. -int FixedSize(FieldDescriptor::Type type); - -// Comparators used to sort fields in MessageGenerator -struct FieldOrderingByNumber { - inline bool operator()(const FieldDescriptor* a, - const FieldDescriptor* b) const { - return a->number() < b->number(); - } -}; - -struct ExtensionRangeOrdering { - bool operator()(const Descriptor::ExtensionRange* a, - const Descriptor::ExtensionRange* b) const { - return a->start < b->start; - } -}; - -// Sort the fields of the given Descriptor by number into a new[]'d array -// and return it. The caller should delete the returned array. -const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor); - -// Does this message class have any packed fields? -inline bool HasPackedFields(const Descriptor* descriptor) { - for (int i = 0; i < descriptor->field_count(); i++) { - if (descriptor->field(i)->is_packed()) { - return true; - } - } - return false; -} - -// Check a message type and its sub-message types recursively to see if any of -// them has a required field. Return true if a required field is found. -bool HasRequiredFields(const Descriptor* descriptor); - + +// Returns whether the JavaType is a reference type. +bool IsReferenceType(JavaType type); + +// Returns the capitalized name for calling relative functions in +// CodedInputStream +const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable); + +// For encodings with fixed sizes, returns that size in bytes. Otherwise +// returns -1. +int FixedSize(FieldDescriptor::Type type); + +// Comparators used to sort fields in MessageGenerator +struct FieldOrderingByNumber { + inline bool operator()(const FieldDescriptor* a, + const FieldDescriptor* b) const { + return a->number() < b->number(); + } +}; + +struct ExtensionRangeOrdering { + bool operator()(const Descriptor::ExtensionRange* a, + const Descriptor::ExtensionRange* b) const { + return a->start < b->start; + } +}; + +// Sort the fields of the given Descriptor by number into a new[]'d array +// and return it. The caller should delete the returned array. +const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor); + +// Does this message class have any packed fields? +inline bool HasPackedFields(const Descriptor* descriptor) { + for (int i = 0; i < descriptor->field_count(); i++) { + if (descriptor->field(i)->is_packed()) { + return true; + } + } + return false; +} + +// Check a message type and its sub-message types recursively to see if any of +// them has a required field. Return true if a required field is found. +bool HasRequiredFields(const Descriptor* descriptor); + inline bool IsProto2(const FileDescriptor* descriptor) { return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2; -} - +} + inline bool IsRealOneof(const FieldDescriptor* descriptor) { return descriptor->containing_oneof() && !descriptor->containing_oneof()->is_synthetic(); @@ -381,50 +381,50 @@ inline bool HasHasbit(const FieldDescriptor* descriptor) { (descriptor->has_optional_keyword() || IsProto2(descriptor->file())); } -// Whether generate classes expose public PARSER instances. -inline bool ExposePublicParser(const FileDescriptor* descriptor) { - // TODO(liujisi): Mark the PARSER private in 3.1.x releases. - return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2; -} - -// Whether unknown enum values are kept (i.e., not stored in UnknownFieldSet -// but in the message and can be queried using additional getters that return -// ints. -inline bool SupportUnknownEnumValue(const FileDescriptor* descriptor) { - return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO3; -} - +// Whether generate classes expose public PARSER instances. +inline bool ExposePublicParser(const FileDescriptor* descriptor) { + // TODO(liujisi): Mark the PARSER private in 3.1.x releases. + return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2; +} + +// Whether unknown enum values are kept (i.e., not stored in UnknownFieldSet +// but in the message and can be queried using additional getters that return +// ints. +inline bool SupportUnknownEnumValue(const FileDescriptor* descriptor) { + return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO3; +} + inline bool SupportUnknownEnumValue(const FieldDescriptor* field) { return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3; } // Check whether a message has repeated fields. -bool HasRepeatedFields(const Descriptor* descriptor); - -inline bool IsMapEntry(const Descriptor* descriptor) { - return descriptor->options().map_entry(); -} - -inline bool IsMapField(const FieldDescriptor* descriptor) { - return descriptor->is_map(); -} - -inline bool IsAnyMessage(const Descriptor* descriptor) { - return descriptor->full_name() == "google.protobuf.Any"; -} - +bool HasRepeatedFields(const Descriptor* descriptor); + +inline bool IsMapEntry(const Descriptor* descriptor) { + return descriptor->options().map_entry(); +} + +inline bool IsMapField(const FieldDescriptor* descriptor) { + return descriptor->is_map(); +} + +inline bool IsAnyMessage(const Descriptor* descriptor) { + return descriptor->full_name() == "google.protobuf.Any"; +} + inline bool IsWrappersProtoFile(const FileDescriptor* descriptor) { return descriptor->name() == "google/protobuf/wrappers.proto"; } -inline bool CheckUtf8(const FieldDescriptor* descriptor) { - return descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 || +inline bool CheckUtf8(const FieldDescriptor* descriptor) { + return descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 || descriptor->file()->options().java_string_check_utf8(); -} - +} + inline TProtoStringType GeneratedCodeVersionSuffix() { - return "V3"; -} + return "V3"; +} void WriteUInt32ToUtf16CharSequence(uint32_t number, std::vector<uint16_t>* output); @@ -451,9 +451,9 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field); // and the first field number that are not in the table part std::pair<int, int> GetTableDrivenNumberOfEntriesAndLookUpStartFieldNumber( const FieldDescriptor** fields, int count); -} // namespace java -} // namespace compiler -} // namespace protobuf +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.cc index 353bff46db..ec6d6d3cc5 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.cc @@ -1,74 +1,74 @@ -// 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. - +// 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/java_map_field.h> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/io/printer.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { - -const FieldDescriptor* KeyField(const FieldDescriptor* descriptor) { - GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); - const Descriptor* message = descriptor->message_type(); - GOOGLE_CHECK(message->options().map_entry()); - return message->FindFieldByName("key"); -} - -const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) { - GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); - const Descriptor* message = descriptor->message_type(); - GOOGLE_CHECK(message->options().map_entry()); - return message->FindFieldByName("value"); -} - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { + +const FieldDescriptor* KeyField(const FieldDescriptor* descriptor) { + GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); + const Descriptor* message = descriptor->message_type(); + GOOGLE_CHECK(message->options().map_entry()); + return message->FindFieldByName("key"); +} + +const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) { + GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); + const Descriptor* message = descriptor->message_type(); + GOOGLE_CHECK(message->options().map_entry()); + return message->FindFieldByName("value"); +} + TProtoStringType TypeName(const FieldDescriptor* field, ClassNameResolver* name_resolver, bool boxed) { - if (GetJavaType(field) == JAVATYPE_MESSAGE) { - return name_resolver->GetImmutableClassName(field->message_type()); - } else if (GetJavaType(field) == JAVATYPE_ENUM) { - return name_resolver->GetImmutableClassName(field->enum_type()); - } else { - return boxed ? BoxedPrimitiveTypeName(GetJavaType(field)) - : PrimitiveTypeName(GetJavaType(field)); - } -} - + if (GetJavaType(field) == JAVATYPE_MESSAGE) { + return name_resolver->GetImmutableClassName(field->message_type()); + } else if (GetJavaType(field) == JAVATYPE_ENUM) { + return name_resolver->GetImmutableClassName(field->enum_type()); + } else { + return boxed ? BoxedPrimitiveTypeName(GetJavaType(field)) + : PrimitiveTypeName(GetJavaType(field)); + } +} + TProtoStringType KotlinTypeName(const FieldDescriptor* field, ClassNameResolver* name_resolver) { if (GetJavaType(field) == JAVATYPE_MESSAGE) { @@ -81,25 +81,25 @@ TProtoStringType KotlinTypeName(const FieldDescriptor* field, } TProtoStringType WireType(const FieldDescriptor* field) { - return "com.google.protobuf.WireFormat.FieldType." + + return "com.google.protobuf.WireFormat.FieldType." + TProtoStringType(FieldTypeName(field->type())); -} - +} + void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, - Context* context, + Context* context, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - ClassNameResolver* name_resolver = context->GetNameResolver(); - - (*variables)["type"] = - name_resolver->GetImmutableClassName(descriptor->message_type()); - const FieldDescriptor* key = KeyField(descriptor); - const FieldDescriptor* value = ValueField(descriptor); - const JavaType keyJavaType = GetJavaType(key); - const JavaType valueJavaType = GetJavaType(value); - - (*variables)["key_type"] = TypeName(key, name_resolver, false); + SetCommonFieldVariables(descriptor, info, variables); + ClassNameResolver* name_resolver = context->GetNameResolver(); + + (*variables)["type"] = + name_resolver->GetImmutableClassName(descriptor->message_type()); + const FieldDescriptor* key = KeyField(descriptor); + const FieldDescriptor* value = ValueField(descriptor); + const JavaType keyJavaType = GetJavaType(key); + const JavaType valueJavaType = GetJavaType(value); + + (*variables)["key_type"] = TypeName(key, name_resolver, false); TProtoStringType boxed_key_type = TypeName(key, name_resolver, true); (*variables)["boxed_key_type"] = boxed_key_type; (*variables)["kt_key_type"] = KotlinTypeName(key, name_resolver); @@ -107,8 +107,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, // Used for calling the serialization function. (*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_wire_type"] = WireType(key); + (*variables)["key_default_value"] = DefaultValue(key, true, name_resolver); (*variables)["key_null_check"] = IsReferenceType(keyJavaType) ? "if (key == null) { throw new java.lang.NullPointerException(); }" @@ -117,36 +117,36 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, IsReferenceType(valueJavaType) ? "if (value == null) { throw new java.lang.NullPointerException(); }" : ""; - if (valueJavaType == JAVATYPE_ENUM) { - // We store enums as Integers internally. - (*variables)["value_type"] = "int"; - (*variables)["boxed_value_type"] = "java.lang.Integer"; - (*variables)["value_wire_type"] = WireType(value); - (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver) + ".getNumber()"; - - (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); - - if (SupportUnknownEnumValue(descriptor->file())) { - // Map unknown values to a special UNRECOGNIZED value if supported. - (*variables)["unrecognized_value"] = - (*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); - } - } else { - (*variables)["value_type"] = TypeName(value, name_resolver, false); - (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); - (*variables)["value_wire_type"] = WireType(value); - (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver); - } - (*variables)["type_parameters"] = - (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"]; - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + if (valueJavaType == JAVATYPE_ENUM) { + // We store enums as Integers internally. + (*variables)["value_type"] = "int"; + (*variables)["boxed_value_type"] = "java.lang.Integer"; + (*variables)["value_wire_type"] = WireType(value); + (*variables)["value_default_value"] = + DefaultValue(value, true, name_resolver) + ".getNumber()"; + + (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); + + if (SupportUnknownEnumValue(descriptor->file())) { + // Map unknown values to a special UNRECOGNIZED value if supported. + (*variables)["unrecognized_value"] = + (*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); + } + } else { + (*variables)["value_type"] = TypeName(value, name_resolver, false); + (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); + (*variables)["value_wire_type"] = WireType(value); + (*variables)["value_default_value"] = + DefaultValue(value, true, name_resolver); + } + (*variables)["type_parameters"] = + (*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"] = @@ -154,53 +154,53 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, ? "@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)["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"] = + (*variables)["map_field_parameter"] = (*variables)["default_entry"]; + (*variables)["descriptor"] = name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" + UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, "; (*variables)["ver"] = GeneratedCodeVersionSuffix(); -} - -} // namespace - +} + +} // namespace + ImmutableMapFieldGenerator::ImmutableMapFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, + SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), context, &variables_); -} - +} + ImmutableMapFieldGenerator::~ImmutableMapFieldGenerator() {} - + int ImmutableMapFieldGenerator::GetNumBitsForMessage() const { return 0; } - + int ImmutableMapFieldGenerator::GetNumBitsForBuilder() const { return 1; } - + void ImmutableMapFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -209,55 +209,55 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" "${$get$capitalized_name$$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n" "${$get$capitalized_name$Map$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_enum_type$ defaultValue);\n"); + " $key_type$ key,\n" + " $value_enum_type$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" - " $key_type$ key);\n"); + " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "java.util.Map<$type_parameters$>\n" + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print( + variables_, + "/**\n" + " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$Value$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$ValueMap$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - } - } else { + } + } else { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -266,41 +266,41 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( "java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$Map$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - } -} - + } +} + void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const { - printer->Print( - variables_, - "private static final class $capitalized_name$DefaultEntryHolder {\n" - " static final com.google.protobuf.MapEntry<\n" - " $type_parameters$> defaultEntry =\n" - " com.google.protobuf.MapEntry\n" - " .<$type_parameters$>newDefaultInstance(\n" - " $descriptor$\n" - " $key_wire_type$,\n" - " $key_default_value$,\n" - " $value_wire_type$,\n" - " $value_default_value$);\n" - "}\n"); + printer->Print( + variables_, + "private static final class $capitalized_name$DefaultEntryHolder {\n" + " static final com.google.protobuf.MapEntry<\n" + " $type_parameters$> defaultEntry =\n" + " com.google.protobuf.MapEntry\n" + " .<$type_parameters$>newDefaultInstance(\n" + " $descriptor$\n" + " $key_wire_type$,\n" + " $key_default_value$,\n" + " $value_wire_type$,\n" + " $value_default_value$);\n" + "}\n"); printer->Print(variables_, "private com.google.protobuf.MapField<\n" " $type_parameters$> $name$_;\n" @@ -312,15 +312,15 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const { " }\n" " return $name$_;\n" "}\n"); - if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { - printer->Print( - variables_, - "private static final\n" - "com.google.protobuf.Internal.MapAdapter.Converter<\n" - " java.lang.Integer, $value_enum_type$> $name$ValueConverter =\n" - " com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n" - " $value_enum_type$.internalGetValueMap(),\n" - " $unrecognized_value$);\n"); + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + printer->Print( + variables_, + "private static final\n" + "com.google.protobuf.Internal.MapAdapter.Converter<\n" + " java.lang.Integer, $value_enum_type$> $name$ValueConverter =\n" + " com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n" + " $value_enum_type$.internalGetValueMap(),\n" + " $unrecognized_value$);\n"); printer->Print( variables_, "private static final java.util.Map<$boxed_key_type$, " @@ -331,10 +331,10 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const { " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n" " map, $name$ValueConverter);\n" "}\n"); - } - GenerateMapGetters(printer); -} - + } + GenerateMapGetters(printer); +} + void ImmutableMapFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { printer->Print(variables_, @@ -360,7 +360,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " }\n" " return $name$_;\n" "}\n"); - GenerateMapGetters(printer); + GenerateMapGetters(printer); printer->Print(variables_, "$deprecation$\n" "public Builder ${$clear$capitalized_name$$}$() {\n" @@ -369,7 +369,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "public Builder ${$remove$capitalized_name$$}$(\n" @@ -380,20 +380,20 @@ 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" + 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"); + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public Builder ${$put$capitalized_name$$}$(\n" " $key_type$ key,\n" @@ -405,65 +405,65 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n" - " java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n" + " java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n" " internalGetAdapted$capitalized_name$Map(\n" " internalGetMutable$capitalized_name$().getMutableMap())\n" " .putAll(values);\n" - " return this;\n" - "}\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" + 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"); + " return internalGetMutable$capitalized_name$().getMutableMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$public Builder ${$put$capitalized_name$Value$}$(\n" - " $key_type$ key,\n" - " $value_type$ value) {\n" - " $key_null_check$\n" + " $key_type$ key,\n" + " $value_type$ value) {\n" + " $key_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, value);\n" - " return this;\n" - "}\n"); + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$public Builder ${$putAll$capitalized_name$Value$}$(\n" - " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .putAll(values);\n" - " return this;\n" - "}\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" + } + } 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"); + " return internalGetMutable$capitalized_name$().getMutableMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$" "public Builder ${$put$capitalized_name$$}$(\n" @@ -476,7 +476,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "public Builder ${$putAll$capitalized_name$$}$(\n" @@ -486,9 +486,9 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } -} - + } +} + void ImmutableMapFieldGenerator::GenerateMapGetters( io::Printer* printer) const { printer->Print(variables_, @@ -497,18 +497,18 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " return internalGet$capitalized_name$().getMap().size();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "$deprecation$\n" + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "$deprecation$\n" "@java.lang.Override\n" "public boolean ${$contains$capitalized_name$$}$(\n" - " $key_type$ key) {\n" - " $key_null_check$\n" - " return internalGet$capitalized_name$().getMap().containsKey(key);\n" - "}\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) { + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -520,7 +520,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " return get$capitalized_name$Map();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -530,93 +530,93 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " internalGet$capitalized_name$().getMap());" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_enum_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" - " internalGet$capitalized_name$().getMap();\n" - " return map.containsKey(key)\n" - " ? $name$ValueConverter.doForward(map.get(key))\n" - " : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_enum_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " internalGet$capitalized_name$().getMap();\n" + " return map.containsKey(key)\n" + " ? $name$ValueConverter.doForward(map.get(key))\n" + " : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "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" - " internalGet$capitalized_name$().getMap();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return $name$ValueConverter.doForward(map.get(key));\n" - "}\n"); + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " internalGet$capitalized_name$().getMap();\n" + " if (!map.containsKey(key)) {\n" + " throw new java.lang.IllegalArgumentException();\n" + " }\n" + " return $name$ValueConverter.doForward(map.get(key));\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" - " */\n" + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print( + variables_, + "/**\n" + " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" + " */\n" "@java.lang.Override\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" "${$get$capitalized_name$Value$}$() {\n" - " return get$capitalized_name$ValueMap();\n" - "}\n"); + " return get$capitalized_name$ValueMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\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"); + " return internalGet$capitalized_name$().getMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" - " $key_type$ key,\n" - " $value_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" - " internalGet$capitalized_name$().getMap();\n" - " return map.containsKey(key) ? map.get(key) : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " internalGet$capitalized_name$().getMap();\n" + " return map.containsKey(key) ? map.get(key) : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "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" - " internalGet$capitalized_name$().getMap();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return map.get(key);\n" - "}\n"); + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> 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_); - } - } else { + } + } else { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -628,7 +628,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " return get$capitalized_name$Map();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -637,21 +637,21 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " return internalGet$capitalized_name$().getMap();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$type_parameters$> map =\n" - " internalGet$capitalized_name$().getMap();\n" - " return map.containsKey(key) ? map.get(key) : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$type_parameters$> map =\n" + " internalGet$capitalized_name$().getMap();\n" + " return map.containsKey(key) ? map.get(key) : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -666,9 +666,9 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " return map.get(key);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } -} - + } +} + void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -752,34 +752,34 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( void ImmutableMapFieldGenerator::GenerateFieldBuilderInitializationCode( io::Printer* printer) const { - // Nothing to initialize. -} - + // Nothing to initialize. +} + void ImmutableMapFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { - // Nothing to initialize. -} - + // Nothing to initialize. +} + void ImmutableMapFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { printer->Print(variables_, "internalGetMutable$capitalized_name$().clear();\n"); -} - +} + void ImmutableMapFieldGenerator::GenerateMergingCode( io::Printer* printer) const { printer->Print(variables_, "internalGetMutable$capitalized_name$().mergeFrom(\n" " other.internalGet$capitalized_name$());\n"); -} - +} + void ImmutableMapFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { printer->Print(variables_, "result.$name$_ = internalGet$capitalized_name$();\n" "result.$name$_.makeImmutable();\n"); -} - +} + void ImmutableMapFieldGenerator::GenerateParsingCode( io::Printer* printer) const { printer->Print(variables_, @@ -788,37 +788,37 @@ void ImmutableMapFieldGenerator::GenerateParsingCode( " $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" + 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_, + printer->Print( + variables_, "if ($value_enum_type$.forNumber($name$__.getValue()) == null) {\n" - " unknownFields.mergeLengthDelimitedField($number$, bytes);\n" - "} else {\n" + " unknownFields.mergeLengthDelimitedField($number$, bytes);\n" + "} else {\n" " $name$_.getMutableMap().put(\n" " $name$__.getKey(), $name$__.getValue());\n" - "}\n"); - } else { - printer->Print( - variables_, - "com.google.protobuf.MapEntry<$type_parameters$>\n" + "}\n"); + } else { + printer->Print( + variables_, + "com.google.protobuf.MapEntry<$type_parameters$>\n" "$name$__ = input.readMessage(\n" - " $default_entry$.getParserForType(), extensionRegistry);\n" + " $default_entry$.getParserForType(), extensionRegistry);\n" "$name$_.getMutableMap().put(\n" " $name$__.getKey(), $name$__.getValue());\n"); - } -} - + } +} + void ImmutableMapFieldGenerator::GenerateParsingDoneCode( io::Printer* printer) const { - // Nothing to do here. -} - + // Nothing to do here. +} + void ImmutableMapFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { printer->Print(variables_, @@ -828,45 +828,45 @@ void ImmutableMapFieldGenerator::GenerateSerializationCode( " internalGet$capitalized_name$(),\n" " $default_entry$,\n" " $number$);\n"); -} - +} + void ImmutableMapFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print( - variables_, - "for (java.util.Map.Entry<$type_parameters$> entry\n" - " : internalGet$capitalized_name$().getMap().entrySet()) {\n" - " com.google.protobuf.MapEntry<$type_parameters$>\n" + printer->Print( + variables_, + "for (java.util.Map.Entry<$type_parameters$> entry\n" + " : internalGet$capitalized_name$().getMap().entrySet()) {\n" + " com.google.protobuf.MapEntry<$type_parameters$>\n" " $name$__ = $default_entry$.newBuilderForType()\n" - " .setKey(entry.getKey())\n" - " .setValue(entry.getValue())\n" - " .build();\n" - " size += com.google.protobuf.CodedOutputStream\n" + " .setKey(entry.getKey())\n" + " .setValue(entry.getValue())\n" + " .build();\n" + " size += com.google.protobuf.CodedOutputStream\n" " .computeMessageSize($number$, $name$__);\n" - "}\n"); -} - + "}\n"); +} + void ImmutableMapFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { printer->Print(variables_, "if (!internalGet$capitalized_name$().equals(\n" " other.internalGet$capitalized_name$())) return false;\n"); -} - +} + void ImmutableMapFieldGenerator::GenerateHashCode(io::Printer* printer) const { - printer->Print( - variables_, - "if (!internalGet$capitalized_name$().getMap().isEmpty()) {\n" - " hash = (37 * hash) + $constant_name$;\n" - " hash = (53 * hash) + internalGet$capitalized_name$().hashCode();\n" - "}\n"); -} - + printer->Print( + variables_, + "if (!internalGet$capitalized_name$().getMap().isEmpty()) {\n" + " hash = (37 * hash) + $constant_name$;\n" + " hash = (53 * hash) + internalGet$capitalized_name$().hashCode();\n" + "}\n"); +} + TProtoStringType ImmutableMapFieldGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->message_type()); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return name_resolver_->GetImmutableClassName(descriptor_->message_type()); +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.h index d4bfbfe132..43de92ef0f 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field.h @@ -1,51 +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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__ - +// 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_MAP_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__ + #include <google/protobuf/compiler/java/java_field.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { - public: + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { + public: explicit ImmutableMapFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); ~ImmutableMapFieldGenerator() override; - - // implements ImmutableFieldGenerator --------------------------------------- + + // implements ImmutableFieldGenerator --------------------------------------- int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -64,19 +64,19 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const override; void GenerateHashCode(io::Printer* printer) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; + + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - void GenerateMapGetters(io::Printer* printer) const; -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; + void GenerateMapGetters(io::Printer* printer) const; +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.cc index 79bd924701..2a1ed335b1 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.cc @@ -1,35 +1,35 @@ -// 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. - +// 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/java_map_field_lite.h> - + #include <cstdint> #include <google/protobuf/compiler/java/java_context.h> @@ -37,40 +37,40 @@ #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/io/printer.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { - -const FieldDescriptor* KeyField(const FieldDescriptor* descriptor) { - GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); - const Descriptor* message = descriptor->message_type(); - GOOGLE_CHECK(message->options().map_entry()); - return message->FindFieldByName("key"); -} - -const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) { - GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); - const Descriptor* message = descriptor->message_type(); - GOOGLE_CHECK(message->options().map_entry()); - return message->FindFieldByName("value"); -} - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { + +const FieldDescriptor* KeyField(const FieldDescriptor* descriptor) { + GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); + const Descriptor* message = descriptor->message_type(); + GOOGLE_CHECK(message->options().map_entry()); + return message->FindFieldByName("key"); +} + +const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) { + GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, descriptor->type()); + const Descriptor* message = descriptor->message_type(); + GOOGLE_CHECK(message->options().map_entry()); + return message->FindFieldByName("value"); +} + TProtoStringType TypeName(const FieldDescriptor* field, ClassNameResolver* name_resolver, bool boxed) { - if (GetJavaType(field) == JAVATYPE_MESSAGE) { - return name_resolver->GetImmutableClassName(field->message_type()); - } else if (GetJavaType(field) == JAVATYPE_ENUM) { - return name_resolver->GetImmutableClassName(field->enum_type()); - } else { - return boxed ? BoxedPrimitiveTypeName(GetJavaType(field)) - : PrimitiveTypeName(GetJavaType(field)); - } -} - + if (GetJavaType(field) == JAVATYPE_MESSAGE) { + return name_resolver->GetImmutableClassName(field->message_type()); + } else if (GetJavaType(field) == JAVATYPE_ENUM) { + return name_resolver->GetImmutableClassName(field->enum_type()); + } else { + return boxed ? BoxedPrimitiveTypeName(GetJavaType(field)) + : PrimitiveTypeName(GetJavaType(field)); + } +} + TProtoStringType KotlinTypeName(const FieldDescriptor* field, ClassNameResolver* name_resolver) { if (GetJavaType(field) == JAVATYPE_MESSAGE) { @@ -83,30 +83,30 @@ TProtoStringType KotlinTypeName(const FieldDescriptor* field, } TProtoStringType WireType(const FieldDescriptor* field) { - return "com.google.protobuf.WireFormat.FieldType." + + return "com.google.protobuf.WireFormat.FieldType." + TProtoStringType(FieldTypeName(field->type())); -} - +} + void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, - Context* context, + Context* context, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - - ClassNameResolver* name_resolver = context->GetNameResolver(); - (*variables)["type"] = - name_resolver->GetImmutableClassName(descriptor->message_type()); - const FieldDescriptor* key = KeyField(descriptor); - const FieldDescriptor* value = ValueField(descriptor); - const JavaType keyJavaType = GetJavaType(key); - const JavaType valueJavaType = GetJavaType(value); - - (*variables)["key_type"] = TypeName(key, name_resolver, false); - (*variables)["boxed_key_type"] = TypeName(key, name_resolver, true); + SetCommonFieldVariables(descriptor, info, variables); + + ClassNameResolver* name_resolver = context->GetNameResolver(); + (*variables)["type"] = + name_resolver->GetImmutableClassName(descriptor->message_type()); + const FieldDescriptor* key = KeyField(descriptor); + const FieldDescriptor* value = ValueField(descriptor); + const JavaType keyJavaType = GetJavaType(key); + const JavaType valueJavaType = GetJavaType(value); + + (*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_wire_type"] = WireType(key); + (*variables)["key_default_value"] = DefaultValue(key, true, name_resolver); // We use `x.getClass()` as a null check because it generates less bytecode // than an `if (x == null) { throw ... }` statement. (*variables)["key_null_check"] = @@ -117,37 +117,37 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, IsReferenceType(valueJavaType) ? "java.lang.Class<?> valueClass = value.getClass();" : ""; - - if (GetJavaType(value) == JAVATYPE_ENUM) { - // We store enums as Integers internally. - (*variables)["value_type"] = "int"; - (*variables)["boxed_value_type"] = "java.lang.Integer"; - (*variables)["value_wire_type"] = WireType(value); - (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver) + ".getNumber()"; - - (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); - - if (SupportUnknownEnumValue(descriptor->file())) { - // Map unknown values to a special UNRECOGNIZED value if supported. - (*variables)["unrecognized_value"] = - (*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); - } - } else { - (*variables)["value_type"] = TypeName(value, name_resolver, false); - (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); - (*variables)["value_wire_type"] = WireType(value); - (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver); - } - (*variables)["type_parameters"] = - (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"]; - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + + if (GetJavaType(value) == JAVATYPE_ENUM) { + // We store enums as Integers internally. + (*variables)["value_type"] = "int"; + (*variables)["boxed_value_type"] = "java.lang.Integer"; + (*variables)["value_wire_type"] = WireType(value); + (*variables)["value_default_value"] = + DefaultValue(value, true, name_resolver) + ".getNumber()"; + + (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); + + if (SupportUnknownEnumValue(descriptor->file())) { + // Map unknown values to a special UNRECOGNIZED value if supported. + (*variables)["unrecognized_value"] = + (*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); + } + } else { + (*variables)["value_type"] = TypeName(value, name_resolver, false); + (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); + (*variables)["value_wire_type"] = WireType(value); + (*variables)["value_default_value"] = + DefaultValue(value, true, name_resolver); + } + (*variables)["type_parameters"] = + (*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"] = @@ -155,13 +155,13 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + " is deprecated\") " : ""; - + (*variables)["default_entry"] = (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry"; -} - -} // namespace - +} + +} // namespace + ImmutableMapFieldLiteGenerator::ImmutableMapFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), @@ -170,24 +170,24 @@ ImmutableMapFieldLiteGenerator::ImmutableMapFieldLiteGenerator( SetMessageVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), context, &variables_); -} - +} + ImmutableMapFieldLiteGenerator::~ImmutableMapFieldLiteGenerator() {} - + int ImmutableMapFieldLiteGenerator::GetNumBitsForMessage() const { return 0; } - + void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -196,55 +196,55 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers( "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" "${$get$capitalized_name$$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n" "${$get$capitalized_name$Map$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_enum_type$ defaultValue);\n"); + " $key_type$ key,\n" + " $value_enum_type$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" - " $key_type$ key);\n"); + " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "java.util.Map<$type_parameters$>\n" + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print( + variables_, + "/**\n" + " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$Value$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$ValueMap$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - } - } else { + } + } else { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -253,41 +253,41 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers( "java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$java.util.Map<$type_parameters$>\n" "${$get$capitalized_name$Map$}$();\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - } -} - + } +} + void ImmutableMapFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - printer->Print( - variables_, - "private static final class $capitalized_name$DefaultEntryHolder {\n" - " static final com.google.protobuf.MapEntryLite<\n" - " $type_parameters$> defaultEntry =\n" - " com.google.protobuf.MapEntryLite\n" - " .<$type_parameters$>newDefaultInstance(\n" - " $key_wire_type$,\n" - " $key_default_value$,\n" - " $value_wire_type$,\n" - " $value_default_value$);\n" - "}\n"); + printer->Print( + variables_, + "private static final class $capitalized_name$DefaultEntryHolder {\n" + " static final com.google.protobuf.MapEntryLite<\n" + " $type_parameters$> defaultEntry =\n" + " com.google.protobuf.MapEntryLite\n" + " .<$type_parameters$>newDefaultInstance(\n" + " $key_wire_type$,\n" + " $key_default_value$,\n" + " $value_wire_type$,\n" + " $value_default_value$);\n" + "}\n"); printer->Print(variables_, "private com.google.protobuf.MapFieldLite<\n" " $type_parameters$> $name$_ =\n" @@ -310,7 +310,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " return internalGet$capitalized_name$().size();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -320,15 +320,15 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " return internalGet$capitalized_name$().containsKey(key);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { - printer->Print( - variables_, - "private static final\n" - "com.google.protobuf.Internal.MapAdapter.Converter<\n" - " java.lang.Integer, $value_enum_type$> $name$ValueConverter =\n" - " com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n" - " $value_enum_type$.internalGetValueMap(),\n" - " $unrecognized_value$);\n"); + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + printer->Print( + variables_, + "private static final\n" + "com.google.protobuf.Internal.MapAdapter.Converter<\n" + " java.lang.Integer, $value_enum_type$> $name$ValueConverter =\n" + " 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" @@ -339,108 +339,108 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " return get$capitalized_name$Map();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "$deprecation$\n" + "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" "${$get$capitalized_name$Map$}$() {\n" - " return java.util.Collections.unmodifiableMap(\n" - " new com.google.protobuf.Internal.MapAdapter<\n" - " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n" - " internalGet$capitalized_name$(),\n" - " $name$ValueConverter));\n" - "}\n"); + " return java.util.Collections.unmodifiableMap(\n" + " new com.google.protobuf.Internal.MapAdapter<\n" + " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n" + " internalGet$capitalized_name$(),\n" + " $name$ValueConverter));\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_enum_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" - " internalGet$capitalized_name$();\n" - " return map.containsKey(key)\n" - " ? $name$ValueConverter.doForward(map.get(key))\n" - " : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_enum_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " internalGet$capitalized_name$();\n" + " return map.containsKey(key)\n" + " ? $name$ValueConverter.doForward(map.get(key))\n" + " : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "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" - " internalGet$capitalized_name$();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return $name$ValueConverter.doForward(map.get(key));\n" - "}\n"); + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " internalGet$capitalized_name$();\n" + " if (!map.containsKey(key)) {\n" + " throw new java.lang.IllegalArgumentException();\n" + " }\n" + " return $name$ValueConverter.doForward(map.get(key));\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" - " */\n" + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print( + variables_, + "/**\n" + " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" + " */\n" "@java.lang.Override\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" "${$get$capitalized_name$Value$}$() {\n" - " return get$capitalized_name$ValueMap();\n" - "}\n"); + " return get$capitalized_name$ValueMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" + "$deprecation$\n" + "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" "${$get$capitalized_name$ValueMap$}$() {\n" - " return java.util.Collections.unmodifiableMap(\n" - " internalGet$capitalized_name$());\n" - "}\n"); + " return java.util.Collections.unmodifiableMap(\n" + " internalGet$capitalized_name$());\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" - " $key_type$ key,\n" - " $value_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" - " internalGet$capitalized_name$();\n" - " return map.containsKey(key) ? map.get(key) : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " internalGet$capitalized_name$();\n" + " return map.containsKey(key) ? map.get(key) : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "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" - " internalGet$capitalized_name$();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return map.get(key);\n" - "}\n"); + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " internalGet$capitalized_name$();\n" + " if (!map.containsKey(key)) {\n" + " throw new java.lang.IllegalArgumentException();\n" + " }\n" + " return map.get(key);\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - } - } else { + } + } else { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -452,7 +452,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " return get$capitalized_name$Map();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -462,21 +462,21 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " internalGet$capitalized_name$());\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$type_parameters$> map =\n" - " internalGet$capitalized_name$();\n" - " return map.containsKey(key) ? map.get(key) : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$type_parameters$> map =\n" + " internalGet$capitalized_name$();\n" + " return map.containsKey(key) ? map.get(key) : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -491,39 +491,39 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " return map.get(key);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - - // Generate private setters for the builder to proxy into. - if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "private java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "getMutable$capitalized_name$Map() {\n" - " return new com.google.protobuf.Internal.MapAdapter<\n" - " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n" - " internalGetMutable$capitalized_name$(),\n" - " $name$ValueConverter);\n" - "}\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "private java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "getMutable$capitalized_name$ValueMap() {\n" - " return internalGetMutable$capitalized_name$();\n" - "}\n"); - } - } else { - WriteFieldDocComment(printer, descriptor_); + } + + // Generate private setters for the builder to proxy into. + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "private java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "getMutable$capitalized_name$Map() {\n" + " return new com.google.protobuf.Internal.MapAdapter<\n" + " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n" + " internalGetMutable$capitalized_name$(),\n" + " $name$ValueConverter);\n" + "}\n"); + if (SupportUnknownEnumValue(descriptor_->file())) { + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "private java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" + "getMutable$capitalized_name$ValueMap() {\n" + " return internalGetMutable$capitalized_name$();\n" + "}\n"); + } + } else { + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "private java.util.Map<$type_parameters$>\n" "getMutable$capitalized_name$Map() {\n" " return internalGetMutable$capitalized_name$();\n" "}\n"); - } -} - + } +} + void ImmutableMapFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); @@ -550,16 +550,16 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " return instance.get$capitalized_name$Map().size();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public boolean ${$contains$capitalized_name$$}$(\n" - " $key_type$ key) {\n" - " $key_null_check$\n" - " return instance.get$capitalized_name$Map().containsKey(key);\n" - "}\n"); + " $key_type$ key) {\n" + " $key_null_check$\n" + " return instance.get$capitalized_name$Map().containsKey(key);\n" + "}\n"); printer->Annotate("{", "}", descriptor_); printer->Print(variables_, "$deprecation$\n" @@ -569,7 +569,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" "public Builder ${$remove$capitalized_name$$}$(\n" @@ -580,7 +580,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -591,7 +591,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " return get$capitalized_name$Map();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -601,139 +601,139 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " instance.get$capitalized_name$Map());\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_enum_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$boxed_key_type$, $value_enum_type$> map =\n" - " instance.get$capitalized_name$Map();\n" - " return map.containsKey(key)\n" - " ? map.get(key)\n" - " : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_enum_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $value_enum_type$> map =\n" + " instance.get$capitalized_name$Map();\n" + " return map.containsKey(key)\n" + " ? map.get(key)\n" + " : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" - " $key_type$ key) {\n" - " $key_null_check$\n" - " java.util.Map<$boxed_key_type$, $value_enum_type$> map =\n" - " instance.get$capitalized_name$Map();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return map.get(key);\n" - "}\n"); + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $value_enum_type$> map =\n" + " instance.get$capitalized_name$Map();\n" + " if (!map.containsKey(key)) {\n" + " throw new java.lang.IllegalArgumentException();\n" + " }\n" + " return map.get(key);\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$public Builder ${$put$capitalized_name$$}$(\n" - " $key_type$ key,\n" - " $value_enum_type$ value) {\n" - " $key_null_check$\n" - " $value_null_check$\n" - " copyOnWrite();\n" - " instance.getMutable$capitalized_name$Map().put(key, value);\n" - " return this;\n" - "}\n"); + " $key_type$ key,\n" + " $value_enum_type$ value) {\n" + " $key_null_check$\n" + " $value_null_check$\n" + " copyOnWrite();\n" + " instance.getMutable$capitalized_name$Map().put(key, value);\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n" - " java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n" - " copyOnWrite();\n" - " instance.getMutable$capitalized_name$Map().putAll(values);\n" - " return this;\n" - "}\n"); + " java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n" + " copyOnWrite();\n" + " instance.getMutable$capitalized_name$Map().putAll(values);\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" - " */\n" + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print( + variables_, + "/**\n" + " * Use {@link #get$capitalized_name$ValueMap()} instead.\n" + " */\n" "@java.lang.Override\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" "${$get$capitalized_name$Value$}$() {\n" - " return get$capitalized_name$ValueMap();\n" - "}\n"); + " return get$capitalized_name$ValueMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" + "$deprecation$\n" + "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" "${$get$capitalized_name$ValueMap$}$() {\n" - " return java.util.Collections.unmodifiableMap(\n" - " instance.get$capitalized_name$ValueMap());\n" - "}\n"); + " return java.util.Collections.unmodifiableMap(\n" + " instance.get$capitalized_name$ValueMap());\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" - " $key_type$ key,\n" - " $value_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" - " instance.get$capitalized_name$ValueMap();\n" - " return map.containsKey(key) ? map.get(key) : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " instance.get$capitalized_name$ValueMap();\n" + " return map.containsKey(key) ? map.get(key) : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "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" - " instance.get$capitalized_name$ValueMap();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return map.get(key);\n" - "}\n"); + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" + " instance.get$capitalized_name$ValueMap();\n" + " if (!map.containsKey(key)) {\n" + " throw new java.lang.IllegalArgumentException();\n" + " }\n" + " return map.get(key);\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$public Builder ${$put$capitalized_name$Value$}$(\n" - " $key_type$ key,\n" - " $value_type$ value) {\n" - " $key_null_check$\n" - " copyOnWrite();\n" - " instance.getMutable$capitalized_name$ValueMap().put(key, value);\n" - " return this;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ value) {\n" + " $key_null_check$\n" + " copyOnWrite();\n" + " instance.getMutable$capitalized_name$ValueMap().put(key, value);\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "$deprecation$public Builder ${$putAll$capitalized_name$Value$}$(\n" - " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" - " copyOnWrite();\n" - " instance.getMutable$capitalized_name$ValueMap().putAll(values);\n" - " return this;\n" - "}\n"); + " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" + " copyOnWrite();\n" + " instance.getMutable$capitalized_name$ValueMap().putAll(values);\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - } - } else { + } + } else { printer->Print(variables_, "/**\n" " * Use {@link #get$capitalized_name$Map()} instead.\n" @@ -745,7 +745,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " return get$capitalized_name$Map();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$" @@ -755,21 +755,21 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " instance.get$capitalized_name$Map());\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, "@java.lang.Override\n" - "$deprecation$\n" + "$deprecation$\n" "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" - " $key_type$ key,\n" - " $value_type$ defaultValue) {\n" - " $key_null_check$\n" - " java.util.Map<$type_parameters$> map =\n" - " instance.get$capitalized_name$Map();\n" - " return map.containsKey(key) ? map.get(key) : defaultValue;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ defaultValue) {\n" + " $key_null_check$\n" + " java.util.Map<$type_parameters$> map =\n" + " instance.get$capitalized_name$Map();\n" + " return map.containsKey(key) ? map.get(key) : defaultValue;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" "$deprecation$\n" @@ -784,34 +784,34 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " return map.get(key);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "$deprecation$" + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "$deprecation$" "public Builder ${$put$capitalized_name$$}$(\n" - " $key_type$ key,\n" - " $value_type$ value) {\n" - " $key_null_check$\n" - " $value_null_check$\n" - " copyOnWrite();\n" - " instance.getMutable$capitalized_name$Map().put(key, value);\n" - " return this;\n" - "}\n"); + " $key_type$ key,\n" + " $value_type$ value) {\n" + " $key_null_check$\n" + " $value_null_check$\n" + " copyOnWrite();\n" + " instance.getMutable$capitalized_name$Map().put(key, value);\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "$deprecation$" + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "$deprecation$" "public Builder ${$putAll$capitalized_name$$}$(\n" - " java.util.Map<$type_parameters$> values) {\n" - " copyOnWrite();\n" - " instance.getMutable$capitalized_name$Map().putAll(values);\n" - " return this;\n" - "}\n"); + " java.util.Map<$type_parameters$> values) {\n" + " copyOnWrite();\n" + " instance.getMutable$capitalized_name$Map().putAll(values);\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); - } -} - + } +} + void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -895,14 +895,14 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( void ImmutableMapFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - // Nothing to initialize. -} - + // Nothing to initialize. +} + TProtoStringType ImmutableMapFieldLiteGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->message_type()); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return name_resolver_->GetImmutableClassName(descriptor_->message_type()); +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.h index f2773f5b35..2672f548c8 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_map_field_lite.h @@ -1,53 +1,53 @@ -// 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_MAP_FIELD_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ - +// 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_MAP_FIELD_LITE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ + #include <cstdint> #include <google/protobuf/compiler/java/java_field.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { - public: + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { + public: explicit ImmutableMapFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~ImmutableMapFieldLiteGenerator() override; - - // implements ImmutableFieldLiteGenerator ------------------------------------ + + // implements ImmutableFieldLiteGenerator ------------------------------------ int GetNumBitsForMessage() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; void GenerateMembers(io::Printer* printer) const override; @@ -56,19 +56,19 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - private: - const FieldDescriptor* descriptor_; + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; Context* context_; - ClassNameResolver* name_resolver_; -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc index 029d886cde..a2d6fc0a4a 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.cc @@ -1,45 +1,45 @@ -// 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. - +// 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/java_message.h> - -#include <algorithm> + +#include <algorithm> #include <cstdint> -#include <map> -#include <memory> -#include <vector> - +#include <map> +#include <memory> +#include <vector> + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_enum.h> @@ -55,27 +55,27 @@ #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -using internal::WireFormat; -using internal::WireFormatLite; - -namespace { + +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->FindFieldByName("value"); - GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type()); - return name_resolver->GetImmutableClassName(value_field->message_type()); -} -} // namespace - -// =================================================================== - -MessageGenerator::MessageGenerator(const Descriptor* descriptor) + const FieldDescriptor* value_field = descriptor->FindFieldByName("value"); + GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type()); + return name_resolver->GetImmutableClassName(value_field->message_type()); +} +} // namespace + +// =================================================================== + +MessageGenerator::MessageGenerator(const Descriptor* descriptor) : descriptor_(descriptor) { for (int i = 0; i < descriptor_->field_count(); i++) { if (IsRealOneof(descriptor_->field(i))) { @@ -83,53 +83,53 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor) } } } - -MessageGenerator::~MessageGenerator() {} - -// =================================================================== -ImmutableMessageGenerator::ImmutableMessageGenerator( - const Descriptor* descriptor, Context* context) + +MessageGenerator::~MessageGenerator() {} + +// =================================================================== +ImmutableMessageGenerator::ImmutableMessageGenerator( + const Descriptor* descriptor, Context* context) : MessageGenerator(descriptor), context_(context), name_resolver_(context->GetNameResolver()), field_generators_(descriptor, context_) { - GOOGLE_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite())) - << "Generator factory error: A non-lite message generator is used to " - "generate lite messages."; -} - -ImmutableMessageGenerator::~ImmutableMessageGenerator() {} - -void ImmutableMessageGenerator::GenerateStaticVariables( - io::Printer* printer, int* bytecode_estimate) { - // Because descriptor.proto (com.google.protobuf.DescriptorProtos) is - // used in the construction of descriptors, we have a tricky bootstrapping - // problem. To help control static initialization order, we make sure all - // descriptors and other static data that depends on them are members of - // the outermost class in the file. This way, they will be initialized in - // a deterministic order. - + GOOGLE_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite())) + << "Generator factory error: A non-lite message generator is used to " + "generate lite messages."; +} + +ImmutableMessageGenerator::~ImmutableMessageGenerator() {} + +void ImmutableMessageGenerator::GenerateStaticVariables( + io::Printer* printer, int* bytecode_estimate) { + // Because descriptor.proto (com.google.protobuf.DescriptorProtos) is + // used in the construction of descriptors, we have a tricky bootstrapping + // problem. To help control static initialization order, we make sure all + // descriptors and other static data that depends on them are members of + // the outermost class in the file. This way, they will be initialized in + // a deterministic order. + std::map<TProtoStringType, TProtoStringType> vars; - vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); + vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["index"] = StrCat(descriptor_->index()); - vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); - if (descriptor_->containing_type() != NULL) { + vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); + if (descriptor_->containing_type() != NULL) { vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type()); - } - if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { - // We can only make these package-private since the classes that use them - // are in separate files. - vars["private"] = ""; - } else { - vars["private"] = "private "; - } - if (*bytecode_estimate <= kMaxStaticSize) { - vars["final"] = "final "; - } else { - vars["final"] = ""; - } - - // The descriptor for this type. + } + if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { + // We can only make these package-private since the classes that use them + // are in separate files. + vars["private"] = ""; + } else { + vars["private"] = "private "; + } + if (*bytecode_estimate <= kMaxStaticSize) { + vars["final"] = "final "; + } else { + vars["final"] = ""; + } + + // The descriptor for this type. printer->Print( vars, // TODO(teboring): final needs to be added back. The way to fix it is to @@ -137,94 +137,94 @@ void ImmutableMessageGenerator::GenerateStaticVariables( // the types, and then init them in clinit with the new method calls. "$private$static $final$com.google.protobuf.Descriptors.Descriptor\n" " internal_$identifier$_descriptor;\n"); - *bytecode_estimate += 30; - - // And the FieldAccessorTable. - GenerateFieldAccessorTable(printer, bytecode_estimate); - - // Generate static members for all nested types. - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // TODO(kenton): Reuse MessageGenerator objects? - ImmutableMessageGenerator(descriptor_->nested_type(i), context_) - .GenerateStaticVariables(printer, bytecode_estimate); - } -} - -int ImmutableMessageGenerator::GenerateStaticVariableInitializers( - io::Printer* printer) { - int bytecode_estimate = 0; + *bytecode_estimate += 30; + + // And the FieldAccessorTable. + GenerateFieldAccessorTable(printer, bytecode_estimate); + + // Generate static members for all nested types. + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + // TODO(kenton): Reuse MessageGenerator objects? + ImmutableMessageGenerator(descriptor_->nested_type(i), context_) + .GenerateStaticVariables(printer, bytecode_estimate); + } +} + +int ImmutableMessageGenerator::GenerateStaticVariableInitializers( + io::Printer* printer) { + int bytecode_estimate = 0; std::map<TProtoStringType, TProtoStringType> vars; - vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); + vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["index"] = StrCat(descriptor_->index()); - vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); - if (descriptor_->containing_type() != NULL) { + vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); + if (descriptor_->containing_type() != NULL) { vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type()); - } - - // The descriptor for this type. - if (descriptor_->containing_type() == NULL) { - printer->Print(vars, + } + + // The descriptor for this type. + if (descriptor_->containing_type() == NULL) { + printer->Print(vars, "internal_$identifier$_descriptor =\n" " getDescriptor().getMessageTypes().get($index$);\n"); - bytecode_estimate += 30; - } else { + bytecode_estimate += 30; + } else { printer->Print( vars, "internal_$identifier$_descriptor =\n" " internal_$parent$_descriptor.getNestedTypes().get($index$);\n"); - bytecode_estimate += 30; - } - - // And the FieldAccessorTable. - bytecode_estimate += GenerateFieldAccessorTableInitializer(printer); - - // Generate static member initializers for all nested types. - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // TODO(kenton): Reuse MessageGenerator objects? - bytecode_estimate += - ImmutableMessageGenerator(descriptor_->nested_type(i), context_) - .GenerateStaticVariableInitializers(printer); - } - return bytecode_estimate; -} - + bytecode_estimate += 30; + } + + // And the FieldAccessorTable. + bytecode_estimate += GenerateFieldAccessorTableInitializer(printer); + + // Generate static member initializers for all nested types. + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + // TODO(kenton): Reuse MessageGenerator objects? + bytecode_estimate += + ImmutableMessageGenerator(descriptor_->nested_type(i), context_) + .GenerateStaticVariableInitializers(printer); + } + return bytecode_estimate; +} + void ImmutableMessageGenerator::GenerateFieldAccessorTable( io::Printer* printer, int* bytecode_estimate) { std::map<TProtoStringType, 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 - // are in separate files. - vars["private"] = ""; - } else { - vars["private"] = "private "; - } - if (*bytecode_estimate <= kMaxStaticSize) { - vars["final"] = "final "; - } else { - vars["final"] = ""; - } - vars["ver"] = GeneratedCodeVersionSuffix(); + vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); + if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { + // We can only make these package-private since the classes that use them + // are in separate files. + vars["private"] = ""; + } else { + vars["private"] = "private "; + } + if (*bytecode_estimate <= kMaxStaticSize) { + vars["final"] = "final "; + } else { + vars["final"] = ""; + } + vars["ver"] = GeneratedCodeVersionSuffix(); printer->Print( vars, "$private$static $final$\n" " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" " internal_$identifier$_fieldAccessorTable;\n"); - + // The following bytecode_estimate calculation logic must stay in sync with // the similar logic in the GenerateFieldAccessorTableInitializer method below // to make sure that the generated static final fields are initialized in the // static initialization block directly. // - // 6 bytes per field and oneof + // 6 bytes per field and oneof *bytecode_estimate += 10 + 6 * descriptor_->field_count() + 6 * descriptor_->oneof_decl_count(); -} - +} + int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer( io::Printer* printer) { - int bytecode_estimate = 10; - printer->Print( + int bytecode_estimate = 10; + printer->Print( "internal_$identifier$_fieldAccessorTable = new\n" " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable(\n" " internal_$identifier$_descriptor,\n" @@ -235,52 +235,52 @@ int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer( // sync with the similar logic in the GenerateFieldAccessorTable method // above. See the corresponding comment in GenerateFieldAccessorTable for // details. - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - bytecode_estimate += 6; + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + bytecode_estimate += 6; printer->Print("\"$field_name$\", ", "field_name", info->capitalized_name); - } + } // We reproduce synthetic oneofs here since proto reflection needs these. - for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { - const OneofDescriptor* oneof = descriptor_->oneof_decl(i); - const OneofGeneratorInfo* info = context_->GetOneofGeneratorInfo(oneof); - bytecode_estimate += 6; + for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { + const OneofDescriptor* oneof = descriptor_->oneof_decl(i); + const OneofGeneratorInfo* info = context_->GetOneofGeneratorInfo(oneof); + bytecode_estimate += 6; printer->Print("\"$oneof_name$\", ", "oneof_name", info->capitalized_name); - } - printer->Print("});\n"); - return bytecode_estimate; -} - -// =================================================================== - -void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { - MaybePrintGeneratedAnnotation(context_, printer, descriptor_, - /* immutable = */ true, "OrBuilder"); - if (descriptor_->extension_range_count() > 0) { - printer->Print( + } + printer->Print("});\n"); + return bytecode_estimate; +} + +// =================================================================== + +void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { + MaybePrintGeneratedAnnotation(context_, printer, descriptor_, + /* immutable = */ true, "OrBuilder"); + if (descriptor_->extension_range_count() > 0) { + printer->Print( "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" - " $extra_interfaces$\n" - " com.google.protobuf.GeneratedMessage$ver$.\n" - " ExtendableMessageOrBuilder<$classname$> {\n", + " $extra_interfaces$\n" + " com.google.protobuf.GeneratedMessage$ver$.\n" + " ExtendableMessageOrBuilder<$classname$> {\n", "deprecation", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", - "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), + "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), "{", "", "}", "", "ver", GeneratedCodeVersionSuffix()); - } else { - printer->Print( + } else { + printer->Print( "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" - " $extra_interfaces$\n" - " com.google.protobuf.MessageOrBuilder {\n", + " $extra_interfaces$\n" + " com.google.protobuf.MessageOrBuilder {\n", "deprecation", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", - "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), + "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), "{", "", "}", ""); - } + } printer->Annotate("{", "}", descriptor_); - - printer->Indent(); + + printer->Indent(); for (int i = 0; i < descriptor_->field_count(); i++) { printer->Print("\n"); field_generators_.get(descriptor_->field(i)) @@ -295,79 +295,79 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname", context_->GetNameResolver()->GetImmutableClassName(descriptor_)); } - printer->Outdent(); - - printer->Print("}\n"); -} - -// =================================================================== - -void ImmutableMessageGenerator::Generate(io::Printer* printer) { - bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - + printer->Outdent(); + + printer->Print("}\n"); +} + +// =================================================================== + +void ImmutableMessageGenerator::Generate(io::Printer* printer) { + bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); + std::map<TProtoStringType, TProtoStringType> variables; variables["static"] = is_own_file ? "" : "static "; - variables["classname"] = descriptor_->name(); - variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); - variables["ver"] = GeneratedCodeVersionSuffix(); + variables["classname"] = descriptor_->name(); + variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); + variables["ver"] = GeneratedCodeVersionSuffix(); variables["deprecation"] = descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""; - - WriteMessageDocComment(printer, descriptor_); - MaybePrintGeneratedAnnotation(context_, printer, descriptor_, - /* immutable = */ true); - - // The builder_type stores the super type name of the nested Builder class. + + WriteMessageDocComment(printer, descriptor_); + MaybePrintGeneratedAnnotation(context_, printer, descriptor_, + /* immutable = */ true); + + // The builder_type stores the super type name of the nested Builder class. TProtoStringType builder_type; - if (descriptor_->extension_range_count() > 0) { + if (descriptor_->extension_range_count() > 0) { printer->Print( variables, "$deprecation$public $static$final class $classname$ extends\n"); - printer->Annotate("classname", descriptor_); - printer->Print( - variables, - " com.google.protobuf.GeneratedMessage$ver$.ExtendableMessage<\n" - " $classname$> implements\n" - " $extra_interfaces$\n" - " $classname$OrBuilder {\n"); - builder_type = strings::Substitute( - "com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>", - name_resolver_->GetImmutableClassName(descriptor_), - GeneratedCodeVersionSuffix()); - } else { + printer->Annotate("classname", descriptor_); + printer->Print( + variables, + " com.google.protobuf.GeneratedMessage$ver$.ExtendableMessage<\n" + " $classname$> implements\n" + " $extra_interfaces$\n" + " $classname$OrBuilder {\n"); + builder_type = strings::Substitute( + "com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>", + name_resolver_->GetImmutableClassName(descriptor_), + GeneratedCodeVersionSuffix()); + } else { printer->Print( variables, "$deprecation$public $static$final class $classname$ extends\n"); - printer->Annotate("classname", descriptor_); - printer->Print(variables, + printer->Annotate("classname", descriptor_); + printer->Print(variables, " com.google.protobuf.GeneratedMessage$ver$ implements\n" " $extra_interfaces$\n" " $classname$OrBuilder {\n"); builder_type = strings::Substitute("com.google.protobuf.GeneratedMessage$0.Builder<?>", GeneratedCodeVersionSuffix()); - } + } printer->Print("private static final long serialVersionUID = 0L;\n"); - printer->Indent(); - // Using builder_type, instead of Builder, prevents the Builder class from - // being loaded into PermGen space when the default instance is created. - // This optimizes the PermGen space usage for clients that do not modify - // messages. - printer->Print( + printer->Indent(); + // Using builder_type, instead of Builder, prevents the Builder class from + // being loaded into PermGen space when the default instance is created. + // This optimizes the PermGen space usage for clients that do not modify + // messages. + printer->Print( "// Use $classname$.newBuilder() to construct.\n" "private $classname$($buildertype$ builder) {\n" " super(builder);\n" "}\n", "classname", descriptor_->name(), "buildertype", builder_type); printer->Print("private $classname$() {\n", "classname", descriptor_->name()); - printer->Indent(); - GenerateInitializers(printer); - printer->Outdent(); - printer->Print( + printer->Indent(); + GenerateInitializers(printer); + printer->Outdent(); + printer->Print( "}\n" "\n"); - + printer->Print(variables, "@java.lang.Override\n" "@SuppressWarnings({\"unused\"})\n" @@ -377,57 +377,57 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { "}\n" "\n"); - printer->Print( + 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 - for (int i = 0; i < descriptor_->enum_type_count(); i++) { + + if (context_->HasGeneratedMethods(descriptor_)) { + GenerateParsingConstructor(printer); + } + + GenerateDescriptorMethods(printer); + + // Nested types + for (int i = 0; i < descriptor_->enum_type_count(); i++) { EnumGenerator(descriptor_->enum_type(i), true, context_).Generate(printer); - } - - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // Don't generate Java classes for map entry messages. - if (IsMapEntry(descriptor_->nested_type(i))) continue; + } + + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + // Don't generate Java classes for map entry messages. + if (IsMapEntry(descriptor_->nested_type(i))) continue; ImmutableMessageGenerator messageGenerator(descriptor_->nested_type(i), context_); - messageGenerator.GenerateInterface(printer); - messageGenerator.Generate(printer); - } - + messageGenerator.GenerateInterface(printer); + messageGenerator.Generate(printer); + } + // Integers for bit fields. int totalBits = 0; for (int i = 0; i < descriptor_->field_count(); i++) { totalBits += field_generators_.get(descriptor_->field(i)).GetNumBitsForMessage(); - } + } int totalInts = (totalBits + 31) / 32; for (int i = 0; i < totalInts; i++) { printer->Print("private int $bit_field_name$;\n", "bit_field_name", GetBitFieldName(i)); } - - // oneof + + // oneof std::map<TProtoStringType, TProtoStringType> vars; for (auto oneof : oneofs_) { 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, + // oneofCase_ and oneof_ + printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" "private java.lang.Object $oneof_name$_;\n"); - // OneofCase enum + // OneofCase enum printer->Print( vars, "public enum $oneof_capitalized_name$Case\n" @@ -435,15 +435,15 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { // 3.x users " implements com.google.protobuf.Internal.EnumLite,\n" " com.google.protobuf.AbstractMessage.InternalOneOfEnum {\n"); - printer->Indent(); + printer->Indent(); for (int j = 0; j < (oneof)->field_count(); j++) { const FieldDescriptor* field = (oneof)->field(j); - printer->Print( + 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())); - } + } printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name", ToUpper(vars["oneof_name"])); printer->Print(vars, @@ -451,7 +451,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { "private $oneof_capitalized_name$Case(int value) {\n" " this.value = value;\n" "}\n"); - printer->Print( + printer->Print( vars, "/**\n" " * @param value The number of the enum to look for.\n" @@ -470,8 +470,8 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { printer->Print(" case $field_number$: return $field_name$;\n", "field_number", StrCat(field->number()), "field_name", ToUpper(field->name())); - } - printer->Print( + } + printer->Print( " case 0: return $cap_oneof_name$_NOT_SET;\n" " default: return null;\n" " }\n" @@ -480,66 +480,66 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { " return this.value;\n" "}\n", "cap_oneof_name", ToUpper(vars["oneof_name"])); - printer->Outdent(); - printer->Print("};\n\n"); - // oneofCase() - printer->Print(vars, + printer->Outdent(); + printer->Print("};\n\n"); + // oneofCase() + printer->Print(vars, "public $oneof_capitalized_name$Case\n" "get$oneof_capitalized_name$Case() {\n" " return $oneof_capitalized_name$Case.forNumber(\n" " $oneof_name$Case_);\n" "}\n" "\n"); - } - - if (IsAnyMessage(descriptor_)) { - GenerateAnyMethods(printer); - } - - // Fields - for (int i = 0; i < descriptor_->field_count(); i++) { - printer->Print("public static final int $constant_name$ = $number$;\n", + } + + if (IsAnyMessage(descriptor_)) { + GenerateAnyMethods(printer); + } + + // 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())); printer->Annotate("constant_name", descriptor_->field(i)); - field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); - printer->Print("\n"); - } - - if (context_->HasGeneratedMethods(descriptor_)) { - GenerateIsInitialized(printer); - GenerateMessageSerializationMethods(printer); - GenerateEqualsAndHashCode(printer); - } - - - GenerateParseFromMethods(printer); - GenerateBuilder(printer); - - printer->Print( + field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); + printer->Print("\n"); + } + + if (context_->HasGeneratedMethods(descriptor_)) { + GenerateIsInitialized(printer); + GenerateMessageSerializationMethods(printer); + GenerateEqualsAndHashCode(printer); + } + + + GenerateParseFromMethods(printer); + GenerateBuilder(printer); + + printer->Print( "\n" "// @@protoc_insertion_point(class_scope:$full_name$)\n", "full_name", descriptor_->full_name()); - - // Carefully initialize the default instance in such a way that it doesn't - // conflict with other initialization. + + // Carefully initialize the default instance in such a way that it doesn't + // conflict with other initialization. printer->Print("private static final $classname$ DEFAULT_INSTANCE;\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - printer->Print( + printer->Print( "static {\n" " DEFAULT_INSTANCE = new $classname$();\n" "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Print( - "public static $classname$ getDefaultInstance() {\n" - " return DEFAULT_INSTANCE;\n" - "}\n" - "\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); - + + printer->Print( + "public static $classname$ getDefaultInstance() {\n" + " return DEFAULT_INSTANCE;\n" + "}\n" + "\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + // 'of' method for Wrappers if (IsWrappersProtoFile(descriptor_->file())) { printer->Print( @@ -551,98 +551,98 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { "field_type", PrimitiveTypeName(GetJavaType(descriptor_->field(0)))); } - GenerateParser(printer); - - printer->Print( + GenerateParser(printer); + + printer->Print( "@java.lang.Override\n" "public $classname$ getDefaultInstanceForType() {\n" " return DEFAULT_INSTANCE;\n" "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - // Extensions must be declared after the DEFAULT_INSTANCE is initialized - // because the DEFAULT_INSTANCE is used by the extension to lazily retrieve - // the outer class's FileDescriptor. - for (int i = 0; i < descriptor_->extension_count(); i++) { - ImmutableExtensionGenerator(descriptor_->extension(i), context_) - .Generate(printer); - } - - printer->Outdent(); - printer->Print("}\n\n"); -} - -// =================================================================== - + + // Extensions must be declared after the DEFAULT_INSTANCE is initialized + // because the DEFAULT_INSTANCE is used by the extension to lazily retrieve + // the outer class's FileDescriptor. + for (int i = 0; i < descriptor_->extension_count(); i++) { + ImmutableExtensionGenerator(descriptor_->extension(i), context_) + .Generate(printer); + } + + printer->Outdent(); + printer->Print("}\n\n"); +} + +// =================================================================== + void ImmutableMessageGenerator::GenerateMessageSerializationMethods( io::Printer* printer) { std::unique_ptr<const FieldDescriptor*[]> sorted_fields( - SortFieldsByNumber(descriptor_)); - + 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( + 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" " throws java.io.IOException {\n"); - printer->Indent(); + printer->Indent(); - if (HasPackedFields(descriptor_)) { - // writeTo(CodedOutputStream output) might be invoked without - // getSerializedSize() ever being called, but we need the memoized + if (HasPackedFields(descriptor_)) { + // writeTo(CodedOutputStream output) might be invoked without + // getSerializedSize() ever being called, but we need the memoized // sizes in case this message has packed fields. Rather than emit checks // for each packed field, just call getSerializedSize() up front. In most // cases, getSerializedSize() will have already been called anyway by one // of the wrapper writeTo() methods, making this call cheap. printer->Print("getSerializedSize();\n"); - } - - if (descriptor_->extension_range_count() > 0) { - if (descriptor_->options().message_set_wire_format()) { - printer->Print( + } + + if (descriptor_->extension_range_count() > 0) { + if (descriptor_->options().message_set_wire_format()) { + printer->Print( "com.google.protobuf.GeneratedMessage$ver$\n" " .ExtendableMessage<$classname$>.ExtensionWriter\n" " extensionWriter = newMessageSetExtensionWriter();\n", "classname", name_resolver_->GetImmutableClassName(descriptor_), "ver", GeneratedCodeVersionSuffix()); - } else { - printer->Print( + } else { + printer->Print( "com.google.protobuf.GeneratedMessage$ver$\n" " .ExtendableMessage<$classname$>.ExtensionWriter\n" " extensionWriter = newExtensionWriter();\n", "classname", name_resolver_->GetImmutableClassName(descriptor_), "ver", GeneratedCodeVersionSuffix()); - } - } - - // Merge the fields and the extension ranges, both sorted by field number. - for (int i = 0, j = 0; + } + } + + // 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++]); - } - } - + 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++]); + } + } + if (descriptor_->options().message_set_wire_format()) { printer->Print("unknownFields.writeAsMessageSetTo(output);\n"); } else { printer->Print("unknownFields.writeTo(output);\n"); - } - - printer->Outdent(); - printer->Print( + } + + printer->Outdent(); + printer->Print( "}\n" "\n" "@java.lang.Override\n" @@ -650,43 +650,43 @@ void ImmutableMessageGenerator::GenerateMessageSerializationMethods( " int size = memoizedSize;\n" " if (size != -1) return size;\n" "\n"); - printer->Indent(); - + printer->Indent(); + printer->Print("size = 0;\n"); - for (int i = 0; i < descriptor_->field_count(); i++) { - field_generators_.get(sorted_fields[i]).GenerateSerializedSizeCode(printer); - } - - if (descriptor_->extension_range_count() > 0) { - if (descriptor_->options().message_set_wire_format()) { + for (int i = 0; i < descriptor_->field_count(); i++) { + field_generators_.get(sorted_fields[i]).GenerateSerializedSizeCode(printer); + } + + if (descriptor_->extension_range_count() > 0) { + if (descriptor_->options().message_set_wire_format()) { printer->Print("size += extensionsSerializedSizeAsMessageSet();\n"); - } else { + } else { printer->Print("size += extensionsSerializedSize();\n"); - } - } - + } + } + if (descriptor_->options().message_set_wire_format()) { printer->Print("size += unknownFields.getSerializedSizeAsMessageSet();\n"); } else { printer->Print("size += unknownFields.getSerializedSize();\n"); - } - + } + printer->Print( "memoizedSize = size;\n" "return size;\n"); - printer->Outdent(); - printer->Print( + printer->Outdent(); + printer->Print( "}\n" "\n"); -} - +} + void ImmutableMessageGenerator::GenerateParseFromMethods(io::Printer* printer) { - // Note: These are separate from GenerateMessageSerializationMethods() - // because they need to be generated even for messages that are optimized - // for code size. - printer->Print( + // Note: These are separate from GenerateMessageSerializationMethods() + // because they need to be generated even for messages that are optimized + // for code size. + printer->Print( "public static $classname$ parseFrom(\n" " java.nio.ByteBuffer data)\n" " throws com.google.protobuf.InvalidProtocolBufferException {\n" @@ -761,28 +761,28 @@ void ImmutableMessageGenerator::GenerateParseFromMethods(io::Printer* printer) { "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_), "ver", 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) { +} + +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) { - // LITE_RUNTIME implements this at the GeneratedMessageLite level. - printer->Print( +} + +// =================================================================== + +void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) { + // LITE_RUNTIME implements this at the GeneratedMessageLite level. + printer->Print( "@java.lang.Override\n" "public Builder newBuilderForType() { return newBuilder(); }\n"); - - printer->Print( + + printer->Print( "public static Builder newBuilder() {\n" " return DEFAULT_INSTANCE.toBuilder();\n" "}\n" @@ -796,8 +796,8 @@ void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) { "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Print( + + printer->Print( "@java.lang.Override\n" "protected Builder newBuilderForType(\n" " com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n" @@ -805,15 +805,15 @@ void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) { " return builder;\n" "}\n", "ver", GeneratedCodeVersionSuffix()); - - MessageBuilderGenerator builderGenerator(descriptor_, context_); - builderGenerator.Generate(printer); -} - + + MessageBuilderGenerator builderGenerator(descriptor_, context_); + builderGenerator.Generate(printer); +} + void ImmutableMessageGenerator::GenerateDescriptorMethods( io::Printer* printer) { - if (!descriptor_->options().no_standard_descriptor_accessor()) { - printer->Print( + if (!descriptor_->options().no_standard_descriptor_accessor()) { + printer->Print( "public static final com.google.protobuf.Descriptors.Descriptor\n" " getDescriptor() {\n" " return $fileclass$.internal_$identifier$_descriptor;\n" @@ -821,44 +821,44 @@ void ImmutableMessageGenerator::GenerateDescriptorMethods( "\n", "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), "identifier", UniqueFileScopeIdentifier(descriptor_)); - } + } std::vector<const FieldDescriptor*> map_fields; - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); - if (GetJavaType(field) == JAVATYPE_MESSAGE && - IsMapEntry(field->message_type())) { - map_fields.push_back(field); - } - } - if (!map_fields.empty()) { - printer->Print( + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + if (GetJavaType(field) == JAVATYPE_MESSAGE && + IsMapEntry(field->message_type())) { + map_fields.push_back(field); + } + } + if (!map_fields.empty()) { + printer->Print( "@SuppressWarnings({\"rawtypes\"})\n" "@java.lang.Override\n" "protected com.google.protobuf.MapField internalGetMapField(\n" " int number) {\n" " switch (number) {\n"); - printer->Indent(); - printer->Indent(); - for (int i = 0; i < map_fields.size(); ++i) { - const FieldDescriptor* field = map_fields[i]; - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - printer->Print( + printer->Indent(); + printer->Indent(); + for (int i = 0; i < map_fields.size(); ++i) { + const FieldDescriptor* field = map_fields[i]; + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + printer->Print( "case $number$:\n" " return internalGet$capitalized_name$();\n", "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); - } - printer->Print( - "default:\n" - " throw new RuntimeException(\n" - " \"Invalid map field number: \" + number);\n"); - printer->Outdent(); - printer->Outdent(); - printer->Print( - " }\n" - "}\n"); - } - printer->Print( + } + printer->Print( + "default:\n" + " throw new RuntimeException(\n" + " \"Invalid map field number: \" + number);\n"); + printer->Outdent(); + printer->Outdent(); + printer->Print( + " }\n" + "}\n"); + } + printer->Print( "@java.lang.Override\n" "protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" " internalGetFieldAccessorTable() {\n" @@ -871,53 +871,53 @@ void ImmutableMessageGenerator::GenerateDescriptorMethods( "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), "identifier", UniqueFileScopeIdentifier(descriptor_), "ver", GeneratedCodeVersionSuffix()); -} - -// =================================================================== - +} + +// =================================================================== + void ImmutableMessageGenerator::GenerateIsInitialized(io::Printer* printer) { - // Memoizes whether the protocol buffer is fully initialized (has all - // required fields). -1 means not yet computed. 0 means false and 1 means - // true. + // Memoizes whether the protocol buffer is fully initialized (has all + // required fields). -1 means not yet computed. 0 means false and 1 means + // true. printer->Print("private byte memoizedIsInitialized = -1;\n"); - printer->Print( + printer->Print( "@java.lang.Override\n" "public final boolean isInitialized() {\n"); - printer->Indent(); - - // Don't directly compare to -1 to avoid an Android x86 JIT bug. - printer->Print( + printer->Indent(); + + // Don't directly compare to -1 to avoid an Android x86 JIT bug. + printer->Print( "byte isInitialized = memoizedIsInitialized;\n" "if (isInitialized == 1) return true;\n" "if (isInitialized == 0) return false;\n" "\n"); - - // Check that all required fields in this message are set. - // TODO(kenton): We can optimize this when we switch to putting all the - // "has" fields into a single bitfield. - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - - if (field->is_required()) { - printer->Print( + + // Check that all required fields in this message are set. + // TODO(kenton): We can optimize this when we switch to putting all the + // "has" fields into a single bitfield. + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + + if (field->is_required()) { + printer->Print( "if (!has$name$()) {\n" " memoizedIsInitialized = 0;\n" " return false;\n" "}\n", "name", info->capitalized_name); - } - } - - // Now check that all embedded messages are initialized. - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - if (GetJavaType(field) == JAVATYPE_MESSAGE && - HasRequiredFields(field->message_type())) { - switch (field->label()) { - case FieldDescriptor::LABEL_REQUIRED: - printer->Print( + } + } + + // Now check that all embedded messages are initialized. + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + if (GetJavaType(field) == JAVATYPE_MESSAGE && + HasRequiredFields(field->message_type())) { + switch (field->label()) { + case FieldDescriptor::LABEL_REQUIRED: + printer->Print( "if (!get$name$().isInitialized()) {\n" " memoizedIsInitialized = 0;\n" " return false;\n" @@ -925,16 +925,16 @@ void ImmutableMessageGenerator::GenerateIsInitialized(io::Printer* printer) { "type", name_resolver_->GetImmutableClassName(field->message_type()), "name", info->capitalized_name); - break; - case FieldDescriptor::LABEL_OPTIONAL: - printer->Print( + break; + case FieldDescriptor::LABEL_OPTIONAL: + printer->Print( "if (has$name$()) {\n" " if (!get$name$().isInitialized()) {\n" - " memoizedIsInitialized = 0;\n" - " return false;\n" - " }\n" - "}\n", - "name", info->capitalized_name); + " memoizedIsInitialized = 0;\n" + " return false;\n" + " }\n" + "}\n", + "name", info->capitalized_name); break; case FieldDescriptor::LABEL_REPEATED: if (IsMapEntry(field->message_type())) { @@ -949,8 +949,8 @@ void ImmutableMessageGenerator::GenerateIsInitialized(io::Printer* printer) { MapValueImmutableClassdName(field->message_type(), name_resolver_), "name", info->capitalized_name); - } else { - printer->Print( + } else { + printer->Print( "for (int i = 0; i < get$name$Count(); i++) {\n" " if (!get$name$(i).isInitialized()) {\n" " memoizedIsInitialized = 0;\n" @@ -960,52 +960,52 @@ void ImmutableMessageGenerator::GenerateIsInitialized(io::Printer* printer) { "type", name_resolver_->GetImmutableClassName(field->message_type()), "name", info->capitalized_name); - } - break; - } - } - } - - if (descriptor_->extension_range_count() > 0) { - printer->Print( + } + break; + } + } + } + + if (descriptor_->extension_range_count() > 0) { + printer->Print( "if (!extensionsAreInitialized()) {\n" " memoizedIsInitialized = 0;\n" " return false;\n" "}\n"); - } - - printer->Outdent(); - + } + + printer->Outdent(); + printer->Print(" memoizedIsInitialized = 1;\n"); - - printer->Print( + + printer->Print( " return true;\n" "}\n" "\n"); -} - -// =================================================================== - -namespace { -bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) { - if (field->is_repeated()) { - return false; - } +} + +// =================================================================== + +namespace { +bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) { + if (field->is_repeated()) { + return false; + } if (HasHasbit(field)) { - return true; - } + return true; + } return GetJavaType(field) == JAVATYPE_MESSAGE && !IsRealOneof(field); -} -} // namespace - +} +} // namespace + void ImmutableMessageGenerator::GenerateEqualsAndHashCode( io::Printer* printer) { - printer->Print( + printer->Print( "@java.lang.Override\n" "public boolean equals("); printer->Print("final java.lang.Object obj) {\n"); - printer->Indent(); - printer->Print( + printer->Indent(); + printer->Print( "if (obj == this) {\n" " return true;\n" "}\n" @@ -1015,246 +1015,246 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode( "$classname$ other = ($classname$) obj;\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); + + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); if (!IsRealOneof(field)) { - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field); - if (check_has_bits) { - printer->Print( + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field); + if (check_has_bits) { + printer->Print( "if (has$name$() != other.has$name$()) return false;\n" "if (has$name$()) {\n", "name", info->capitalized_name); - printer->Indent(); - } - field_generators_.get(field).GenerateEqualsCode(printer); - if (check_has_bits) { - printer->Outdent(); + printer->Indent(); + } + field_generators_.get(field).GenerateEqualsCode(printer); + if (check_has_bits) { + printer->Outdent(); printer->Print("}\n"); - } - } - } - - // Compare oneofs. + } + } + } + + // Compare oneofs. for (auto oneof : oneofs_) { - printer->Print( + printer->Print( "if (!get$oneof_capitalized_name$Case().equals(" "other.get$oneof_capitalized_name$Case())) return false;\n", "oneof_capitalized_name", context_->GetOneofGeneratorInfo(oneof)->capitalized_name); printer->Print("switch ($oneof_name$Case_) {\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); - printer->Indent(); + 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())); - printer->Indent(); - field_generators_.get(field).GenerateEqualsCode(printer); - printer->Print("break;\n"); - printer->Outdent(); - } - printer->Print( + printer->Indent(); + field_generators_.get(field).GenerateEqualsCode(printer); + printer->Print("break;\n"); + printer->Outdent(); + } + printer->Print( "case 0:\n" "default:\n"); - printer->Outdent(); - printer->Print("}\n"); - } - + printer->Outdent(); + printer->Print("}\n"); + } + // Always consider unknown fields for equality. This will sometimes return // 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 (descriptor_->extension_range_count() > 0) { - printer->Print( + if (descriptor_->extension_range_count() > 0) { + printer->Print( "if (!getExtensionFields().equals(other.getExtensionFields()))\n" " return false;\n"); - } + } printer->Print("return true;\n"); - printer->Outdent(); - printer->Print( + printer->Outdent(); + printer->Print( "}\n" "\n"); - - printer->Print( + + printer->Print( "@java.lang.Override\n" "public int hashCode() {\n"); - printer->Indent(); + printer->Indent(); printer->Print("if (memoizedHashCode != 0) {\n"); - printer->Indent(); + printer->Indent(); printer->Print("return memoizedHashCode;\n"); - printer->Outdent(); - printer->Print( + printer->Outdent(); + printer->Print( "}\n" "int hash = 41;\n"); - + // If we output a getDescriptor() method, use that as it is more efficient. if (descriptor_->options().no_standard_descriptor_accessor()) { printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n"); } else { printer->Print("hash = (19 * hash) + getDescriptor().hashCode();\n"); } - - // hashCode non-oneofs. - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); + + // hashCode non-oneofs. + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); if (!IsRealOneof(field)) { - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field); - if (check_has_bits) { + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field); + if (check_has_bits) { printer->Print("if (has$name$()) {\n", "name", info->capitalized_name); - printer->Indent(); - } - field_generators_.get(field).GenerateHashCode(printer); - if (check_has_bits) { - printer->Outdent(); - printer->Print("}\n"); - } - } - } - - // hashCode oneofs. + printer->Indent(); + } + field_generators_.get(field).GenerateHashCode(printer); + if (check_has_bits) { + printer->Outdent(); + printer->Print("}\n"); + } + } + } + + // hashCode oneofs. for (auto oneof : oneofs_) { printer->Print("switch ($oneof_name$Case_) {\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); - printer->Indent(); + 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())); - printer->Indent(); - field_generators_.get(field).GenerateHashCode(printer); - printer->Print("break;\n"); - printer->Outdent(); - } - printer->Print( + printer->Indent(); + field_generators_.get(field).GenerateHashCode(printer); + printer->Print("break;\n"); + printer->Outdent(); + } + printer->Print( "case 0:\n" "default:\n"); - printer->Outdent(); - printer->Print("}\n"); - } - - if (descriptor_->extension_range_count() > 0) { + printer->Outdent(); + printer->Print("}\n"); + } + + if (descriptor_->extension_range_count() > 0) { printer->Print("hash = hashFields(hash, getExtensionFields());\n"); - } - + } + printer->Print("hash = (29 * hash) + unknownFields.hashCode();\n"); - printer->Print( + printer->Print( "memoizedHashCode = hash;\n" "return hash;\n"); - printer->Outdent(); - printer->Print( + printer->Outdent(); + printer->Print( "}\n" "\n"); -} - -// =================================================================== - +} + +// =================================================================== + void ImmutableMessageGenerator::GenerateExtensionRegistrationCode( io::Printer* printer) { - for (int i = 0; i < descriptor_->extension_count(); i++) { - ImmutableExtensionGenerator(descriptor_->extension(i), context_) + for (int i = 0; i < descriptor_->extension_count(); i++) { + ImmutableExtensionGenerator(descriptor_->extension(i), context_) .GenerateRegistrationCode(printer); - } - - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - ImmutableMessageGenerator(descriptor_->nested_type(i), context_) + } + + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + ImmutableMessageGenerator(descriptor_->nested_type(i), context_) .GenerateExtensionRegistrationCode(printer); - } -} - -// =================================================================== + } +} + +// =================================================================== 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( + 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++) { + + // 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"); - + "com.google.protobuf.UnknownFieldSet.Builder unknownFields =\n" + " com.google.protobuf.UnknownFieldSet.newBuilder();\n"); + printer->Print("try {\n"); - printer->Indent(); - - printer->Print( + printer->Indent(); + + printer->Print( "boolean done = false;\n" "while (!done) {\n"); - printer->Indent(); - - printer->Print( + printer->Indent(); + + printer->Print( "int tag = input.readTag();\n" "switch (tag) {\n"); - printer->Indent(); - - printer->Print( + 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]; + + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = sorted_fields[i]; uint32_t tag = WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); - + printer->Print("case $tag$: {\n", "tag", StrCat(static_cast<int32_t>(tag))); - printer->Indent(); - - field_generators_.get(field).GenerateParsingCode(printer); - - printer->Outdent(); - printer->Print( + 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(). + + 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(). uint32_t packed_tag = WireFormatLite::MakeTag( field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED); printer->Print("case $tag$: {\n", "tag", StrCat(static_cast<int32_t>(packed_tag))); - printer->Indent(); - - field_generators_.get(field).GenerateParsingCodeFromPacked(printer); - - printer->Outdent(); - printer->Print( + printer->Indent(); + + field_generators_.get(field).GenerateParsingCodeFromPacked(printer); + + printer->Outdent(); + printer->Print( " break;\n" "}\n"); - } - } - + } + } + printer->Print( "default: {\n" " if (!parseUnknownField(\n" @@ -1264,109 +1264,109 @@ void ImmutableMessageGenerator::GenerateParsingConstructor( " break;\n" "}\n"); - printer->Outdent(); - printer->Outdent(); - printer->Print( + 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 (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); - } - + + printer->Outdent(); + printer->Print( + "} catch (com.google.protobuf.InvalidProtocolBufferException e) {\n" + " throw e.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. + + // Make extensions immutable. printer->Print("makeExtensionsImmutable();\n"); - - printer->Outdent(); - printer->Outdent(); - printer->Print( + + 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( + "}\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_)) { + "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(); - } + } 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( - "};\n" - "\n"); - - printer->Print( - "public static com.google.protobuf.Parser<$classname$> parser() {\n" - " return PARSER;\n" - "}\n" - "\n" - "@java.lang.Override\n" - "public com.google.protobuf.Parser<$classname$> getParserForType() {\n" - " return PARSER;\n" - "}\n" - "\n", - "classname", descriptor_->name()); -} - -// =================================================================== -void ImmutableMessageGenerator::GenerateInitializers(io::Printer* printer) { - for (int i = 0; i < descriptor_->field_count(); i++) { + printer->Outdent(); + printer->Print( + "};\n" + "\n"); + + printer->Print( + "public static com.google.protobuf.Parser<$classname$> parser() {\n" + " return PARSER;\n" + "}\n" + "\n" + "@java.lang.Override\n" + "public com.google.protobuf.Parser<$classname$> getParserForType() {\n" + " return PARSER;\n" + "}\n" + "\n", + "classname", descriptor_->name()); +} + +// =================================================================== +void ImmutableMessageGenerator::GenerateInitializers(io::Printer* printer) { + for (int i = 0; i < descriptor_->field_count(); i++) { if (!IsRealOneof(descriptor_->field(i))) { - field_generators_.get(descriptor_->field(i)) - .GenerateInitializationCode(printer); - } - } -} - + field_generators_.get(descriptor_->field(i)) + .GenerateInitializationCode(printer); + } + } +} + // =================================================================== void ImmutableMessageGenerator::GenerateMutableCopy(io::Printer* printer) { printer->Print( @@ -1639,8 +1639,8 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( "message", message_name); } -void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { - printer->Print( +void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { + printer->Print( "private static String getTypeUrl(\n" " java.lang.String typeUrlPrefix,\n" " com.google.protobuf.Descriptors.Descriptor descriptor) {\n" @@ -1711,9 +1711,9 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { " cachedUnpackValue = result;\n" " return result;\n" "}\n"); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.h index cafc91e68b..d32bb056a5 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message.h @@ -1,46 +1,46 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ + #include <map> #include <string> #include <google/protobuf/compiler/java/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,105 +49,105 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -static const int kMaxStaticSize = 1 << 15; // aka 32k - -class MessageGenerator { - public: - explicit MessageGenerator(const Descriptor* descriptor); - virtual ~MessageGenerator(); - - // All static variables have to be declared at the top-level of the file - // so that we can control initialization order, which is important for - // DescriptorProto bootstrapping to work. +namespace protobuf { +namespace compiler { +namespace java { + +static const int kMaxStaticSize = 1 << 15; // aka 32k + +class MessageGenerator { + public: + explicit MessageGenerator(const Descriptor* descriptor); + virtual ~MessageGenerator(); + + // All static variables have to be declared at the top-level of the file + // so that we can control initialization order, which is important for + // DescriptorProto bootstrapping to work. virtual void GenerateStaticVariables(io::Printer* printer, int* bytecode_estimate) = 0; - - // Output code which initializes the static variables generated by - // GenerateStaticVariables(). Returns an estimate of bytecode size. - virtual int GenerateStaticVariableInitializers(io::Printer* printer) = 0; - - // Generate the class itself. - virtual void Generate(io::Printer* printer) = 0; - + + // Output code which initializes the static variables generated by + // GenerateStaticVariables(). Returns an estimate of bytecode size. + virtual int GenerateStaticVariableInitializers(io::Printer* printer) = 0; + + // Generate the class itself. + virtual void Generate(io::Printer* printer) = 0; + // Generates the base interface that both the class and its builder // implement - virtual void GenerateInterface(io::Printer* printer) = 0; - - // Generate code to register all contained extensions with an - // ExtensionRegistry. - virtual void GenerateExtensionRegistrationCode(io::Printer* printer) = 0; + virtual void GenerateInterface(io::Printer* printer) = 0; + + // Generate code to register all contained extensions with an + // ExtensionRegistry. + virtual void GenerateExtensionRegistrationCode(io::Printer* printer) = 0; virtual void GenerateKotlinDsl(io::Printer* printer) const = 0; virtual void GenerateKotlinMembers(io::Printer* printer) const = 0; virtual void GenerateTopLevelKotlinMembers(io::Printer* printer) const = 0; - - protected: - const Descriptor* descriptor_; + + protected: + const Descriptor* descriptor_; std::set<const OneofDescriptor*> oneofs_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); -}; - -class ImmutableMessageGenerator : public MessageGenerator { - public: - ImmutableMessageGenerator(const Descriptor* descriptor, Context* context); - virtual ~ImmutableMessageGenerator(); - + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); +}; + +class ImmutableMessageGenerator : public MessageGenerator { + public: + ImmutableMessageGenerator(const Descriptor* descriptor, Context* context); + virtual ~ImmutableMessageGenerator(); + void Generate(io::Printer* printer) override; void GenerateInterface(io::Printer* printer) override; void GenerateExtensionRegistrationCode(io::Printer* printer) override; void GenerateStaticVariables(io::Printer* printer, int* bytecode_estimate) override; - - // Returns an estimate of the number of bytes the printed code will compile to + + // Returns an estimate of the number of bytes the printed code will compile to int GenerateStaticVariableInitializers(io::Printer* printer) override; void GenerateKotlinDsl(io::Printer* printer) const override; void GenerateKotlinMembers(io::Printer* printer) const override; void GenerateTopLevelKotlinMembers(io::Printer* printer) const override; - - private: - void GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate); - - // Returns an estimate of the number of bytes the printed code will compile to - int GenerateFieldAccessorTableInitializer(io::Printer* printer); - - 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); - void GenerateDescriptorMethods(io::Printer* printer); - void GenerateInitializers(io::Printer* printer); - void GenerateEqualsAndHashCode(io::Printer* printer); - void GenerateParser(io::Printer* printer); - void GenerateParsingConstructor(io::Printer* printer); + + private: + void GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate); + + // Returns an estimate of the number of bytes the printed code will compile to + int GenerateFieldAccessorTableInitializer(io::Printer* printer); + + 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); + void GenerateDescriptorMethods(io::Printer* printer); + void GenerateInitializers(io::Printer* printer); + void GenerateEqualsAndHashCode(io::Printer* printer); + void GenerateParser(io::Printer* printer); + void GenerateParsingConstructor(io::Printer* printer); void GenerateMutableCopy(io::Printer* printer); void GenerateKotlinExtensions(io::Printer* printer) const; - void GenerateAnyMethods(io::Printer* printer); - - Context* context_; - ClassNameResolver* name_resolver_; - FieldGeneratorMap<ImmutableFieldGenerator> field_generators_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + void GenerateAnyMethods(io::Printer* printer); + + Context* context_; + ClassNameResolver* name_resolver_; + FieldGeneratorMap<ImmutableFieldGenerator> field_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.cc index 510b9d785c..3fd517cde1 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.cc @@ -1,44 +1,44 @@ -// 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: dweis@google.com (Daniel Weis) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - +// 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: dweis@google.com (Daniel Weis) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + #include <google/protobuf/compiler/java/java_message_builder.h> - -#include <algorithm> -#include <map> -#include <memory> -#include <vector> - + +#include <algorithm> +#include <map> +#include <memory> +#include <vector> + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_enum.h> @@ -52,43 +52,43 @@ #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { TProtoStringType MapValueImmutableClassdName(const Descriptor* descriptor, ClassNameResolver* name_resolver) { - const FieldDescriptor* value_field = descriptor->FindFieldByName("value"); - GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type()); - return name_resolver->GetImmutableClassName(value_field->message_type()); -} -} // namespace - + const FieldDescriptor* value_field = descriptor->FindFieldByName("value"); + GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type()); + return name_resolver->GetImmutableClassName(value_field->message_type()); +} +} // namespace + MessageBuilderGenerator::MessageBuilderGenerator(const Descriptor* descriptor, Context* context) : descriptor_(descriptor), context_(context), name_resolver_(context->GetNameResolver()), field_generators_(descriptor, context_) { - GOOGLE_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite())) - << "Generator factory error: A non-lite message generator is used to " - "generate lite messages."; + GOOGLE_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()); } } -} - -MessageBuilderGenerator::~MessageBuilderGenerator() {} - +} + +MessageBuilderGenerator::~MessageBuilderGenerator() {} + void MessageBuilderGenerator::Generate(io::Printer* printer) { - WriteMessageDocComment(printer, descriptor_); - if (descriptor_->extension_range_count() > 0) { - printer->Print( + WriteMessageDocComment(printer, descriptor_); + if (descriptor_->extension_range_count() > 0) { + printer->Print( "public static final class Builder extends\n" " com.google.protobuf.GeneratedMessage$ver$.ExtendableBuilder<\n" " $classname$, Builder> implements\n" @@ -97,8 +97,8 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { "classname", name_resolver_->GetImmutableClassName(descriptor_), "extra_interfaces", ExtraBuilderInterfaces(descriptor_), "ver", GeneratedCodeVersionSuffix()); - } else { - printer->Print( + } else { + printer->Print( "public static final class Builder extends\n" " com.google.protobuf.GeneratedMessage$ver$.Builder<Builder> " "implements\n" @@ -107,30 +107,30 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { "classname", name_resolver_->GetImmutableClassName(descriptor_), "extra_interfaces", ExtraBuilderInterfaces(descriptor_), "ver", GeneratedCodeVersionSuffix()); - } - printer->Indent(); - - GenerateDescriptorMethods(printer); - GenerateCommonBuilderMethods(printer); - - if (context_->HasGeneratedMethods(descriptor_)) { - GenerateIsInitialized(printer); - GenerateBuilderParsingMethods(printer); - } - - // oneof + } + printer->Indent(); + + GenerateDescriptorMethods(printer); + GenerateCommonBuilderMethods(printer); + + if (context_->HasGeneratedMethods(descriptor_)) { + GenerateIsInitialized(printer); + GenerateBuilderParsingMethods(printer); + } + + // oneof std::map<TProtoStringType, TProtoStringType> vars; for (auto oneof : oneofs_) { 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, + // oneofCase_ and oneof_ + printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" "private java.lang.Object $oneof_name$_;\n"); - // oneofCase() and clearOneof() - printer->Print(vars, + // oneofCase() and clearOneof() + printer->Print(vars, "public $oneof_capitalized_name$Case\n" " get$oneof_capitalized_name$Case() {\n" " return $oneof_capitalized_name$Case.forNumber(\n" @@ -140,31 +140,31 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { "public Builder clear$oneof_capitalized_name$() {\n" " $oneof_name$Case_ = 0;\n" " $oneof_name$_ = null;\n"); - printer->Print(" onChanged();\n"); - printer->Print( + printer->Print(" onChanged();\n"); + printer->Print( " return this;\n" "}\n" "\n"); - } - + } + // Integers for bit fields. int totalBits = 0; for (int i = 0; i < descriptor_->field_count(); i++) { totalBits += field_generators_.get(descriptor_->field(i)).GetNumBitsForBuilder(); - } + } int totalInts = (totalBits + 31) / 32; for (int i = 0; i < totalInts; i++) { printer->Print("private int $bit_field_name$;\n", "bit_field_name", GetBitFieldName(i)); } - - for (int i = 0; i < descriptor_->field_count(); i++) { - printer->Print("\n"); - field_generators_.get(descriptor_->field(i)) + + for (int i = 0; i < descriptor_->field_count(); i++) { + printer->Print("\n"); + field_generators_.get(descriptor_->field(i)) .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 @@ -183,21 +183,21 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { " return super.mergeUnknownFields(unknownFields);\n" "}\n" "\n"); - - printer->Print( + + printer->Print( "\n" "// @@protoc_insertion_point(builder_scope:$full_name$)\n", "full_name", descriptor_->full_name()); - - printer->Outdent(); - printer->Print("}\n"); -} - -// =================================================================== - + + printer->Outdent(); + printer->Print("}\n"); +} + +// =================================================================== + void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) { - if (!descriptor_->options().no_standard_descriptor_accessor()) { - printer->Print( + if (!descriptor_->options().no_standard_descriptor_accessor()) { + printer->Print( "public static final com.google.protobuf.Descriptors.Descriptor\n" " getDescriptor() {\n" " return $fileclass$.internal_$identifier$_descriptor;\n" @@ -205,68 +205,68 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) { "\n", "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), "identifier", UniqueFileScopeIdentifier(descriptor_)); - } + } std::vector<const FieldDescriptor*> map_fields; - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); - if (GetJavaType(field) == JAVATYPE_MESSAGE && - IsMapEntry(field->message_type())) { - map_fields.push_back(field); - } - } - if (!map_fields.empty()) { - printer->Print( + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + if (GetJavaType(field) == JAVATYPE_MESSAGE && + IsMapEntry(field->message_type())) { + map_fields.push_back(field); + } + } + if (!map_fields.empty()) { + printer->Print( "@SuppressWarnings({\"rawtypes\"})\n" "protected com.google.protobuf.MapField internalGetMapField(\n" " int number) {\n" " switch (number) {\n"); - printer->Indent(); - printer->Indent(); - for (int i = 0; i < map_fields.size(); ++i) { - const FieldDescriptor* field = map_fields[i]; - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - printer->Print( + printer->Indent(); + printer->Indent(); + for (int i = 0; i < map_fields.size(); ++i) { + const FieldDescriptor* field = map_fields[i]; + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + printer->Print( "case $number$:\n" " return internalGet$capitalized_name$();\n", "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); - } - printer->Print( - "default:\n" - " throw new RuntimeException(\n" - " \"Invalid map field number: \" + number);\n"); - printer->Outdent(); - printer->Outdent(); - printer->Print( - " }\n" - "}\n"); - printer->Print( + } + printer->Print( + "default:\n" + " throw new RuntimeException(\n" + " \"Invalid map field number: \" + number);\n"); + printer->Outdent(); + printer->Outdent(); + printer->Print( + " }\n" + "}\n"); + printer->Print( "@SuppressWarnings({\"rawtypes\"})\n" "protected com.google.protobuf.MapField internalGetMutableMapField(\n" " int number) {\n" " switch (number) {\n"); - printer->Indent(); - printer->Indent(); - for (int i = 0; i < map_fields.size(); ++i) { - const FieldDescriptor* field = map_fields[i]; + printer->Indent(); + printer->Indent(); + for (int i = 0; i < map_fields.size(); ++i) { + const FieldDescriptor* field = map_fields[i]; const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - printer->Print( + printer->Print( "case $number$:\n" " return internalGetMutable$capitalized_name$();\n", "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); - } - printer->Print( - "default:\n" - " throw new RuntimeException(\n" - " \"Invalid map field number: \" + number);\n"); - printer->Outdent(); - printer->Outdent(); - printer->Print( - " }\n" - "}\n"); - } - printer->Print( + } + printer->Print( + "default:\n" + " throw new RuntimeException(\n" + " \"Invalid map field number: \" + number);\n"); + printer->Outdent(); + printer->Outdent(); + printer->Print( + " }\n" + "}\n"); + } + printer->Print( "@java.lang.Override\n" "protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" " internalGetFieldAccessorTable() {\n" @@ -279,21 +279,21 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) { "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), "identifier", UniqueFileScopeIdentifier(descriptor_), "ver", GeneratedCodeVersionSuffix()); -} - -// =================================================================== - +} + +// =================================================================== + void MessageBuilderGenerator::GenerateCommonBuilderMethods( io::Printer* printer) { - printer->Print( - "// Construct using $classname$.newBuilder()\n" - "private Builder() {\n" - " maybeForceBuilderInitialization();\n" - "}\n" - "\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Print( + printer->Print( + "// Construct using $classname$.newBuilder()\n" + "private Builder() {\n" + " maybeForceBuilderInitialization();\n" + "}\n" + "\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + + printer->Print( "private Builder(\n" " com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n" " super(parent);\n" @@ -301,57 +301,57 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( "}\n", "classname", name_resolver_->GetImmutableClassName(descriptor_), "ver", GeneratedCodeVersionSuffix()); - - printer->Print( + + 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++) { + + 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->Print( + field_generators_.get(descriptor_->field(i)) + .GenerateFieldBuilderInitializationCode(printer); + } + } + printer->Outdent(); + printer->Outdent(); + + printer->Print( " }\n" "}\n"); - - printer->Print( + + printer->Print( "@java.lang.Override\n" "public Builder clear() {\n" " super.clear();\n"); - - printer->Indent(); - - for (int i = 0; i < descriptor_->field_count(); i++) { + + printer->Indent(); + + 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_) { - printer->Print( + printer->Print( "$oneof_name$Case_ = 0;\n" "$oneof_name$_ = null;\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); - } - - printer->Outdent(); - - printer->Print( + } + + printer->Outdent(); + + printer->Print( " return this;\n" "}\n" "\n"); - - printer->Print( + + printer->Print( "@java.lang.Override\n" "public com.google.protobuf.Descriptors.Descriptor\n" " getDescriptorForType() {\n" @@ -360,17 +360,17 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( "\n", "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), "identifier", UniqueFileScopeIdentifier(descriptor_)); - - // LITE runtime implements this in GeneratedMessageLite. - printer->Print( + + // LITE runtime implements this in GeneratedMessageLite. + printer->Print( "@java.lang.Override\n" "public $classname$ getDefaultInstanceForType() {\n" " return $classname$.getDefaultInstance();\n" "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Print( + + printer->Print( "@java.lang.Override\n" "public $classname$ build() {\n" " $classname$ result = buildPartial();\n" @@ -381,26 +381,26 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Print( + + 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; - + + 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 @@ -408,44 +408,44 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( 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); - } - + + // 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", + printer->Print("result.$oneof_name$Case_ = $oneof_name$Case_;\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); - } - - printer->Outdent(); - + } + + printer->Outdent(); + printer->Print(" onBuilt();\n"); - - printer->Print( + + 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( + printer->Print( "@java.lang.Override\n" "public Builder clone() {\n" " return super.clone();\n" @@ -478,9 +478,9 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( " java.lang.Object value) {\n" " return super.addRepeatedField(field, value);\n" "}\n"); - - if (descriptor_->extension_range_count() > 0) { - printer->Print( + + if (descriptor_->extension_range_count() > 0) { + printer->Print( "@java.lang.Override\n" "public <Type> Builder setExtension(\n" " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" @@ -509,12 +509,12 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( " return super.clearExtension(extension);\n" "}\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - } - - // ----------------------------------------------------------------- - - if (context_->HasGeneratedMethods(descriptor_)) { - printer->Print( + } + + // ----------------------------------------------------------------- + + if (context_->HasGeneratedMethods(descriptor_)) { + printer->Print( "@java.lang.Override\n" "public Builder mergeFrom(com.google.protobuf.Message other) {\n" " if (other instanceof $classname$) {\n" @@ -526,71 +526,71 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Print( + + printer->Print( "public Builder mergeFrom($classname$ other) {\n" // Optimization: If other is the default instance, we know none of its // fields are set so we can skip the merge. " if (other == $classname$.getDefaultInstance()) return this;\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - printer->Indent(); - - for (int i = 0; i < descriptor_->field_count(); i++) { + printer->Indent(); + + for (int i = 0; i < descriptor_->field_count(); i++) { if (!IsRealOneof(descriptor_->field(i))) { field_generators_.get(descriptor_->field(i)) .GenerateMergingCode(printer); - } - } - - // Merge oneof fields. + } + } + + // Merge oneof fields. for (auto oneof : oneofs_) { printer->Print("switch (other.get$oneof_capitalized_name$Case()) {\n", "oneof_capitalized_name", context_->GetOneofGeneratorInfo(oneof)->capitalized_name); - printer->Indent(); + printer->Indent(); 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())); - printer->Indent(); - field_generators_.get(field).GenerateMergingCode(printer); + printer->Indent(); + field_generators_.get(field).GenerateMergingCode(printer); printer->Print("break;\n"); - printer->Outdent(); + printer->Outdent(); printer->Print("}\n"); - } - printer->Print( + } + printer->Print( "case $cap_oneof_name$_NOT_SET: {\n" " break;\n" "}\n", "cap_oneof_name", ToUpper(context_->GetOneofGeneratorInfo(oneof)->name)); - printer->Outdent(); + printer->Outdent(); printer->Print("}\n"); - } - - printer->Outdent(); - - // if message type has extensions - if (descriptor_->extension_range_count() > 0) { + } + + printer->Outdent(); + + // if message type has extensions + if (descriptor_->extension_range_count() > 0) { printer->Print(" this.mergeExtensionFields(other);\n"); - } - + } + printer->Print(" this.mergeUnknownFields(other.unknownFields);\n"); - + printer->Print(" onChanged();\n"); - - printer->Print( + + printer->Print( " return this;\n" "}\n" "\n"); - } -} - -// =================================================================== - + } +} + +// =================================================================== + void MessageBuilderGenerator::GenerateBuilderParsingMethods( io::Printer* printer) { - printer->Print( + printer->Print( "@java.lang.Override\n" "public Builder mergeFrom(\n" " com.google.protobuf.CodedInputStream input,\n" @@ -610,60 +610,60 @@ void MessageBuilderGenerator::GenerateBuilderParsingMethods( " return this;\n" "}\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); -} - -// =================================================================== - +} + +// =================================================================== + void MessageBuilderGenerator::GenerateIsInitialized(io::Printer* printer) { - printer->Print( + printer->Print( "@java.lang.Override\n" "public final boolean isInitialized() {\n"); - printer->Indent(); - - // Check that all required fields in this message are set. - // TODO(kenton): We can optimize this when we switch to putting all the - // "has" fields into a single bitfield. - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - - if (field->is_required()) { - printer->Print( + printer->Indent(); + + // Check that all required fields in this message are set. + // TODO(kenton): We can optimize this when we switch to putting all the + // "has" fields into a single bitfield. + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + + if (field->is_required()) { + printer->Print( "if (!has$name$()) {\n" " return false;\n" "}\n", "name", info->capitalized_name); - } - } - - // Now check that all embedded messages are initialized. - for (int i = 0; i < descriptor_->field_count(); i++) { - const FieldDescriptor* field = descriptor_->field(i); - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); - if (GetJavaType(field) == JAVATYPE_MESSAGE && - HasRequiredFields(field->message_type())) { - switch (field->label()) { - case FieldDescriptor::LABEL_REQUIRED: - printer->Print( + } + } + + // Now check that all embedded messages are initialized. + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); + if (GetJavaType(field) == JAVATYPE_MESSAGE && + HasRequiredFields(field->message_type())) { + switch (field->label()) { + case FieldDescriptor::LABEL_REQUIRED: + printer->Print( "if (!get$name$().isInitialized()) {\n" " return false;\n" "}\n", "type", name_resolver_->GetImmutableClassName(field->message_type()), "name", info->capitalized_name); - break; - case FieldDescriptor::LABEL_OPTIONAL: + break; + case FieldDescriptor::LABEL_OPTIONAL: printer->Print( "if (has$name$()) {\n" " if (!get$name$().isInitialized()) {\n" " return false;\n" " }\n" "}\n", - "name", info->capitalized_name); - break; - case FieldDescriptor::LABEL_REPEATED: - if (IsMapEntry(field->message_type())) { - printer->Print( + "name", info->capitalized_name); + break; + case FieldDescriptor::LABEL_REPEATED: + if (IsMapEntry(field->message_type())) { + printer->Print( "for ($type$ item : get$name$Map().values()) {\n" " if (!item.isInitialized()) {\n" " return false;\n" @@ -673,8 +673,8 @@ void MessageBuilderGenerator::GenerateIsInitialized(io::Printer* printer) { MapValueImmutableClassdName(field->message_type(), name_resolver_), "name", info->capitalized_name); - } else { - printer->Print( + } else { + printer->Print( "for (int i = 0; i < get$name$Count(); i++) {\n" " if (!get$name$(i).isInitialized()) {\n" " return false;\n" @@ -683,30 +683,30 @@ void MessageBuilderGenerator::GenerateIsInitialized(io::Printer* printer) { "type", name_resolver_->GetImmutableClassName(field->message_type()), "name", info->capitalized_name); - } - break; - } - } - } - - if (descriptor_->extension_range_count() > 0) { - printer->Print( + } + break; + } + } + } + + if (descriptor_->extension_range_count() > 0) { + printer->Print( "if (!extensionsAreInitialized()) {\n" " return false;\n" "}\n"); - } - - printer->Outdent(); - - printer->Print( + } + + printer->Outdent(); + + printer->Print( " return true;\n" "}\n" "\n"); -} - -// =================================================================== - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} + +// =================================================================== + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.h index fcd73b3436..fc3acc2e13 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder.h @@ -1,46 +1,46 @@ -// 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: dweis@google.com (Daniel Weis) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ - +// 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: dweis@google.com (Daniel Weis) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#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/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,41 +49,41 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class MessageBuilderGenerator { - public: - explicit MessageBuilderGenerator(const Descriptor* descriptor, - Context* context); - virtual ~MessageBuilderGenerator(); - - virtual void Generate(io::Printer* printer); - - private: - void GenerateCommonBuilderMethods(io::Printer* printer); - void GenerateDescriptorMethods(io::Printer* printer); - void GenerateBuilderParsingMethods(io::Printer* printer); - void GenerateIsInitialized(io::Printer* printer); - - const Descriptor* descriptor_; - Context* context_; - ClassNameResolver* name_resolver_; - FieldGeneratorMap<ImmutableFieldGenerator> field_generators_; +namespace protobuf { +namespace compiler { +namespace java { + +class MessageBuilderGenerator { + public: + explicit MessageBuilderGenerator(const Descriptor* descriptor, + Context* context); + virtual ~MessageBuilderGenerator(); + + virtual void Generate(io::Printer* printer); + + private: + void GenerateCommonBuilderMethods(io::Printer* printer); + void GenerateDescriptorMethods(io::Printer* printer); + void GenerateBuilderParsingMethods(io::Printer* printer); + 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); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageBuilderGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.cc index bff99b7b1a..185870fa6e 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.cc @@ -1,44 +1,44 @@ -// 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: dweis@google.com (Daniel Weis) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - +// 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: dweis@google.com (Daniel Weis) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + #include <google/protobuf/compiler/java/java_message_builder_lite.h> - -#include <algorithm> -#include <map> -#include <memory> -#include <vector> - + +#include <algorithm> +#include <map> +#include <memory> +#include <vector> + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_enum.h> @@ -52,33 +52,33 @@ #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -MessageBuilderLiteGenerator::MessageBuilderLiteGenerator( - const Descriptor* descriptor, Context* context) + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +MessageBuilderLiteGenerator::MessageBuilderLiteGenerator( + const Descriptor* descriptor, Context* context) : descriptor_(descriptor), context_(context), name_resolver_(context->GetNameResolver()), field_generators_(descriptor, context_) { - GOOGLE_CHECK(!HasDescriptorMethods(descriptor->file(), context->EnforceLite())) - << "Generator factory error: A lite message generator is used to " - "generate non-lite messages."; + GOOGLE_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()); } } -} - -MessageBuilderLiteGenerator::~MessageBuilderLiteGenerator() {} - +} + +MessageBuilderLiteGenerator::~MessageBuilderLiteGenerator() {} + void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { - WriteMessageDocComment(printer, descriptor_); - printer->Print( + WriteMessageDocComment(printer, descriptor_); + printer->Print( "public static final class Builder extends\n" " com.google.protobuf.GeneratedMessageLite.$extendible$Builder<\n" " $classname$, Builder> implements\n" @@ -87,20 +87,20 @@ void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { "classname", name_resolver_->GetImmutableClassName(descriptor_), "extra_interfaces", ExtraBuilderInterfaces(descriptor_), "extendible", descriptor_->extension_range_count() > 0 ? "Extendable" : ""); - printer->Indent(); - - GenerateCommonBuilderMethods(printer); - - // oneof + printer->Indent(); + + GenerateCommonBuilderMethods(printer); + + // oneof std::map<TProtoStringType, TProtoStringType> vars; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; vars["oneof_index"] = StrCat(oneof->index()); - - // oneofCase() and clearOneof() - printer->Print(vars, + + // oneofCase() and clearOneof() + printer->Print(vars, "@java.lang.Override\n" "public $oneof_capitalized_name$Case\n" " get$oneof_capitalized_name$Case() {\n" @@ -113,39 +113,39 @@ void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { " return this;\n" "}\n" "\n"); - } - - for (int i = 0; i < descriptor_->field_count(); i++) { - printer->Print("\n"); - field_generators_.get(descriptor_->field(i)) + } + + for (int i = 0; i < descriptor_->field_count(); i++) { + printer->Print("\n"); + field_generators_.get(descriptor_->field(i)) .GenerateBuilderMembers(printer); - } - - printer->Print( + } + + printer->Print( "\n" "// @@protoc_insertion_point(builder_scope:$full_name$)\n", "full_name", descriptor_->full_name()); - - printer->Outdent(); - printer->Print("}\n"); -} - -// =================================================================== - + + printer->Outdent(); + printer->Print("}\n"); +} + +// =================================================================== + void MessageBuilderLiteGenerator::GenerateCommonBuilderMethods( io::Printer* printer) { - printer->Print( + printer->Print( "// Construct using $classname$.newBuilder()\n" "private Builder() {\n" " super(DEFAULT_INSTANCE);\n" "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); -} - -// =================================================================== - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} + +// =================================================================== + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.h index 3402adf332..b0100e0bde 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_builder_lite.h @@ -1,46 +1,46 @@ -// 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: dweis@google.com (Daniel Weis) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__ - +// 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: dweis@google.com (Daniel Weis) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#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/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,38 +49,38 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class MessageBuilderLiteGenerator { - public: - explicit MessageBuilderLiteGenerator(const Descriptor* descriptor, +namespace protobuf { +namespace compiler { +namespace java { + +class MessageBuilderLiteGenerator { + public: + explicit MessageBuilderLiteGenerator(const Descriptor* descriptor, Context* context); - virtual ~MessageBuilderLiteGenerator(); - - virtual void Generate(io::Printer* printer); - - private: - void GenerateCommonBuilderMethods(io::Printer* printer); - - const Descriptor* descriptor_; - Context* context_; - ClassNameResolver* name_resolver_; - FieldGeneratorMap<ImmutableFieldLiteGenerator> field_generators_; + virtual ~MessageBuilderLiteGenerator(); + + virtual void Generate(io::Printer* printer); + + private: + void GenerateCommonBuilderMethods(io::Printer* printer); + + const Descriptor* descriptor_; + Context* context_; + ClassNameResolver* name_resolver_; + FieldGeneratorMap<ImmutableFieldLiteGenerator> field_generators_; std::set<const OneofDescriptor*> oneofs_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageBuilderLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageBuilderLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.cc index 6e2f181387..4e962b2dc2 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.cc @@ -1,40 +1,40 @@ -// 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 <map> +// 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 <map> #include <string> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_helpers.h> @@ -43,31 +43,31 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - - -namespace { - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + + +namespace { + void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - - (*variables)["type"] = - name_resolver->GetImmutableClassName(descriptor->message_type()); + SetCommonFieldVariables(descriptor, info, variables); + + (*variables)["type"] = + name_resolver->GetImmutableClassName(descriptor->message_type()); (*variables)["kt_type"] = (*variables)["type"]; - (*variables)["mutable_type"] = - name_resolver->GetMutableClassName(descriptor->message_type()); - (*variables)["group_or_message"] = + (*variables)["mutable_type"] = + name_resolver->GetMutableClassName(descriptor->message_type()); + (*variables)["group_or_message"] = (GetType(descriptor) == FieldDescriptor::TYPE_GROUP) ? "Group" : "Message"; - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + // 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"] = @@ -75,57 +75,57 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + " is deprecated\") " : ""; - (*variables)["on_changed"] = "onChanged();"; - (*variables)["ver"] = GeneratedCodeVersionSuffix(); - (*variables)["get_parser"] = + (*variables)["on_changed"] = "onChanged();"; + (*variables)["ver"] = GeneratedCodeVersionSuffix(); + (*variables)["get_parser"] = ExposePublicParser(descriptor->message_type()->file()) ? "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)["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"; - } - + // 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)["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"; + } + // 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_from_local"] = - GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); -} - -} // namespace - -// =================================================================== - + (*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_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); +} + +} // namespace + +// =================================================================== + ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) @@ -133,40 +133,40 @@ ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator( SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); -} - -ImmutableMessageFieldGenerator::~ImmutableMessageFieldGenerator() {} - -int ImmutableMessageFieldGenerator::GetNumBitsForMessage() const { +} + +ImmutableMessageFieldGenerator::~ImmutableMessageFieldGenerator() {} + +int ImmutableMessageFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; -} - -int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { +} + +int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { return GetNumBitsForMessage(); -} - +} + void ImmutableMessageFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { - // TODO(jonp): In the future, consider having a method specific to the - // interface so that builders can choose dynamically to either return a - // message or a nested builder, so that asking for the interface doesn't - // cause a message to ever be built. + // TODO(jonp): In the future, consider having a method specific to the + // interface so that builders can choose dynamically to either return a + // message or a nested builder, so that asking for the interface doesn't + // cause a message to ever be built. WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); - - WriteFieldDocComment(printer, descriptor_); + + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$$type$OrBuilder get$capitalized_name$OrBuilder();\n"); -} - +} + void ImmutableMessageFieldGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private $type$ $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); - + PrintExtraFieldInfo(variables_, printer); + if (HasHasbit(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -184,8 +184,8 @@ void ImmutableMessageFieldGenerator::GenerateMembers( " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); + + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -194,7 +194,7 @@ void ImmutableMessageFieldGenerator::GenerateMembers( " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } else { + } else { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, @@ -211,69 +211,69 @@ void ImmutableMessageFieldGenerator::GenerateMembers( " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + 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_); - } -} - -void ImmutableMessageFieldGenerator::PrintNestedBuilderCondition( + } +} + +void ImmutableMessageFieldGenerator::PrintNestedBuilderCondition( io::Printer* printer, const char* regular_case, - const char* nested_builder_case) const { - printer->Print(variables_, "if ($name$Builder_ == null) {\n"); - printer->Indent(); - printer->Print(variables_, regular_case); - printer->Outdent(); - printer->Print("} else {\n"); - printer->Indent(); - printer->Print(variables_, nested_builder_case); - printer->Outdent(); - printer->Print("}\n"); -} - -void ImmutableMessageFieldGenerator::PrintNestedBuilderFunction( + const char* nested_builder_case) const { + printer->Print(variables_, "if ($name$Builder_ == null) {\n"); + printer->Indent(); + printer->Print(variables_, regular_case); + printer->Outdent(); + printer->Print("} else {\n"); + printer->Indent(); + printer->Print(variables_, nested_builder_case); + printer->Outdent(); + printer->Print("}\n"); +} + +void ImmutableMessageFieldGenerator::PrintNestedBuilderFunction( io::Printer* printer, const char* method_prototype, const char* regular_case, const char* nested_builder_case, - const char* trailing_code) const { - printer->Print(variables_, method_prototype); + const char* trailing_code) const { + printer->Print(variables_, method_prototype); printer->Annotate("{", "}", descriptor_); - printer->Print(" {\n"); - printer->Indent(); - PrintNestedBuilderCondition(printer, regular_case, nested_builder_case); - if (trailing_code != NULL) { - printer->Print(variables_, trailing_code); - } - printer->Outdent(); - printer->Print("}\n"); -} - + printer->Print(" {\n"); + printer->Indent(); + PrintNestedBuilderCondition(printer, regular_case, nested_builder_case); + if (trailing_code != NULL) { + printer->Print(variables_, trailing_code); + } + printer->Outdent(); + printer->Print("}\n"); +} + void ImmutableMessageFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // 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. - + // 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_, + + printer->Print(variables_, // If this builder is non-null, it is used and the other fields // are ignored. "private com.google.protobuf.SingleFieldBuilder$ver$<\n" " $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;" "\n"); - - // The comments above the methods below are based on a hypothetical - // field of type "Field" called "Field". - - // boolean hasField() + + // The comments above the methods below are based on a hypothetical + // field of type "Field" called "Field". + + // boolean hasField() WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); if (has_hasbit) { printer->Print( @@ -282,60 +282,60 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " return $get_has_field_bit_builder$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } else { + } else { printer->Print( variables_, "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $name$Builder_ != null || $name$_ != null;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - - // Field getField() + } + + // Field getField() WriteFieldAccessorDocComment(printer, descriptor_, GETTER); PrintNestedBuilderFunction( printer, "$deprecation$public $type$ ${$get$capitalized_name$$}$()", "return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n", "return $name$Builder_.getMessage();\n", NULL); - - // Field.Builder setField(Field value) - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder setField(Field value) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value)", - + "if (value == null) {\n" " throw new NullPointerException();\n" "}\n" "$name$_ = value;\n" "$on_changed$\n", - + "$name$Builder_.setMessage(value);\n", - + "$set_has_field_bit_builder$\n" "return this;\n"); - - // Field.Builder setField(Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder setField(Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", - + "$name$_ = builderForValue.build();\n" "$on_changed$\n", - + "$name$Builder_.setMessage(builderForValue.build());\n", - + "$set_has_field_bit_builder$\n" "return this;\n"); - - // Field.Builder mergeField(Field value) - WriteFieldDocComment(printer, descriptor_); + + // Field.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" @@ -353,29 +353,29 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " $name$_ = value;\n" "}\n" "$on_changed$\n", - + "$name$Builder_.mergeFrom(value);\n", - + "$set_has_field_bit_builder$\n" "return this;\n"); - - // Field.Builder clearField() - WriteFieldDocComment(printer, descriptor_); + + // Field.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"); - - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public $type$.Builder " "${$get$capitalized_name$Builder$}$() {\n" " $set_has_field_bit_builder$\n" @@ -383,8 +383,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public $type$OrBuilder " "${$get$capitalized_name$OrBuilder$}$() {\n" " if ($name$Builder_ != null) {\n" @@ -395,7 +395,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "private com.google.protobuf.SingleFieldBuilder$ver$<\n" @@ -411,8 +411,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" " return $name$Builder_;\n" "}\n"); -} - +} + void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -443,35 +443,35 @@ void ImmutableMessageFieldGenerator::GenerateFieldBuilderInitializationCode( io::Printer* printer) const { if (HasHasbit(descriptor_)) { printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n"); - } -} - + } +} + void ImmutableMessageFieldGenerator::GenerateInitializationCode( io::Printer* printer) const {} - + 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 { + printer->Print(variables_, "$clear_has_field_bit_builder$\n"); + } else { PrintNestedBuilderCondition(printer, "$name$_ = null;\n", - + "$name$_ = null;\n" "$name$Builder_ = null;\n"); - } -} - + } +} + void ImmutableMessageFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if (other.has$capitalized_name$()) {\n" " merge$capitalized_name$(other.get$capitalized_name$());\n" "}\n"); -} - +} + void ImmutableMessageFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { if (HasHasbit(descriptor_)) { @@ -480,46 +480,46 @@ void ImmutableMessageFieldGenerator::GenerateBuildingCode( PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n", "result.$name$_ = $name$Builder_.build();\n"); printer->Outdent(); - printer->Print(variables_, + printer->Print(variables_, " $set_has_field_bit_to_local$;\n" "}\n"); } else { PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n", "result.$name$_ = $name$Builder_.build();\n"); - } -} - + } +} + void ImmutableMessageFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - printer->Print(variables_, + 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_, + + if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) { + printer->Print(variables_, "$name$_ = input.readGroup($number$, $type$.$get_parser$,\n" " extensionRegistry);\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "$name$_ = input.readMessage($type$.$get_parser$, " "extensionRegistry);\n"); - } - - printer->Print(variables_, + } + + 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. -} - + // noop for messages. +} + void ImmutableMessageFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { printer->Print( @@ -527,8 +527,8 @@ void ImmutableMessageFieldGenerator::GenerateSerializationCode( "if ($is_field_present_message$) {\n" " output.write$group_or_message$($number$, get$capitalized_name$());\n" "}\n"); -} - +} + void ImmutableMessageFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { printer->Print( @@ -537,45 +537,45 @@ void ImmutableMessageFieldGenerator::GenerateSerializedSizeCode( " size += com.google.protobuf.CodedOutputStream\n" " .compute$group_or_message$Size($number$, get$capitalized_name$());\n" "}\n"); -} - +} + void ImmutableMessageFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if (!get$capitalized_name$()\n" " .equals(other.get$capitalized_name$())) return false;\n"); -} - +} + void ImmutableMessageFieldGenerator::GenerateHashCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "hash = (37 * hash) + $constant_name$;\n" "hash = (53 * hash) + get$capitalized_name$().hashCode();\n"); -} - +} + TProtoStringType ImmutableMessageFieldGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->message_type()); -} - -// =================================================================== - + return name_resolver_->GetImmutableClassName(descriptor_->message_type()); +} + +// =================================================================== + ImmutableMessageOneofFieldGenerator::ImmutableMessageOneofFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : ImmutableMessageFieldGenerator(descriptor, messageBitIndex, builderBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + ImmutableMessageOneofFieldGenerator::~ImmutableMessageOneofFieldGenerator() {} - + void ImmutableMessageOneofFieldGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" @@ -591,9 +591,9 @@ void ImmutableMessageOneofFieldGenerator::GenerateMembers( " return $type$.getDefaultInstance();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$OrBuilder " "${$get$capitalized_name$OrBuilder$}$() {\n" @@ -603,23 +603,23 @@ void ImmutableMessageOneofFieldGenerator::GenerateMembers( " return $type$.getDefaultInstance();\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // 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. - printer->Print(variables_, + // 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. + printer->Print(variables_, // If this builder is non-null, it is used and the other fields // are ignored. "private com.google.protobuf.SingleFieldBuilder$ver$<\n" " $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;" "\n"); - - // The comments above the methods below are based on a hypothetical - // field of type "Field" called "Field". - + + // The comments above the methods below are based on a hypothetical + // field of type "Field" called "Field". + // boolean hasField() WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, @@ -628,64 +628,64 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field getField() + + // Field getField() WriteFieldAccessorDocComment(printer, descriptor_, GETTER); PrintNestedBuilderFunction( printer, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$()", - + "if ($has_oneof_case_message$) {\n" " return ($type$) $oneof_name$_;\n" "}\n" "return $type$.getDefaultInstance();\n", - + "if ($has_oneof_case_message$) {\n" " return $name$Builder_.getMessage();\n" "}\n" "return $type$.getDefaultInstance();\n", - + NULL); - - // Field.Builder setField(Field value) - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder setField(Field value) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value)", - + "if (value == null) {\n" " throw new NullPointerException();\n" "}\n" "$oneof_name$_ = value;\n" "$on_changed$\n", - + "$name$Builder_.setMessage(value);\n", - + "$set_oneof_case_message$;\n" "return this;\n"); - - // Field.Builder setField(Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder setField(Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", - + "$oneof_name$_ = builderForValue.build();\n" "$on_changed$\n", - + "$name$Builder_.setMessage(builderForValue.build());\n", - + "$set_oneof_case_message$;\n" "return this;\n"); - - // Field.Builder mergeField(Field value) - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder mergeField(Field value) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)", - + "if ($has_oneof_case_message$ &&\n" " $oneof_name$_ != $type$.getDefaultInstance()) {\n" " $oneof_name$_ = $type$.newBuilder(($type$) $oneof_name$_)\n" @@ -694,42 +694,42 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( " $oneof_name$_ = value;\n" "}\n" "$on_changed$\n", - + "if ($has_oneof_case_message$) {\n" " $name$Builder_.mergeFrom(value);\n" "}\n" "$name$Builder_.setMessage(value);\n", - + "$set_oneof_case_message$;\n" "return this;\n"); - - // Field.Builder clearField() - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder clearField() + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()", - + "if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" " $on_changed$\n" "}\n", - + "if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" "}\n" "$name$Builder_.clear();\n", - + "return this;\n"); - - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public $type$.Builder " "${$get$capitalized_name$Builder$}$() {\n" " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -745,7 +745,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "private com.google.protobuf.SingleFieldBuilder$ver$<\n" @@ -767,56 +767,56 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( " return $name$Builder_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableMessageOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { printer->Print(variables_, "if ($has_oneof_case_message$) {\n"); - printer->Indent(); - + printer->Indent(); + PrintNestedBuilderCondition( printer, "result.$oneof_name$_ = $oneof_name$_;\n", - + "result.$oneof_name$_ = $name$Builder_.build();\n"); - - printer->Outdent(); - printer->Print("}\n"); -} - + + printer->Outdent(); + printer->Print("}\n"); +} + void ImmutableMessageOneofFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "merge$capitalized_name$(other.get$capitalized_name$());\n"); -} - +} + void ImmutableMessageOneofFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - printer->Print(variables_, + 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) { + + if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) { printer->Print( variables_, "$oneof_name$_ = input.readGroup($number$, $type$.$get_parser$,\n" " extensionRegistry);\n"); - } else { + } else { printer->Print( variables_, "$oneof_name$_ =\n" " input.readMessage($type$.$get_parser$, extensionRegistry);\n"); - } - - printer->Print(variables_, + } + + 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( io::Printer* printer) const { printer->Print( @@ -824,8 +824,8 @@ void ImmutableMessageOneofFieldGenerator::GenerateSerializationCode( "if ($has_oneof_case_message$) {\n" " output.write$group_or_message$($number$, ($type$) $oneof_name$_);\n" "}\n"); -} - +} + void ImmutableMessageOneofFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { printer->Print( @@ -834,71 +834,71 @@ void ImmutableMessageOneofFieldGenerator::GenerateSerializedSizeCode( " size += com.google.protobuf.CodedOutputStream\n" " .compute$group_or_message$Size($number$, ($type$) $oneof_name$_);\n" "}\n"); -} - -// =================================================================== - +} + +// =================================================================== + 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_); -} - -RepeatedImmutableMessageFieldGenerator:: + SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +RepeatedImmutableMessageFieldGenerator:: ~RepeatedImmutableMessageFieldGenerator() {} - -int RepeatedImmutableMessageFieldGenerator::GetNumBitsForMessage() const { - return 0; -} - -int RepeatedImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { - return 1; -} - + +int RepeatedImmutableMessageFieldGenerator::GetNumBitsForMessage() const { + return 0; +} + +int RepeatedImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { + return 1; +} + void RepeatedImmutableMessageFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { - // TODO(jonp): In the future, consider having methods specific to the - // interface so that builders can choose dynamically to either return a - // message or a nested builder, so that asking for the interface doesn't - // cause a message to ever be built. - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + // TODO(jonp): In the future, consider having methods specific to the + // interface so that builders can choose dynamically to either return a + // message or a nested builder, so that asking for the interface doesn't + // cause a message to ever be built. + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$java.util.List<$type$> \n" " get$capitalized_name$List();\n"); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$(int index);\n"); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); - - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$java.util.List<? extends $type$OrBuilder> \n" " get$capitalized_name$OrBuilderList();\n"); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$$type$OrBuilder get$capitalized_name$OrBuilder(\n" " int index);\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private java.util.List<$type$> $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + PrintExtraFieldInfo(variables_, printer); + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<$type$> " "${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -907,7 +907,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -915,7 +915,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_.size();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -923,8 +923,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_.get(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$OrBuilder " "${$get$capitalized_name$OrBuilder$}$(\n" @@ -932,44 +932,44 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_.get(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - -void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderCondition( +} + +void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderCondition( io::Printer* printer, const char* regular_case, - const char* nested_builder_case) const { - printer->Print(variables_, "if ($name$Builder_ == null) {\n"); - printer->Indent(); - printer->Print(variables_, regular_case); - printer->Outdent(); - printer->Print("} else {\n"); - printer->Indent(); - printer->Print(variables_, nested_builder_case); - printer->Outdent(); - printer->Print("}\n"); -} - -void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderFunction( + const char* nested_builder_case) const { + printer->Print(variables_, "if ($name$Builder_ == null) {\n"); + printer->Indent(); + printer->Print(variables_, regular_case); + printer->Outdent(); + printer->Print("} else {\n"); + printer->Indent(); + printer->Print(variables_, nested_builder_case); + printer->Outdent(); + printer->Print("}\n"); +} + +void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderFunction( io::Printer* printer, const char* method_prototype, const char* regular_case, const char* nested_builder_case, - const char* trailing_code) const { - printer->Print(variables_, method_prototype); + const char* trailing_code) const { + printer->Print(variables_, method_prototype); printer->Annotate("{", "}", descriptor_); - printer->Print(" {\n"); - printer->Indent(); - PrintNestedBuilderCondition(printer, regular_case, nested_builder_case); - if (trailing_code != NULL) { - printer->Print(variables_, trailing_code); - } - printer->Outdent(); - printer->Print("}\n"); -} - + printer->Print(" {\n"); + printer->Indent(); + PrintNestedBuilderCondition(printer, regular_case, nested_builder_case); + if (trailing_code != NULL) { + printer->Print(variables_, trailing_code); + } + printer->Outdent(); + printer->Print("}\n"); +} + void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // 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. - + // 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. + printer->Print( variables_, // Used when the builder is null. @@ -984,7 +984,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( // list can never be modified. "private java.util.List<$type$> $name$_ =\n" " java.util.Collections.emptyList();\n" - + "private void ensure$capitalized_name$IsMutable() {\n" " if (!$get_mutable_bit_builder$) {\n" " $name$_ = new java.util.ArrayList<$type$>($name$_);\n" @@ -992,7 +992,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" "}\n" "\n"); - + printer->Print( variables_, // If this builder is non-null, it is used and the other fields are @@ -1000,45 +1000,45 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "private com.google.protobuf.RepeatedFieldBuilder$ver$<\n" " $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;\n" "\n"); - - // The comments above the methods below are based on a hypothetical - // repeated field of type "Field" called "RepeatedField". - - // List<Field> getRepeatedFieldList() - WriteFieldDocComment(printer, descriptor_); + + // The comments above the methods below are based on a hypothetical + // repeated field of type "Field" called "RepeatedField". + + // List<Field> getRepeatedFieldList() + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public java.util.List<$type$> " "${$get$capitalized_name$List$}$()", - + "return java.util.Collections.unmodifiableList($name$_);\n", "return $name$Builder_.getMessageList();\n", - + NULL); - - // int getRepeatedFieldCount() - WriteFieldDocComment(printer, descriptor_); + + // int getRepeatedFieldCount() + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public int ${$get$capitalized_name$Count$}$()", - + "return $name$_.size();\n", "return $name$Builder_.getCount();\n", - + NULL); - - // Field getRepeatedField(int index) - WriteFieldDocComment(printer, descriptor_); + + // Field getRepeatedField(int index) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index)", - + "return $name$_.get(index);\n", - + "return $name$Builder_.getMessage(index);\n", - + NULL); - - // Builder setRepeatedField(int index, Field value) - WriteFieldDocComment(printer, descriptor_); + + // Builder setRepeatedField(int index, Field value) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" @@ -1050,132 +1050,132 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "$name$_.set(index, value);\n" "$on_changed$\n", "$name$Builder_.setMessage(index, value);\n", "return this;\n"); - - // Builder setRepeatedField(int index, Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); + + // Builder setRepeatedField(int index, Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue)", - + "ensure$capitalized_name$IsMutable();\n" "$name$_.set(index, builderForValue.build());\n" "$on_changed$\n", - + "$name$Builder_.setMessage(index, builderForValue.build());\n", - + "return this;\n"); - - // Builder addRepeatedField(Field value) - WriteFieldDocComment(printer, descriptor_); + + // Builder addRepeatedField(Field value) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value)", - + "if (value == null) {\n" " throw new NullPointerException();\n" "}\n" "ensure$capitalized_name$IsMutable();\n" "$name$_.add(value);\n" - + "$on_changed$\n", - + "$name$Builder_.addMessage(value);\n", - + "return this;\n"); - - // Builder addRepeatedField(int index, Field value) - WriteFieldDocComment(printer, descriptor_); + + // Builder addRepeatedField(int index, Field value) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$ value)", - + "if (value == null) {\n" " throw new NullPointerException();\n" "}\n" "ensure$capitalized_name$IsMutable();\n" "$name$_.add(index, value);\n" "$on_changed$\n", - + "$name$Builder_.addMessage(index, value);\n", - + "return this;\n"); - - // Builder addRepeatedField(Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); + + // Builder addRepeatedField(Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", - + "ensure$capitalized_name$IsMutable();\n" "$name$_.add(builderForValue.build());\n" "$on_changed$\n", - + "$name$Builder_.addMessage(builderForValue.build());\n", - + "return this;\n"); - - // Builder addRepeatedField(int index, Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); + + // Builder addRepeatedField(int index, Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue)", - + "ensure$capitalized_name$IsMutable();\n" "$name$_.add(index, builderForValue.build());\n" "$on_changed$\n", - + "$name$Builder_.addMessage(index, builderForValue.build());\n", - + "return this;\n"); - - // Builder addAllRepeatedField(Iterable<Field> values) - WriteFieldDocComment(printer, descriptor_); + + // Builder addAllRepeatedField(Iterable<Field> values) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values)", - + "ensure$capitalized_name$IsMutable();\n" "com.google.protobuf.AbstractMessageLite.Builder.addAll(\n" " values, $name$_);\n" "$on_changed$\n", - + "$name$Builder_.addAllMessages(values);\n", - + "return this;\n"); - - // Builder clearAllRepeatedField() - WriteFieldDocComment(printer, descriptor_); + + // Builder clearAllRepeatedField() + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()", - + "$name$_ = java.util.Collections.emptyList();\n" "$clear_mutable_bit_builder$;\n" "$on_changed$\n", - + "$name$Builder_.clear();\n", - + "return this;\n"); - - // Builder removeRepeatedField(int index) - WriteFieldDocComment(printer, descriptor_); + + // Builder removeRepeatedField(int index) + WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$remove$capitalized_name$$}$(int index)", - + "ensure$capitalized_name$IsMutable();\n" "$name$_.remove(index);\n" "$on_changed$\n", - + "$name$Builder_.remove(index);\n", - + "return this;\n"); - - WriteFieldDocComment(printer, descriptor_); + + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$public $type$.Builder ${$get$capitalized_name$Builder$}$(\n" @@ -1183,8 +1183,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " return get$capitalized_name$FieldBuilder().getBuilder(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); + + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$OrBuilder " "${$get$capitalized_name$OrBuilder$}$(\n" @@ -1196,8 +1196,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); + + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$public java.util.List<? extends $type$OrBuilder> \n" @@ -1209,8 +1209,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); + + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$.Builder " "${$add$capitalized_name$Builder$}$() {\n" @@ -1218,7 +1218,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " $type$.getDefaultInstance());\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$public $type$.Builder ${$add$capitalized_name$Builder$}$(\n" @@ -1227,7 +1227,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " index, $type$.getDefaultInstance());\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$public java.util.List<$type$.Builder> \n" @@ -1250,34 +1250,34 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " return $name$Builder_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - -void RepeatedImmutableMessageFieldGenerator:: +} + +void RepeatedImmutableMessageFieldGenerator:: GenerateFieldBuilderInitializationCode(io::Printer* printer) const { printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = java.util.Collections.emptyList();\n"); -} - + printer->Print(variables_, "$name$_ = java.util.Collections.emptyList();\n"); +} + void RepeatedImmutableMessageFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - PrintNestedBuilderCondition(printer, + PrintNestedBuilderCondition(printer, "$name$_ = java.util.Collections.emptyList();\n" "$clear_mutable_bit_builder$;\n", - + "$name$Builder_.clear();\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - // The code below does two optimizations (non-nested builder case): - // 1. If the other list is empty, there's nothing to do. This ensures we - // don't allocate a new array if we already have an immutable one. - // 2. If the other list is non-empty and our current list is empty, we can - // reuse the other list which is guaranteed to be immutable. + // The code below does two optimizations (non-nested builder case): + // 1. If the other list is empty, there's nothing to do. This ensures we + // don't allocate a new array if we already have an immutable one. + // 2. If the other list is non-empty and our current list is empty, we can + // reuse the other list which is guaranteed to be immutable. PrintNestedBuilderCondition( printer, "if (!other.$name$_.isEmpty()) {\n" @@ -1290,7 +1290,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMergingCode( " }\n" " $on_changed$\n" "}\n", - + "if (!other.$name$_.isEmpty()) {\n" " if ($name$Builder_.isEmpty()) {\n" " $name$Builder_.dispose();\n" @@ -1305,13 +1305,13 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMergingCode( " $name$Builder_.addAllMessages(other.$name$_);\n" " }\n" "}\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - // The code below (non-nested builder case) ensures that the result has an - // immutable list. If our list is immutable, we can just reuse it. If not, - // we make it immutable. + // The code below (non-nested builder case) ensures that the result has an + // immutable list. If our list is immutable, we can just reuse it. If not, + // we make it immutable. PrintNestedBuilderCondition( printer, "if ($get_mutable_bit_builder$) {\n" @@ -1319,31 +1319,31 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuildingCode( " $clear_mutable_bit_builder$;\n" "}\n" "result.$name$_ = $name$_;\n", - + "result.$name$_ = $name$Builder_.build();\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - printer->Print(variables_, + 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) { + + if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) { printer->Print( variables_, "$name$_.add(input.readGroup($number$, $type$.$get_parser$,\n" " extensionRegistry));\n"); - } else { + } else { printer->Print( variables_, "$name$_.add(\n" " input.readMessage($type$.$get_parser$, extensionRegistry));\n"); - } -} - + } +} + void RepeatedImmutableMessageFieldGenerator::GenerateParsingDoneCode( io::Printer* printer) const { printer->Print( @@ -1351,16 +1351,16 @@ void RepeatedImmutableMessageFieldGenerator::GenerateParsingDoneCode( "if ($get_mutable_bit_parser$) {\n" " $name$_ = java.util.Collections.unmodifiableList($name$_);\n" "}\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "for (int i = 0; i < $name$_.size(); i++) {\n" " output.write$group_or_message$($number$, $name$_.get(i));\n" "}\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { printer->Print( @@ -1369,16 +1369,16 @@ void RepeatedImmutableMessageFieldGenerator::GenerateSerializedSizeCode( " size += com.google.protobuf.CodedOutputStream\n" " .compute$group_or_message$Size($number$, $name$_.get(i));\n" "}\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { printer->Print( variables_, "if (!get$capitalized_name$List()\n" " .equals(other.get$capitalized_name$List())) return false;\n"); -} - +} + void RepeatedImmutableMessageFieldGenerator::GenerateHashCode( io::Printer* printer) const { printer->Print( @@ -1387,12 +1387,12 @@ void RepeatedImmutableMessageFieldGenerator::GenerateHashCode( " hash = (37 * hash) + $constant_name$;\n" " hash = (53 * hash) + get$capitalized_name$List().hashCode();\n" "}\n"); -} - +} + TProtoStringType RepeatedImmutableMessageFieldGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->message_type()); -} - + return name_resolver_->GetImmutableClassName(descriptor_->message_type()); +} + void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -1485,7 +1485,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "}"); } -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.h index 2716498328..94a215577f 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field.h @@ -1,46 +1,46 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ - -#include <map> +// 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. + +#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/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,88 +49,88 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { - public: +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { + public: explicit ImmutableMessageFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); - ~ImmutableMessageFieldGenerator(); - + ~ImmutableMessageFieldGenerator(); + // implements ImmutableFieldGenerator // --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateParsingDoneCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateParsingDoneCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; void GenerateKotlinDslMembers(io::Printer* printer) const; - + TProtoStringType GetBoxedType() const; - - protected: - const FieldDescriptor* descriptor_; + + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - void PrintNestedBuilderCondition(io::Printer* printer, + ClassNameResolver* name_resolver_; + + void PrintNestedBuilderCondition(io::Printer* printer, const char* regular_case, const char* nested_builder_case) const; - void PrintNestedBuilderFunction(io::Printer* printer, + 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); -}; - -class ImmutableMessageOneofFieldGenerator - : public ImmutableMessageFieldGenerator { - public: + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageFieldGenerator); +}; + +class ImmutableMessageOneofFieldGenerator + : public ImmutableMessageFieldGenerator { + public: ImmutableMessageOneofFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); - ~ImmutableMessageOneofFieldGenerator(); - - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldGenerator); -}; - -class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { - public: - explicit RepeatedImmutableMessageFieldGenerator( - const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, Context* context); + ~ImmutableMessageOneofFieldGenerator(); + + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldGenerator); +}; + +class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { + public: + explicit RepeatedImmutableMessageFieldGenerator( + const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, Context* context); ~RepeatedImmutableMessageFieldGenerator() override; - - // implements ImmutableFieldGenerator --------------------------------------- + + // implements ImmutableFieldGenerator --------------------------------------- int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -149,30 +149,30 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const override; void GenerateHashCode(io::Printer* printer) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - protected: - const FieldDescriptor* descriptor_; + + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - void PrintNestedBuilderCondition(io::Printer* printer, + ClassNameResolver* name_resolver_; + + void PrintNestedBuilderCondition(io::Printer* printer, const char* regular_case, const char* nested_builder_case) const; - void PrintNestedBuilderFunction(io::Printer* printer, + 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); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableMessageFieldGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.cc index f36555f00c..0de4dbe0f8 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.cc @@ -1,43 +1,43 @@ -// 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. - +// 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/java_message_field_lite.h> #include <cstdint> -#include <map> +#include <map> #include <string> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_helpers.h> @@ -45,30 +45,30 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { + void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - - (*variables)["type"] = - name_resolver->GetImmutableClassName(descriptor->message_type()); + SetCommonFieldVariables(descriptor, info, variables); + + (*variables)["type"] = + name_resolver->GetImmutableClassName(descriptor->message_type()); (*variables)["kt_type"] = (*variables)["type"]; - (*variables)["mutable_type"] = - name_resolver->GetMutableClassName(descriptor->message_type()); - (*variables)["group_or_message"] = + (*variables)["mutable_type"] = + name_resolver->GetMutableClassName(descriptor->message_type()); + (*variables)["group_or_message"] = (GetType(descriptor) == FieldDescriptor::TYPE_GROUP) ? "Group" : "Message"; - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + // 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"] = @@ -77,40 +77,40 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, " is deprecated\") " : ""; (*variables)["required"] = descriptor->is_required() ? "true" : "false"; - + if (HasHasbit(descriptor)) { - // 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) + ";"; - (*variables)["clear_has_field_bit_message"] = - 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)["get_has_field_bit_from_local"] = - GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); + // 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) + ";"; + (*variables)["clear_has_field_bit_message"] = + 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)["get_has_field_bit_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(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"; -} - -} // namespace - -// =================================================================== - +} + +} // namespace + +// =================================================================== + ImmutableMessageFieldLiteGenerator::ImmutableMessageFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), @@ -119,34 +119,34 @@ ImmutableMessageFieldLiteGenerator::ImmutableMessageFieldLiteGenerator( SetMessageVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); -} - -ImmutableMessageFieldLiteGenerator::~ImmutableMessageFieldLiteGenerator() {} - -int ImmutableMessageFieldLiteGenerator::GetNumBitsForMessage() const { +} + +ImmutableMessageFieldLiteGenerator::~ImmutableMessageFieldLiteGenerator() {} + +int ImmutableMessageFieldLiteGenerator::GetNumBitsForMessage() const { // TODO(dweis): We don't need a has bit for messages as they have null // sentinels and no user should be reflecting on this. We could save some // bits by setting to 0 and updating the runtimes but this might come at a // runtime performance cost since we can't memoize has-bit reads. return HasHasbit(descriptor_) ? 1 : 0; -} - +} + void ImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); -} - +} + void ImmutableMessageFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - + printer->Print(variables_, "private $type$ $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); - + PrintExtraFieldInfo(variables_, printer); + if (HasHasbit(descriptor_)) { - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -154,7 +154,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -162,8 +162,8 @@ void ImmutableMessageFieldLiteGenerator::GenerateMembers( " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } else { - WriteFieldDocComment(printer, descriptor_); + } else { + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -171,7 +171,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateMembers( " return $name$_ != null;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -179,19 +179,19 @@ void ImmutableMessageFieldLiteGenerator::GenerateMembers( " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - - // Field.Builder setField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + } + + // Field.Builder setField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void set$capitalized_name$($type$ value) {\n" " $null_check$" " $name$_ = value;\n" " $set_has_field_bit_message$\n" " }\n"); - - // Field.Builder mergeField(Field value) - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder mergeField(Field value) + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.SuppressWarnings({\"ReferenceEquality\"})\n" @@ -206,42 +206,42 @@ void ImmutableMessageFieldLiteGenerator::GenerateMembers( " }\n" " $set_has_field_bit_message$\n" "}\n"); - - // Field.Builder clearField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder clearField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void clear$capitalized_name$() {" " $name$_ = null;\n" " $clear_has_field_bit_message$\n" "}\n"); -} - +} + void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // The comments above the methods below are based on a hypothetical - // field of type "Field" called "Field". - - // boolean hasField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + // The comments above the methods below are based on a hypothetical + // field of type "Field" called "Field". + + // boolean hasField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field getField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field getField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder setField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder setField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -249,10 +249,10 @@ void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" " }\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder setField(Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder setField(Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue) {\n" " copyOnWrite();\n" @@ -260,10 +260,10 @@ void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder mergeField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder mergeField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder " "${$merge$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -271,18 +271,18 @@ void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder clearField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder clearField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$clear$capitalized_name$$}$() {" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -316,37 +316,37 @@ void ImmutableMessageFieldLiteGenerator::GenerateFieldInfo( output); if (HasHasbit(descriptor_)) { WriteIntToUtf16CharSequence(messageBitIndex_, output); - } + } printer->Print(variables_, "\"$name$_\",\n"); -} - +} + void ImmutableMessageFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const {} - + TProtoStringType ImmutableMessageFieldLiteGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->message_type()); -} - -// =================================================================== - -ImmutableMessageOneofFieldLiteGenerator:: + return name_resolver_->GetImmutableClassName(descriptor_->message_type()); +} + +// =================================================================== + +ImmutableMessageOneofFieldLiteGenerator:: ImmutableMessageOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : ImmutableMessageFieldLiteGenerator(descriptor, messageBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - -ImmutableMessageOneofFieldLiteGenerator:: + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + +ImmutableMessageOneofFieldLiteGenerator:: ~ImmutableMessageOneofFieldLiteGenerator() {} - + void ImmutableMessageOneofFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + PrintExtraFieldInfo(variables_, printer); + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" @@ -362,18 +362,18 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateMembers( " return $type$.getDefaultInstance();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder setField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder setField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void set$capitalized_name$($type$ value) {\n" " $null_check$" " $oneof_name$_ = value;\n" " $set_oneof_case_message$;\n" "}\n"); - - // Field.Builder mergeField(Field value) - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder mergeField(Field value) + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "private void merge$capitalized_name$($type$ value) {\n" @@ -387,18 +387,18 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateMembers( " }\n" " $set_oneof_case_message$;\n" "}\n"); - - // Field.Builder clearField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder clearField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" " }\n" "}\n"); -} - +} + void ImmutableMessageOneofFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); @@ -410,9 +410,9 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateFieldInfo( void ImmutableMessageOneofFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // The comments above the methods below are based on a hypothetical - // field of type "Field" called "Field". - + // The comments above the methods below are based on a hypothetical + // field of type "Field" called "Field". + // boolean hasField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, @@ -421,19 +421,19 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateBuilderMembers( " return instance.has$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field getField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field getField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder setField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder setField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -441,10 +441,10 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder setField(Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder setField(Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue) {\n" " copyOnWrite();\n" @@ -452,10 +452,10 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder mergeField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Field.Builder mergeField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder " "${$merge$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -463,9 +463,9 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Field.Builder clearField() - WriteFieldDocComment(printer, descriptor_); + + // Field.Builder clearField() + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" @@ -474,60 +474,60 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - -// =================================================================== - -RepeatedImmutableMessageFieldLiteGenerator:: +} + +// =================================================================== + +RepeatedImmutableMessageFieldLiteGenerator:: RepeatedImmutableMessageFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { SetMessageVariables(descriptor, messageBitIndex, 0, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_); -} - -RepeatedImmutableMessageFieldLiteGenerator:: + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +RepeatedImmutableMessageFieldLiteGenerator:: ~RepeatedImmutableMessageFieldLiteGenerator() {} - -int RepeatedImmutableMessageFieldLiteGenerator::GetNumBitsForMessage() const { - return 0; -} - + +int RepeatedImmutableMessageFieldLiteGenerator::GetNumBitsForMessage() const { + return 0; +} + void RepeatedImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { - // TODO(jonp): In the future, consider having methods specific to the - // interface so that builders can choose dynamically to either return a - // message or a nested builder, so that asking for the interface doesn't - // cause a message to ever be built. - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + // TODO(jonp): In the future, consider having methods specific to the + // interface so that builders can choose dynamically to either return a + // message or a nested builder, so that asking for the interface doesn't + // cause a message to ever be built. + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$java.util.List<$type$> \n" " get$capitalized_name$List();\n"); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$(int index);\n"); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); -} - +} + void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { printer->Print( variables_, "private com.google.protobuf.Internal.ProtobufList<$type$> $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + PrintExtraFieldInfo(variables_, printer); + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<$type$> " "${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$public java.util.List<? extends $type$OrBuilder> \n" @@ -535,7 +535,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers( " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -543,7 +543,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers( " return $name$_.size();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -551,15 +551,15 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers( " return $name$_.get(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public $type$OrBuilder " "${$get$capitalized_name$OrBuilder$}$(\n" " int index) {\n" " return $name$_.get(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + printer->Print( variables_, "private void ensure$capitalized_name$IsMutable() {\n" @@ -571,70 +571,70 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers( " }\n" "}\n" "\n"); - - // Builder setRepeatedField(int index, Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder setRepeatedField(int index, Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void set$capitalized_name$(\n" " int index, $type$ value) {\n" " $null_check$" " ensure$capitalized_name$IsMutable();\n" " $name$_.set(index, value);\n" "}\n"); - - // Builder addRepeatedField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder addRepeatedField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void add$capitalized_name$($type$ value) {\n" " $null_check$" " ensure$capitalized_name$IsMutable();\n" " $name$_.add(value);\n" "}\n"); - - // Builder addRepeatedField(int index, Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder addRepeatedField(int index, Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void add$capitalized_name$(\n" " int index, $type$ value) {\n" " $null_check$" " ensure$capitalized_name$IsMutable();\n" " $name$_.add(index, value);\n" "}\n"); - - // Builder addAllRepeatedField(Iterable<Field> values) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder addAllRepeatedField(Iterable<Field> values) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void addAll$capitalized_name$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " ensure$capitalized_name$IsMutable();\n" " com.google.protobuf.AbstractMessageLite.addAll(\n" " values, $name$_);\n" "}\n"); - - // Builder clearAllRepeatedField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder clearAllRepeatedField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " $name$_ = emptyProtobufList();\n" "}\n"); - - // Builder removeRepeatedField(int index) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder removeRepeatedField(int index) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "private void remove$capitalized_name$(int index) {\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.remove(index);\n" "}\n"); -} - +} + void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // The comments above the methods below are based on a hypothetical - // repeated field of type "Field" called "RepeatedField". - - // List<Field> getRepeatedFieldList() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + // The comments above the methods below are based on a hypothetical + // repeated field of type "Field" called "RepeatedField". + + // List<Field> getRepeatedFieldList() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<$type$> " "${$get$capitalized_name$List$}$() {\n" @@ -642,9 +642,9 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " instance.get$capitalized_name$List());\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // int getRepeatedFieldCount() - WriteFieldDocComment(printer, descriptor_); + + // int getRepeatedFieldCount() + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -652,9 +652,9 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return instance.get$capitalized_name$Count();\n" "}"); printer->Annotate("{", "}", descriptor_); - - // Field getRepeatedField(int index) - WriteFieldDocComment(printer, descriptor_); + + // Field getRepeatedField(int index) + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" @@ -662,10 +662,10 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return instance.get$capitalized_name$(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder setRepeatedField(int index, Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder setRepeatedField(int index, Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" @@ -673,10 +673,10 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder setRepeatedField(int index, Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder setRepeatedField(int index, Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue) {\n" " copyOnWrite();\n" @@ -685,10 +685,10 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder addRepeatedField(Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder addRepeatedField(Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -696,10 +696,10 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder addRepeatedField(int index, Field value) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder addRepeatedField(int index, Field value) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" @@ -707,9 +707,9 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - // Builder addRepeatedField(Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + // Builder addRepeatedField(Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " $type$.Builder builderForValue) {\n" " copyOnWrite();\n" @@ -717,10 +717,10 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder addRepeatedField(int index, Field.Builder builderForValue) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder addRepeatedField(int index, Field.Builder builderForValue) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue) {\n" " copyOnWrite();\n" @@ -729,10 +729,10 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder addAllRepeatedField(Iterable<Field> values) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder addAllRepeatedField(Iterable<Field> values) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " copyOnWrite();\n" @@ -740,9 +740,9 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder clearAllRepeatedField() - WriteFieldDocComment(printer, descriptor_); + + // Builder clearAllRepeatedField() + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" @@ -751,10 +751,10 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - - // Builder removeRepeatedField(int index) - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, + + // Builder removeRepeatedField(int index) + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, "$deprecation$public Builder " "${$remove$capitalized_name$$}$(int index) {\n" " copyOnWrite();\n" @@ -762,27 +762,27 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void RepeatedImmutableMessageFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); - printer->Print(variables_, + printer->Print(variables_, "\"$name$_\",\n" "$type$.class,\n"); -} - +} + void RepeatedImmutableMessageFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = emptyProtobufList();\n"); -} - + printer->Print(variables_, "$name$_ = emptyProtobufList();\n"); +} + TProtoStringType RepeatedImmutableMessageFieldLiteGenerator::GetBoxedType() const { - return name_resolver_->GetImmutableClassName(descriptor_->message_type()); -} - + return name_resolver_->GetImmutableClassName(descriptor_->message_type()); +} + void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -875,7 +875,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "}"); } -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.h index 22a12ce857..571347f197 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_field_lite.h @@ -1,48 +1,48 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ + #include <cstdint> -#include <map> +#include <map> #include <string> #include <google/protobuf/compiler/java/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -51,67 +51,67 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { - public: +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { + public: explicit ImmutableMessageFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ~ImmutableMessageFieldLiteGenerator(); - + ~ImmutableMessageFieldLiteGenerator(); + // implements ImmutableFieldLiteGenerator // ------------------------------------ - int GetNumBitsForMessage() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; + int GetNumBitsForMessage() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const; void GenerateKotlinDslMembers(io::Printer* printer) const; - + TProtoStringType GetBoxedType() const; - - protected: - const FieldDescriptor* descriptor_; + + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - const int messageBitIndex_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageFieldLiteGenerator); -}; - -class ImmutableMessageOneofFieldLiteGenerator - : public ImmutableMessageFieldLiteGenerator { - public: + const int messageBitIndex_; + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageFieldLiteGenerator); +}; + +class ImmutableMessageOneofFieldLiteGenerator + : public ImmutableMessageFieldLiteGenerator { + public: ImmutableMessageOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ~ImmutableMessageOneofFieldLiteGenerator(); - - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; + ~ImmutableMessageOneofFieldLiteGenerator(); + + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldLiteGenerator); -}; - -class RepeatedImmutableMessageFieldLiteGenerator - : public ImmutableFieldLiteGenerator { - public: - explicit RepeatedImmutableMessageFieldLiteGenerator( + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldLiteGenerator); +}; + +class RepeatedImmutableMessageFieldLiteGenerator + : public ImmutableFieldLiteGenerator { + public: + explicit RepeatedImmutableMessageFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~RepeatedImmutableMessageFieldLiteGenerator() override; - - // implements ImmutableFieldLiteGenerator ------------------------------------ + + // implements ImmutableFieldLiteGenerator ------------------------------------ int GetNumBitsForMessage() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; void GenerateMembers(io::Printer* printer) const override; @@ -120,21 +120,21 @@ class RepeatedImmutableMessageFieldLiteGenerator void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - protected: - const FieldDescriptor* descriptor_; + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableMessageFieldLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableMessageFieldLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.cc index bec5a7f47c..74a54def04 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.cc @@ -1,45 +1,45 @@ -// 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: dweis@google.com (Daniel Weis) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - +// 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: dweis@google.com (Daniel Weis) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + #include <google/protobuf/compiler/java/java_message_lite.h> - -#include <algorithm> + +#include <algorithm> #include <cstdint> -#include <map> -#include <memory> -#include <vector> - +#include <map> +#include <memory> +#include <vector> + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_enum_lite.h> @@ -55,86 +55,86 @@ #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -using internal::WireFormat; -using internal::WireFormatLite; - -// =================================================================== -ImmutableMessageLiteGenerator::ImmutableMessageLiteGenerator( - const Descriptor* descriptor, Context* context) + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +using internal::WireFormat; +using internal::WireFormatLite; + +// =================================================================== +ImmutableMessageLiteGenerator::ImmutableMessageLiteGenerator( + const Descriptor* descriptor, Context* context) : MessageGenerator(descriptor), context_(context), name_resolver_(context->GetNameResolver()), field_generators_(descriptor, context_) { - GOOGLE_CHECK(!HasDescriptorMethods(descriptor->file(), context->EnforceLite())) - << "Generator factory error: A lite message generator is used to " - "generate non-lite messages."; + GOOGLE_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()); } } -} - -ImmutableMessageLiteGenerator::~ImmutableMessageLiteGenerator() {} - -void ImmutableMessageLiteGenerator::GenerateStaticVariables( - io::Printer* printer, int* bytecode_estimate) { - // Generate static members for all nested types. - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // TODO(kenton): Reuse MessageGenerator objects? - ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) - .GenerateStaticVariables(printer, bytecode_estimate); - } -} - -int ImmutableMessageLiteGenerator::GenerateStaticVariableInitializers( - io::Printer* printer) { - int bytecode_estimate = 0; - // Generate static member initializers for all nested types. - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // TODO(kenton): Reuse MessageGenerator objects? - bytecode_estimate += - ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) - .GenerateStaticVariableInitializers(printer); - } - return bytecode_estimate; -} - -// =================================================================== - -void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { - MaybePrintGeneratedAnnotation(context_, printer, descriptor_, - /* immutable = */ true, "OrBuilder"); - if (descriptor_->extension_range_count() > 0) { - printer->Print( +} + +ImmutableMessageLiteGenerator::~ImmutableMessageLiteGenerator() {} + +void ImmutableMessageLiteGenerator::GenerateStaticVariables( + io::Printer* printer, int* bytecode_estimate) { + // Generate static members for all nested types. + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + // TODO(kenton): Reuse MessageGenerator objects? + ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) + .GenerateStaticVariables(printer, bytecode_estimate); + } +} + +int ImmutableMessageLiteGenerator::GenerateStaticVariableInitializers( + io::Printer* printer) { + int bytecode_estimate = 0; + // Generate static member initializers for all nested types. + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + // TODO(kenton): Reuse MessageGenerator objects? + bytecode_estimate += + ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) + .GenerateStaticVariableInitializers(printer); + } + return bytecode_estimate; +} + +// =================================================================== + +void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { + MaybePrintGeneratedAnnotation(context_, printer, descriptor_, + /* immutable = */ true, "OrBuilder"); + if (descriptor_->extension_range_count() > 0) { + printer->Print( "$deprecation$public interface ${$$classname$OrBuilder$}$ extends \n" - " $extra_interfaces$\n" - " com.google.protobuf.GeneratedMessageLite.\n" - " ExtendableMessageOrBuilder<\n" - " $classname$, $classname$.Builder> {\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_), + "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), "{", "", "}", ""); - } else { - printer->Print( + } else { + printer->Print( "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" - " $extra_interfaces$\n" - " com.google.protobuf.MessageLiteOrBuilder {\n", + " $extra_interfaces$\n" + " com.google.protobuf.MessageLiteOrBuilder {\n", "deprecation", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", - "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), + "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), "{", "", "}", ""); - } + } printer->Annotate("{", "}", descriptor_); - - printer->Indent(); + + printer->Indent(); for (int i = 0; i < descriptor_->field_count(); i++) { printer->Print("\n"); field_generators_.get(descriptor_->field(i)) @@ -149,31 +149,31 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname", context_->GetNameResolver()->GetImmutableClassName(descriptor_)); } - printer->Outdent(); - - printer->Print("}\n"); -} - -// =================================================================== - -void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { - bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - + printer->Outdent(); + + printer->Print("}\n"); +} + +// =================================================================== + +void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { + bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); + std::map<TProtoStringType, TProtoStringType> variables; - variables["static"] = is_own_file ? " " : " static "; - variables["classname"] = descriptor_->name(); - variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); + variables["static"] = is_own_file ? " " : " static "; + variables["classname"] = descriptor_->name(); + variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["deprecation"] = descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""; + + WriteMessageDocComment(printer, descriptor_); + MaybePrintGeneratedAnnotation(context_, printer, descriptor_, + /* immutable = */ true); + - WriteMessageDocComment(printer, descriptor_); - MaybePrintGeneratedAnnotation(context_, printer, descriptor_, - /* immutable = */ true); - - - // The builder_type stores the super type name of the nested Builder class. + // The builder_type stores the super type name of the nested Builder class. TProtoStringType builder_type; - if (descriptor_->extension_range_count() > 0) { + if (descriptor_->extension_range_count() > 0) { printer->Print( variables, "$deprecation$public $static$final class $classname$ extends\n" @@ -181,71 +181,71 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { " $classname$, $classname$.Builder> implements\n" " $extra_interfaces$\n" " $classname$OrBuilder {\n"); - builder_type = strings::Substitute( - "com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>", - name_resolver_->GetImmutableClassName(descriptor_)); - } else { + builder_type = strings::Substitute( + "com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>", + name_resolver_->GetImmutableClassName(descriptor_)); + } else { printer->Print( variables, "$deprecation$public $static$final class $classname$ extends\n" - " com.google.protobuf.GeneratedMessageLite<\n" - " $classname$, $classname$.Builder> implements\n" - " $extra_interfaces$\n" - " $classname$OrBuilder {\n"); - - builder_type = "com.google.protobuf.GeneratedMessageLite.Builder"; - } - printer->Indent(); - - GenerateConstructor(printer); - - // Nested types - for (int i = 0; i < descriptor_->enum_type_count(); i++) { - EnumLiteGenerator(descriptor_->enum_type(i), true, context_) - .Generate(printer); - } - - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // Don't generate Java classes for map entry messages. - if (IsMapEntry(descriptor_->nested_type(i))) continue; + " com.google.protobuf.GeneratedMessageLite<\n" + " $classname$, $classname$.Builder> implements\n" + " $extra_interfaces$\n" + " $classname$OrBuilder {\n"); + + builder_type = "com.google.protobuf.GeneratedMessageLite.Builder"; + } + printer->Indent(); + + GenerateConstructor(printer); + + // Nested types + for (int i = 0; i < descriptor_->enum_type_count(); i++) { + EnumLiteGenerator(descriptor_->enum_type(i), true, context_) + .Generate(printer); + } + + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + // Don't generate Java classes for map entry messages. + if (IsMapEntry(descriptor_->nested_type(i))) continue; ImmutableMessageLiteGenerator messageGenerator(descriptor_->nested_type(i), context_); - messageGenerator.GenerateInterface(printer); - messageGenerator.Generate(printer); - } - + messageGenerator.GenerateInterface(printer); + messageGenerator.Generate(printer); + } + // Integers for bit fields. int totalBits = 0; for (int i = 0; i < descriptor_->field_count(); i++) { totalBits += field_generators_.get(descriptor_->field(i)).GetNumBitsForMessage(); - } + } int totalInts = (totalBits + 31) / 32; for (int i = 0; i < totalInts; i++) { printer->Print("private int $bit_field_name$;\n", "bit_field_name", GetBitFieldName(i)); } - - // oneof + + // oneof std::map<TProtoStringType, TProtoStringType> vars; for (auto oneof : oneofs_) { 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, + // oneofCase_ and oneof_ + printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" "private java.lang.Object $oneof_name$_;\n"); - // OneofCase enum + // OneofCase enum printer->Print(vars, "public enum $oneof_capitalized_name$Case {\n"); - printer->Indent(); + 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())); - } + } printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name", ToUpper(vars["oneof_name"])); printer->Print(vars, @@ -253,7 +253,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { "private $oneof_capitalized_name$Case(int value) {\n" " this.value = value;\n" "}\n"); - printer->Print( + printer->Print( vars, "/**\n" " * @deprecated Use {@link #forNumber(int)} instead.\n" @@ -270,8 +270,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { printer->Print(" case $field_number$: return $field_name$;\n", "field_number", StrCat(field->number()), "field_name", ToUpper(field->name())); - } - printer->Print( + } + printer->Print( " case 0: return $cap_oneof_name$_NOT_SET;\n" " default: return null;\n" " }\n" @@ -282,10 +282,10 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { " return this.value;\n" "}\n", "cap_oneof_name", ToUpper(vars["oneof_name"])); - printer->Outdent(); - printer->Print("};\n\n"); - // oneofCase() - printer->Print(vars, + 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" @@ -298,28 +298,28 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { " $oneof_name$_ = null;\n" "}\n" "\n"); - } - - // Fields - for (int i = 0; i < descriptor_->field_count(); i++) { - printer->Print("public static final int $constant_name$ = $number$;\n", + } + + // 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())); - field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); - printer->Print("\n"); - } - - GenerateParseFromMethods(printer); - GenerateBuilder(printer); - - if (HasRequiredFields(descriptor_)) { - // Memoizes whether the protocol buffer is fully initialized (has all + field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); + printer->Print("\n"); + } + + GenerateParseFromMethods(printer); + GenerateBuilder(printer); + + if (HasRequiredFields(descriptor_)) { + // Memoizes whether the protocol buffer is fully initialized (has all // required fields). 0 means false, 1 means true, and all other values // mean not yet computed. printer->Print("private byte memoizedIsInitialized = 2;\n"); - } - - printer->Print( + } + + printer->Print( "@java.lang.Override\n" "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n" "protected final java.lang.Object dynamicMethod(\n" @@ -330,25 +330,25 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { " return new $classname$();\n" " }\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Indent(); - printer->Indent(); - + + printer->Indent(); + printer->Indent(); + printer->Print("case NEW_BUILDER: {\n"); - - printer->Indent(); - GenerateDynamicMethodNewBuilder(printer); - printer->Outdent(); - - printer->Print( + + printer->Indent(); + GenerateDynamicMethodNewBuilder(printer); + printer->Outdent(); + + printer->Print( "}\n" "case BUILD_MESSAGE_INFO: {\n"); - - printer->Indent(); + + printer->Indent(); GenerateDynamicMethodNewBuildMessageInfo(printer); - printer->Outdent(); - - printer->Print( + printer->Outdent(); + + printer->Print( "}\n" "// fall through\n" "case GET_DEFAULT_INSTANCE: {\n" @@ -376,9 +376,9 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { " }\n" " return parser;\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Outdent(); - + + printer->Outdent(); + if (HasRequiredFields(descriptor_)) { printer->Print( "}\n" @@ -399,27 +399,27 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { " return null;\n" "}\n"); } - - printer->Outdent(); - printer->Print( + + printer->Outdent(); + printer->Print( " }\n" " throw new UnsupportedOperationException();\n" "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Print( + + printer->Print( "\n" "// @@protoc_insertion_point(class_scope:$full_name$)\n", "full_name", descriptor_->full_name()); - - // Carefully initialize the default instance in such a way that it doesn't - // conflict with other initialization. + + // Carefully initialize the default instance in such a way that it doesn't + // conflict with other initialization. printer->Print("private static final $classname$ DEFAULT_INSTANCE;\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - printer->Print( + printer->Print( "static {\n" " $classname$ defaultInstance = new $classname$();\n" " // New instances are implicitly immutable so no need to make\n" @@ -433,14 +433,14 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { "}\n" "\n", "classname", descriptor_->name()); - - printer->Print( - "public static $classname$ getDefaultInstance() {\n" - " return DEFAULT_INSTANCE;\n" - "}\n" - "\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); - + + printer->Print( + "public static $classname$ getDefaultInstance() {\n" + " return DEFAULT_INSTANCE;\n" + "}\n" + "\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + // 'of' method for Wrappers if (IsWrappersProtoFile(descriptor_->file())) { printer->Print( @@ -452,38 +452,38 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { "field_type", PrimitiveTypeName(GetJavaType(descriptor_->field(0)))); } - GenerateParser(printer); - - // Extensions must be declared after the DEFAULT_INSTANCE is initialized - // because the DEFAULT_INSTANCE is used by the extension to lazily retrieve - // the outer class's FileDescriptor. - for (int i = 0; i < descriptor_->extension_count(); i++) { - ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_) - .Generate(printer); - } - - printer->Outdent(); - printer->Print("}\n\n"); -} - + GenerateParser(printer); + + // Extensions must be declared after the DEFAULT_INSTANCE is initialized + // because the DEFAULT_INSTANCE is used by the extension to lazily retrieve + // the outer class's FileDescriptor. + for (int i = 0; i < descriptor_->extension_count(); i++) { + ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_) + .Generate(printer); + } + + printer->Outdent(); + printer->Print("}\n\n"); +} + void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( io::Printer* printer) { printer->Indent(); - + // Collect field info into a sequence of UTF-16 chars. It will be embedded // as a Java string in the generated code. std::vector<uint16_t> chars; - + int flags = 0; if (IsProto2(descriptor_->file())) { flags |= 0x1; - } + } if (descriptor_->options().message_set_wire_format()) { flags |= 0x2; - } + } WriteIntToUtf16CharSequence(flags, &chars); WriteIntToUtf16CharSequence(descriptor_->field_count(), &chars); - + if (descriptor_->field_count() == 0) { printer->Print("java.lang.Object[] objects = null;"); } else { @@ -494,25 +494,25 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( // Record the number of oneofs. WriteIntToUtf16CharSequence(oneofs_.size(), &chars); for (auto oneof : oneofs_) { - printer->Print( + printer->Print( "\"$oneof_name$_\",\n" "\"$oneof_name$Case_\",\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); - } - + } + // Integers for bit fields. int total_bits = 0; for (int i = 0; i < descriptor_->field_count(); i++) { total_bits += field_generators_.get(descriptor_->field(i)).GetNumBitsForMessage(); - } + } int total_ints = (total_bits + 31) / 32; for (int i = 0; i < total_ints; i++) { printer->Print("\"$bit_field_name$\",\n", "bit_field_name", GetBitFieldName(i)); } WriteIntToUtf16CharSequence(total_ints, &chars); - + int map_count = 0; int repeated_count = 0; std::unique_ptr<const FieldDescriptor*[]> sorted_fields( @@ -525,14 +525,14 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( repeated_count++; } } - + WriteIntToUtf16CharSequence(sorted_fields[0]->number(), &chars); WriteIntToUtf16CharSequence( sorted_fields[descriptor_->field_count() - 1]->number(), &chars); WriteIntToUtf16CharSequence(descriptor_->field_count(), &chars); WriteIntToUtf16CharSequence(map_count, &chars); WriteIntToUtf16CharSequence(repeated_count, &chars); - + std::vector<const FieldDescriptor*> fields_for_is_initialized_check; for (int i = 0; i < descriptor_->field_count(); i++) { if (descriptor_->field(i)->is_required() || @@ -542,15 +542,15 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( } } WriteIntToUtf16CharSequence(fields_for_is_initialized_check.size(), &chars); - + for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = sorted_fields[i]; field_generators_.get(field).GenerateFieldInfo(printer, &chars); - } + } printer->Outdent(); printer->Print("};\n"); - } - + } + printer->Print("java.lang.String info =\n"); TProtoStringType line; for (size_t i = 0; i < chars.size(); i++) { @@ -560,18 +560,18 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( printer->Print(" \"$string$\" +\n", "string", line); line.clear(); } - } + } printer->Print(" \"$string$\";\n", "string", line); - + printer->Print("return newMessageInfo(DEFAULT_INSTANCE, info, objects);\n"); - printer->Outdent(); -} - + printer->Outdent(); +} + // =================================================================== - + void ImmutableMessageLiteGenerator::GenerateParseFromMethods( io::Printer* printer) { - printer->Print( + printer->Print( "public static $classname$ parseFrom(\n" " java.nio.ByteBuffer data)\n" " throws com.google.protobuf.InvalidProtocolBufferException {\n" @@ -649,12 +649,12 @@ void ImmutableMessageLiteGenerator::GenerateParseFromMethods( "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); -} - -// =================================================================== - -void ImmutableMessageLiteGenerator::GenerateBuilder(io::Printer* printer) { - printer->Print( +} + +// =================================================================== + +void ImmutableMessageLiteGenerator::GenerateBuilder(io::Printer* printer) { + printer->Print( "public static Builder newBuilder() {\n" " return (Builder) DEFAULT_INSTANCE.createBuilder();\n" "}\n" @@ -663,67 +663,67 @@ void ImmutableMessageLiteGenerator::GenerateBuilder(io::Printer* printer) { "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - MessageBuilderLiteGenerator builderGenerator(descriptor_, context_); - builderGenerator.Generate(printer); -} - -// =================================================================== - -void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuilder( - io::Printer* printer) { + + MessageBuilderLiteGenerator builderGenerator(descriptor_, context_); + builderGenerator.Generate(printer); +} + +// =================================================================== + +void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuilder( + io::Printer* printer) { printer->Print("return new Builder();\n"); -} - -// =================================================================== - +} + +// =================================================================== + void ImmutableMessageLiteGenerator::GenerateExtensionRegistrationCode( - io::Printer* printer) { - for (int i = 0; i < descriptor_->extension_count(); i++) { - ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_) + io::Printer* printer) { + for (int i = 0; i < descriptor_->extension_count(); i++) { + ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_) .GenerateRegistrationCode(printer); - } - - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) + } + + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) .GenerateExtensionRegistrationCode(printer); - } -} - -// =================================================================== + } +} + +// =================================================================== void ImmutableMessageLiteGenerator::GenerateConstructor(io::Printer* printer) { printer->Print("private $classname$() {\n", "classname", descriptor_->name()); - printer->Indent(); - - // Initialize all fields to default. - GenerateInitializers(printer); - - printer->Outdent(); + printer->Indent(); + + // Initialize all fields to default. + GenerateInitializers(printer); + + printer->Outdent(); printer->Print("}\n"); -} - -// =================================================================== -void ImmutableMessageLiteGenerator::GenerateParser(io::Printer* printer) { - printer->Print( +} + +// =================================================================== +void ImmutableMessageLiteGenerator::GenerateParser(io::Printer* printer) { + printer->Print( "private static volatile com.google.protobuf.Parser<$classname$> " "PARSER;\n" - "\n" - "public static com.google.protobuf.Parser<$classname$> parser() {\n" - " return DEFAULT_INSTANCE.getParserForType();\n" - "}\n", - "classname", descriptor_->name()); -} - -// =================================================================== -void ImmutableMessageLiteGenerator::GenerateInitializers(io::Printer* printer) { - for (int i = 0; i < descriptor_->field_count(); i++) { + "\n" + "public static com.google.protobuf.Parser<$classname$> parser() {\n" + " return DEFAULT_INSTANCE.getParserForType();\n" + "}\n", + "classname", descriptor_->name()); +} + +// =================================================================== +void ImmutableMessageLiteGenerator::GenerateInitializers(io::Printer* printer) { + for (int i = 0; i < descriptor_->field_count(); i++) { if (!IsRealOneof(descriptor_->field(i))) { - field_generators_.get(descriptor_->field(i)) - .GenerateInitializationCode(printer); - } - } -} - + field_generators_.get(descriptor_->field(i)) + .GenerateInitializationCode(printer); + } + } +} + void ImmutableMessageLiteGenerator::GenerateKotlinDsl( io::Printer* printer) const { printer->Print( @@ -960,7 +960,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( "message", message_name); } -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.h index 4dfa291314..a5308062c2 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_message_lite.h @@ -1,86 +1,86 @@ -// 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: dweis@google.com (Daniel Weis) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ - +// 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: dweis@google.com (Daniel Weis) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ + #include <map> #include <string> #include <google/protobuf/compiler/java/java_field.h> #include <google/protobuf/compiler/java/java_message.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableMessageLiteGenerator : public MessageGenerator { - public: - ImmutableMessageLiteGenerator(const Descriptor* descriptor, Context* context); - virtual ~ImmutableMessageLiteGenerator(); - - virtual void Generate(io::Printer* printer); - virtual void GenerateInterface(io::Printer* printer); - virtual void GenerateExtensionRegistrationCode(io::Printer* printer); + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableMessageLiteGenerator : public MessageGenerator { + public: + ImmutableMessageLiteGenerator(const Descriptor* descriptor, Context* context); + virtual ~ImmutableMessageLiteGenerator(); + + virtual void Generate(io::Printer* printer); + virtual void GenerateInterface(io::Printer* printer); + virtual void GenerateExtensionRegistrationCode(io::Printer* printer); virtual void GenerateStaticVariables(io::Printer* printer, int* bytecode_estimate); - virtual int GenerateStaticVariableInitializers(io::Printer* printer); + virtual int GenerateStaticVariableInitializers(io::Printer* printer); void GenerateKotlinDsl(io::Printer* printer) const override; void GenerateKotlinMembers(io::Printer* printer) const override; void GenerateTopLevelKotlinMembers(io::Printer* printer) const override; - - private: - void GenerateParseFromMethods(io::Printer* printer); - - void GenerateBuilder(io::Printer* printer); - void GenerateDynamicMethodNewBuilder(io::Printer* printer); - void GenerateInitializers(io::Printer* printer); - void GenerateParser(io::Printer* printer); - void GenerateConstructor(io::Printer* printer); + + private: + void GenerateParseFromMethods(io::Printer* printer); + + void GenerateBuilder(io::Printer* printer); + void GenerateDynamicMethodNewBuilder(io::Printer* printer); + void GenerateInitializers(io::Printer* printer); + void GenerateParser(io::Printer* printer); + void GenerateConstructor(io::Printer* printer); void GenerateDynamicMethodNewBuildMessageInfo(io::Printer* printer); void GenerateKotlinExtensions(io::Printer* printer) const; - - Context* context_; - ClassNameResolver* name_resolver_; - FieldGeneratorMap<ImmutableFieldLiteGenerator> field_generators_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + Context* context_; + ClassNameResolver* name_resolver_; + FieldGeneratorMap<ImmutableFieldLiteGenerator> field_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.cc index 595ead4955..ee131f2bdd 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.cc @@ -1,74 +1,74 @@ -// 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. - +// 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/java_name_resolver.h> - -#include <map> + +#include <map> #include <string> - + #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_names.h> #include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/stubs/substitute.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { -// A suffix that will be appended to the file's outer class name if the name -// conflicts with some other types defined in the file. -const char* kOuterClassNameSuffix = "OuterClass"; - -// Strip package name from a descriptor's full name. -// For example: -// Full name : foo.Bar.Baz -// Package name: foo -// After strip : Bar.Baz + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +namespace { +// A suffix that will be appended to the file's outer class name if the name +// conflicts with some other types defined in the file. +const char* kOuterClassNameSuffix = "OuterClass"; + +// Strip package name from a descriptor's full name. +// For example: +// Full name : foo.Bar.Baz +// Package name: foo +// After strip : Bar.Baz TProtoStringType StripPackageName(const TProtoStringType& full_name, const FileDescriptor* file) { - if (file->package().empty()) { - return full_name; - } else { - // Strip package name - return full_name.substr(file->package().size() + 1); - } -} - -// Get the name of a message's Java class without package name prefix. + if (file->package().empty()) { + return full_name; + } else { + // Strip package name + return full_name.substr(file->package().size() + 1); + } +} + +// 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()); -} - +} + TProtoStringType ClassNameWithoutPackageKotlin(const Descriptor* descriptor) { TProtoStringType result = descriptor->name(); const Descriptor* temp = descriptor->containing_type(); @@ -80,29 +80,29 @@ TProtoStringType ClassNameWithoutPackageKotlin(const Descriptor* descriptor) { return result; } -// Get the name of an enum's Java class without package name prefix. +// Get the name of an enum's Java class without package name prefix. TProtoStringType ClassNameWithoutPackage(const EnumDescriptor* descriptor, bool immutable) { - // Doesn't append "Mutable" for enum type's name. - const Descriptor* message_descriptor = descriptor->containing_type(); - if (message_descriptor == NULL) { - return descriptor->name(); - } else { + // Doesn't append "Mutable" for enum type's name. + const Descriptor* message_descriptor = descriptor->containing_type(); + if (message_descriptor == NULL) { + return descriptor->name(); + } else { return ClassNameWithoutPackage(message_descriptor, immutable) + "." + descriptor->name(); - } -} - -// Get the name of a service's Java class without package name prefix. + } +} + +// Get the name of a service's Java class without package name prefix. TProtoStringType ClassNameWithoutPackage(const ServiceDescriptor* descriptor, bool immutable) { TProtoStringType full_name = StripPackageName(descriptor->full_name(), descriptor->file()); - // We don't allow nested service definitions. + // We don't allow nested service definitions. GOOGLE_CHECK(full_name.find('.') == TProtoStringType::npos); - return full_name; -} - + return 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)) { @@ -114,63 +114,63 @@ NameEquality CheckNameEquality(const TProtoStringType& a, const TProtoStringType return NameEquality::NO_MATCH; } -// Check whether a given message or its nested types has the given class name. -bool MessageHasConflictingClassName(const Descriptor* message, +// Check whether a given message or its nested types has the given class name. +bool MessageHasConflictingClassName(const Descriptor* message, const TProtoStringType& classname, NameEquality equality_mode) { if (CheckNameEquality(message->name(), classname) == equality_mode) { return true; } - for (int i = 0; i < message->nested_type_count(); ++i) { + for (int i = 0; i < message->nested_type_count(); ++i) { if (MessageHasConflictingClassName(message->nested_type(i), classname, equality_mode)) { - return true; - } - } - for (int i = 0; i < message->enum_type_count(); ++i) { + return true; + } + } + for (int i = 0; i < message->enum_type_count(); ++i) { if (CheckNameEquality(message->enum_type(i)->name(), classname) == equality_mode) { - return true; - } - } - return false; -} - -} // namespace - + return true; + } + } + return false; +} + +} // namespace + ClassNameResolver::ClassNameResolver() {} - + ClassNameResolver::~ClassNameResolver() {} - + TProtoStringType ClassNameResolver::GetFileDefaultImmutableClassName( - const FileDescriptor* file) { + const FileDescriptor* file) { TProtoStringType basename; TProtoStringType::size_type last_slash = file->name().find_last_of('/'); if (last_slash == TProtoStringType::npos) { - basename = file->name(); - } else { - basename = file->name().substr(last_slash + 1); - } - return UnderscoresToCamelCase(StripProto(basename), true); -} - + basename = file->name(); + } else { + basename = file->name().substr(last_slash + 1); + } + return UnderscoresToCamelCase(StripProto(basename), true); +} + TProtoStringType ClassNameResolver::GetFileImmutableClassName( - const FileDescriptor* file) { + const FileDescriptor* file) { TProtoStringType& class_name = file_immutable_outer_class_names_[file]; - if (class_name.empty()) { - if (file->options().has_java_outer_classname()) { - class_name = file->options().java_outer_classname(); - } else { - class_name = GetFileDefaultImmutableClassName(file); + if (class_name.empty()) { + if (file->options().has_java_outer_classname()) { + class_name = file->options().java_outer_classname(); + } else { + class_name = GetFileDefaultImmutableClassName(file); if (HasConflictingClassName(file, class_name, NameEquality::EXACT_EQUAL)) { - class_name += kOuterClassNameSuffix; - } - } - } - return class_name; -} - + class_name += kOuterClassNameSuffix; + } + } + } + return class_name; +} + TProtoStringType ClassNameResolver::GetFileClassName(const FileDescriptor* file, bool immutable) { return GetFileClassName(file, immutable, false); @@ -181,43 +181,43 @@ TProtoStringType ClassNameResolver::GetFileClassName(const FileDescriptor* file, if (kotlin) { return GetFileImmutableClassName(file) + "Kt"; } else if (immutable) { - return GetFileImmutableClassName(file); - } else { - return "Mutable" + GetFileImmutableClassName(file); - } -} - -// Check whether there is any type defined in the proto file that has -// the given class name. + return GetFileImmutableClassName(file); + } else { + return "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, NameEquality equality_mode) { - for (int i = 0; i < file->enum_type_count(); i++) { + for (int i = 0; i < file->enum_type_count(); i++) { if (CheckNameEquality(file->enum_type(i)->name(), classname) == equality_mode) { - return true; - } - } - for (int i = 0; i < file->service_count(); i++) { + return true; + } + } + for (int i = 0; i < file->service_count(); i++) { if (CheckNameEquality(file->service(i)->name(), classname) == equality_mode) { - return true; - } - } - for (int i = 0; i < file->message_type_count(); i++) { + return true; + } + } + for (int i = 0; i < file->message_type_count(); i++) { if (MessageHasConflictingClassName(file->message_type(i), classname, equality_mode)) { - return true; - } - } - return false; -} - + return true; + } + } + return false; +} + TProtoStringType ClassNameResolver::GetDescriptorClassName( - const FileDescriptor* descriptor) { - return GetFileImmutableClassName(descriptor); -} - + const FileDescriptor* descriptor) { + return GetFileImmutableClassName(descriptor); +} + TProtoStringType ClassNameResolver::GetClassName(const FileDescriptor* descriptor, bool immutable) { return GetClassName(descriptor, immutable, false); @@ -226,13 +226,13 @@ TProtoStringType ClassNameResolver::GetClassName(const FileDescriptor* descripto TProtoStringType ClassNameResolver::GetClassName(const FileDescriptor* descriptor, bool immutable, bool kotlin) { TProtoStringType result = FileJavaPackage(descriptor, immutable); - if (!result.empty()) result += '.'; + if (!result.empty()) result += '.'; result += GetFileClassName(descriptor, immutable, kotlin); - return result; -} - -// Get the full name of a Java class by prepending the Java package name -// or outer class name. + return result; +} + +// 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, bool immutable, bool is_own_file) { @@ -245,30 +245,30 @@ TProtoStringType ClassNameResolver::GetClassFullName( bool immutable, bool is_own_file, bool kotlin) { TProtoStringType result; if (is_own_file) { - result = FileJavaPackage(file, immutable); - } else { + result = FileJavaPackage(file, immutable); + } else { result = GetClassName(file, immutable, kotlin); - } - if (!result.empty()) { - result += '.'; - } - result += name_without_package; + } + if (!result.empty()) { + result += '.'; + } + result += name_without_package; if (kotlin) result += "Kt"; - return result; -} - + return result; +} + TProtoStringType ClassNameResolver::GetClassName(const Descriptor* descriptor, bool immutable) { return GetClassName(descriptor, immutable, false); -} - +} + TProtoStringType ClassNameResolver::GetClassName(const Descriptor* descriptor, bool immutable, bool kotlin) { return GetClassFullName( ClassNameWithoutPackage(descriptor, immutable), descriptor->file(), immutable, MultipleJavaFiles(descriptor->file(), immutable), kotlin); -} - +} + TProtoStringType ClassNameResolver::GetClassName(const EnumDescriptor* descriptor, bool immutable) { return GetClassName(descriptor, immutable, false); @@ -288,15 +288,15 @@ TProtoStringType ClassNameResolver::GetClassName(const ServiceDescriptor* descri TProtoStringType ClassNameResolver::GetClassName(const ServiceDescriptor* descriptor, bool immutable, bool kotlin) { - return GetClassFullName(ClassNameWithoutPackage(descriptor, immutable), - descriptor->file(), immutable, + return GetClassFullName(ClassNameWithoutPackage(descriptor, immutable), + descriptor->file(), immutable, IsOwnFile(descriptor, immutable), kotlin); -} - -// Get the Java Class style full name of a message. +} + +// Get the Java Class style full name of a message. TProtoStringType ClassNameResolver::GetJavaClassFullName( const TProtoStringType& name_without_package, const FileDescriptor* file, - bool immutable) { + bool immutable) { return GetJavaClassFullName(name_without_package, file, immutable, false); } @@ -304,28 +304,28 @@ TProtoStringType ClassNameResolver::GetJavaClassFullName( const TProtoStringType& name_without_package, const FileDescriptor* file, bool immutable, bool kotlin) { TProtoStringType result; - if (MultipleJavaFiles(file, immutable)) { - result = FileJavaPackage(file, immutable); - if (!result.empty()) result += '.'; - } else { + if (MultipleJavaFiles(file, immutable)) { + result = FileJavaPackage(file, immutable); + if (!result.empty()) result += '.'; + } else { result = GetClassName(file, immutable, kotlin); - if (!result.empty()) result += '$'; - } - result += StringReplace(name_without_package, ".", "$", true); - return result; -} - + if (!result.empty()) result += '$'; + } + result += StringReplace(name_without_package, ".", "$", true); + return result; +} + TProtoStringType ClassNameResolver::GetExtensionIdentifierName( - const FieldDescriptor* descriptor, bool immutable) { + const FieldDescriptor* descriptor, bool immutable) { return GetExtensionIdentifierName(descriptor, immutable, false); } TProtoStringType ClassNameResolver::GetExtensionIdentifierName( const FieldDescriptor* descriptor, bool immutable, bool kotlin) { return GetClassName(descriptor->containing_type(), immutable, kotlin) + "." + - descriptor->name(); -} - + descriptor->name(); +} + TProtoStringType ClassNameResolver::GetKotlinFactoryName( const Descriptor* descriptor) { TProtoStringType name = ToCamelCase(descriptor->name(), /* lower_first = */ true); @@ -333,23 +333,23 @@ TProtoStringType ClassNameResolver::GetKotlinFactoryName( } TProtoStringType ClassNameResolver::GetJavaImmutableClassName( - const Descriptor* descriptor) { + const Descriptor* descriptor) { return GetJavaClassFullName(ClassNameWithoutPackage(descriptor, true), descriptor->file(), true); -} - +} + TProtoStringType ClassNameResolver::GetJavaImmutableClassName( - const EnumDescriptor* descriptor) { + const EnumDescriptor* descriptor) { return GetJavaClassFullName(ClassNameWithoutPackage(descriptor, true), descriptor->file(), true); -} - +} + TProtoStringType ClassNameResolver::GetKotlinExtensionsClassName( const Descriptor* descriptor) { return GetClassFullName(ClassNameWithoutPackageKotlin(descriptor), descriptor->file(), true, true, true); } - + TProtoStringType ClassNameResolver::GetJavaMutableClassName( const Descriptor* descriptor) { return GetJavaClassFullName(ClassNameWithoutPackage(descriptor, false), @@ -374,7 +374,7 @@ TProtoStringType ClassNameResolver::GetDowngradedClassName( ClassNameWithoutPackage(descriptor, false); } -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.h index 180f3de630..31b95900e4 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_name_resolver.h @@ -1,86 +1,86 @@ -// 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_NAME_RESOLVER_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ - -#include <map> +// 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_NAME_RESOLVER_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ + +#include <map> #include <string> - + #include <google/protobuf/stubs/common.h> - -namespace google { -namespace protobuf { -class Descriptor; -class EnumDescriptor; -class FieldDescriptor; -class FileDescriptor; -class ServiceDescriptor; - -namespace compiler { -namespace java { - + +namespace google { +namespace protobuf { +class Descriptor; +class EnumDescriptor; +class FieldDescriptor; +class FileDescriptor; +class ServiceDescriptor; + +namespace compiler { +namespace java { + // Indicates how closely the two class names match. enum NameEquality { NO_MATCH, EXACT_EQUAL, EQUAL_IGNORE_CASE }; -// Used to get the Java class related names for a given descriptor. It caches -// the results to avoid redundant calculation across multiple name queries. -// Thread-safety note: This class is *not* thread-safe. -class ClassNameResolver { - public: - ClassNameResolver(); - ~ClassNameResolver(); - - // Gets the unqualified outer class name for the file. +// Used to get the Java class related names for a given descriptor. It caches +// the results to avoid redundant calculation across multiple name queries. +// Thread-safety note: This class is *not* thread-safe. +class ClassNameResolver { + public: + ClassNameResolver(); + ~ClassNameResolver(); + + // Gets the unqualified outer class name for the file. TProtoStringType GetFileClassName(const FileDescriptor* file, bool immutable); TProtoStringType GetFileClassName(const FileDescriptor* file, bool immutable, bool kotlin); - // Gets the unqualified immutable outer class name of a file. + // Gets the unqualified immutable outer class name of a file. TProtoStringType GetFileImmutableClassName(const FileDescriptor* file); - // Gets the unqualified default immutable outer class name of a file - // (converted from the proto file's name). + // Gets the unqualified default immutable outer class name of a file + // (converted from the proto file's name). TProtoStringType GetFileDefaultImmutableClassName(const FileDescriptor* file); - - // Check whether there is any type defined in the proto file that has - // the given class name. - bool HasConflictingClassName(const FileDescriptor* file, + + // 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, NameEquality equality_mode); - - // Gets the name of the outer class that holds descriptor information. - // Descriptors are shared between immutable messages and mutable messages. - // Since both of them are generated optionally, the descriptors need to be - // put in another common place. + + // Gets the name of the outer class that holds descriptor information. + // Descriptors are shared between immutable messages and mutable messages. + // Since both of them are generated optionally, the descriptors need to be + // put in another common place. TProtoStringType GetDescriptorClassName(const FileDescriptor* file); - - // Gets the fully-qualified class name corresponding to the given descriptor. + + // Gets the fully-qualified class name corresponding to the given descriptor. TProtoStringType GetClassName(const Descriptor* descriptor, bool immutable); TProtoStringType GetClassName(const Descriptor* descriptor, bool immutable, bool kotlin); @@ -93,26 +93,26 @@ class ClassNameResolver { TProtoStringType GetClassName(const FileDescriptor* descriptor, bool immutable); TProtoStringType GetClassName(const FileDescriptor* descriptor, bool immutable, bool kotlin); - + template <class DescriptorType> TProtoStringType GetImmutableClassName(const DescriptorType* descriptor) { - return GetClassName(descriptor, true); - } + return GetClassName(descriptor, true); + } template <class DescriptorType> TProtoStringType GetMutableClassName(const DescriptorType* descriptor) { - return GetClassName(descriptor, false); - } - - // Gets the fully qualified name of an extension identifier. + return GetClassName(descriptor, false); + } + + // Gets the fully qualified name of an extension identifier. TProtoStringType GetExtensionIdentifierName(const FieldDescriptor* descriptor, bool immutable); TProtoStringType GetExtensionIdentifierName(const FieldDescriptor* descriptor, bool immutable, bool kotlin); - - // Gets the fully qualified name for generated classes in Java convention. - // Nested classes will be separated using '$' instead of '.' - // For example: - // com.package.OuterClass$OuterMessage$InnerMessage + + // Gets the fully qualified name for generated classes in Java convention. + // Nested classes will be separated using '$' instead of '.' + // For example: + // com.package.OuterClass$OuterMessage$InnerMessage TProtoStringType GetJavaImmutableClassName(const Descriptor* descriptor); TProtoStringType GetJavaImmutableClassName(const EnumDescriptor* descriptor); TProtoStringType GetKotlinFactoryName(const Descriptor* descriptor); @@ -123,31 +123,31 @@ class ClassNameResolver { TProtoStringType GetDowngradedFileClassName(const FileDescriptor* file); TProtoStringType GetDowngradedClassName(const Descriptor* descriptor); - private: - // Get the full name of a Java class by prepending the Java package name - // or outer class name. + private: + // 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, const FileDescriptor* file, bool immutable, bool is_own_file); TProtoStringType GetClassFullName(const TProtoStringType& name_without_package, const FileDescriptor* file, bool immutable, bool is_own_file, bool kotlin); - // Get the Java Class style full name of a message. + // Get the Java Class style full name of a message. TProtoStringType GetJavaClassFullName(const TProtoStringType& name_without_package, const FileDescriptor* file, bool immutable); TProtoStringType GetJavaClassFullName(const TProtoStringType& name_without_package, const FileDescriptor* file, bool immutable, bool kotlin); - // Caches the result to provide better performance. + // Caches the result to provide better performance. std::map<const FileDescriptor*, TProtoStringType> file_immutable_outer_class_names_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_names.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_names.h index 9aeddc81cc..838d63e814 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_names.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_names.h @@ -1,85 +1,85 @@ -// 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. -// -// Provides a mechanism for mapping a descriptor to the -// fully-qualified name of the corresponding Java class. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ - +// 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. +// +// Provides a mechanism for mapping a descriptor to the +// fully-qualified name of the corresponding Java class. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ + #include <string> - -namespace google { -namespace protobuf { - -class Descriptor; -class EnumDescriptor; -class FileDescriptor; + +namespace google { +namespace protobuf { + +class Descriptor; +class EnumDescriptor; +class FileDescriptor; class FieldDescriptor; -class ServiceDescriptor; - -namespace compiler { -namespace java { - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. +class ServiceDescriptor; + +namespace compiler { +namespace java { + +// Requires: +// descriptor != NULL +// +// Returns: +// The fully-qualified Java class name. TProtoStringType ClassName(const Descriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. + +// Requires: +// descriptor != NULL +// +// Returns: +// The fully-qualified Java class name. TProtoStringType ClassName(const EnumDescriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. + +// Requires: +// descriptor != NULL +// +// Returns: +// The fully-qualified Java class name. TProtoStringType ClassName(const FileDescriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. + +// Requires: +// descriptor != NULL +// +// Returns: +// The fully-qualified Java class name. TProtoStringType ClassName(const ServiceDescriptor* descriptor); - + // Requires: // descriptor != NULL // @@ -93,8 +93,8 @@ TProtoStringType FileJavaPackage(const FileDescriptor* descriptor); // Capitalized camel case name field name. TProtoStringType CapitalizedFieldName(const FieldDescriptor* descriptor); -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_options.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_options.h index 1454c23206..be0d2a9e02 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_options.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_options.h @@ -1,73 +1,73 @@ -// 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_OPTIONS_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__ - +// 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_OPTIONS_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__ + #include <string> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// Generator options -struct Options { - Options() - : generate_immutable_code(false), - generate_mutable_code(false), - generate_shared_code(false), - enforce_lite(false), - annotate_code(false) { - } - - bool generate_immutable_code; - bool generate_mutable_code; - bool generate_shared_code; - // When set, the protoc will generate the current files and all the transitive - // dependencies as lite runtime. - bool enforce_lite; - // If true, we should build .meta files and emit @Generated annotations into - // generated code. - bool annotate_code; - // Name of a file where we will write a list of generated .meta file names, - // one per line. + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +// Generator options +struct Options { + Options() + : generate_immutable_code(false), + generate_mutable_code(false), + generate_shared_code(false), + enforce_lite(false), + annotate_code(false) { + } + + bool generate_immutable_code; + bool generate_mutable_code; + bool generate_shared_code; + // When set, the protoc will generate the current files and all the transitive + // dependencies as lite runtime. + bool enforce_lite; + // If true, we should build .meta files and emit @Generated annotations into + // generated code. + bool annotate_code; + // Name of a file where we will write a list of generated .meta file names, + // one per line. TProtoStringType annotation_list_file; - // Name of a file where we will write a list of generated file names, one - // per line. + // Name of a file where we will write a list of generated file names, one + // per line. TProtoStringType output_list_file; -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.cc index ab550761b1..fc69e2d8a4 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.cc @@ -1,43 +1,43 @@ -// 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. - +// 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/java_primitive_field.h> #include <cstdint> -#include <map> +#include <map> #include <string> - + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_context.h> @@ -47,28 +47,28 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -using internal::WireFormat; - -namespace { - -void SetPrimitiveVariables(const FieldDescriptor* descriptor, + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +using internal::WireFormat; + +namespace { + +void SetPrimitiveVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); + 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)["field_type"] = (*variables)["type"]; if (javaType == JAVATYPE_BOOLEAN || javaType == JAVATYPE_DOUBLE || javaType == JAVATYPE_FLOAT || javaType == JAVATYPE_INT || @@ -106,27 +106,27 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["repeated_set"] = (*variables)["name"] + "_.set"; } - (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_init"] = IsDefaultValueJavaDefault(descriptor) ? "" : ("= " + ImmutableDefaultValue(descriptor, name_resolver)); - (*variables)["capitalized_type"] = - GetCapitalizedType(descriptor, /* immutable = */ true); + (*variables)["capitalized_type"] = + GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( - WireFormat::TagSize(descriptor->number(), GetType(descriptor))); - if (IsReferenceType(GetJavaType(descriptor))) { - (*variables)["null_check"] = - " if (value == null) {\n" - " throw new NullPointerException();\n" - " }\n"; - } else { - (*variables)["null_check"] = ""; - } - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + WireFormat::TagSize(descriptor->number(), GetType(descriptor))); + if (IsReferenceType(GetJavaType(descriptor))) { + (*variables)["null_check"] = + " if (value == null) {\n" + " throw new NullPointerException();\n" + " }\n"; + } else { + (*variables)["null_check"] = ""; + } + // 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"] = @@ -134,96 +134,96 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + " is deprecated\") " : ""; - int fixed_size = FixedSize(GetType(descriptor)); - if (fixed_size != -1) { + int fixed_size = FixedSize(GetType(descriptor)); + if (fixed_size != -1) { (*variables)["fixed_size"] = StrCat(fixed_size); - } - (*variables)["on_changed"] = "onChanged();"; - + } + (*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)["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"] = ""; - - if (descriptor->type() == FieldDescriptor::TYPE_BYTES) { - (*variables)["is_field_present_message"] = - "!" + (*variables)["name"] + "_.isEmpty()"; - } else { - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"]; - } - } - + // 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)["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"] = ""; + + if (descriptor->type() == FieldDescriptor::TYPE_BYTES) { + (*variables)["is_field_present_message"] = + "!" + (*variables)["name"] + "_.isEmpty()"; + } else { + (*variables)["is_field_present_message"] = + (*variables)["name"] + "_ != " + (*variables)["default"]; + } + } + // 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_from_local"] = - GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); -} - -} // namespace - -// =================================================================== - + (*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_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); +} + +} // namespace + +// =================================================================== + ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator( 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_); -} - -ImmutablePrimitiveFieldGenerator::~ImmutablePrimitiveFieldGenerator() {} - -int ImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { + SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +ImmutablePrimitiveFieldGenerator::~ImmutablePrimitiveFieldGenerator() {} + +int ImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; -} - -int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { +} + +int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { return GetNumBitsForMessage(); -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private $field_type$ $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -233,21 +233,21 @@ void ImmutablePrimitiveFieldGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { printer->Print(variables_, "private $field_type$ $name$_ $default_init$;\n"); - + if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -257,19 +257,19 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( " return $get_has_field_bit_builder$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" "$null_check$" @@ -279,7 +279,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ true); printer->Print( @@ -287,22 +287,22 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $clear_has_field_bit_builder$\n"); printer->Annotate("{", "}", descriptor_); - JavaType type = GetJavaType(descriptor_); - if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) { - // 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. + JavaType type = GetJavaType(descriptor_); + if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) { + // 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"); - } else { + } else { printer->Print(variables_, " $name$_ = $default$;\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " $on_changed$\n" " return this;\n" "}\n"); -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -333,38 +333,38 @@ void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( void ImmutablePrimitiveFieldGenerator::GenerateFieldBuilderInitializationCode( io::Printer* printer) const { - // noop for primitives -} - + // noop for primitives +} + void ImmutablePrimitiveFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { if (!IsDefaultValueJavaDefault(descriptor_)) { printer->Print(variables_, "$name$_ = $default$;\n"); } -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "$name$_ = $default$;\n" "$clear_has_field_bit_builder$\n"); -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateMergingCode( io::Printer* printer) const { if (HasHazzer(descriptor_)) { - printer->Print(variables_, + printer->Print(variables_, "if (other.has$capitalized_name$()) {\n" " set$capitalized_name$(other.get$capitalized_name$());\n" "}\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "if (other.get$capitalized_name$() != $default$) {\n" " set$capitalized_name$(other.get$capitalized_name$());\n" "}\n"); - } -} - + } +} + void ImmutablePrimitiveFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { if (HasHazzer(descriptor_)) { @@ -383,154 +383,154 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuildingCode( } } else { printer->Print(variables_, "result.$name$_ = $name$_;\n"); - } -} - + } +} + void ImmutablePrimitiveFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - printer->Print(variables_, + 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. -} - + // noop for primitives. +} + void ImmutablePrimitiveFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($is_field_present_message$) {\n" " output.write$capitalized_type$($number$, $name$_);\n" "}\n"); -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($is_field_present_message$) {\n" " size += com.google.protobuf.CodedOutputStream\n" " .compute$capitalized_type$Size($number$, $name$_);\n" "}\n"); -} - +} + void ImmutablePrimitiveFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { - switch (GetJavaType(descriptor_)) { - case JAVATYPE_INT: - case JAVATYPE_LONG: - case JAVATYPE_BOOLEAN: - printer->Print(variables_, + switch (GetJavaType(descriptor_)) { + case JAVATYPE_INT: + case JAVATYPE_LONG: + case JAVATYPE_BOOLEAN: + printer->Print(variables_, "if (get$capitalized_name$()\n" " != other.get$capitalized_name$()) return false;\n"); - break; - - case JAVATYPE_FLOAT: + break; + + case JAVATYPE_FLOAT: printer->Print( variables_, "if (java.lang.Float.floatToIntBits(get$capitalized_name$())\n" " != java.lang.Float.floatToIntBits(\n" " other.get$capitalized_name$())) return false;\n"); - break; - - case JAVATYPE_DOUBLE: + break; + + case JAVATYPE_DOUBLE: printer->Print( variables_, "if (java.lang.Double.doubleToLongBits(get$capitalized_name$())\n" " != java.lang.Double.doubleToLongBits(\n" " other.get$capitalized_name$())) return false;\n"); - break; - - case JAVATYPE_STRING: - case JAVATYPE_BYTES: + break; + + case JAVATYPE_STRING: + case JAVATYPE_BYTES: printer->Print( variables_, "if (!get$capitalized_name$()\n" " .equals(other.get$capitalized_name$())) return false;\n"); - break; - - case JAVATYPE_ENUM: - case JAVATYPE_MESSAGE: - default: - GOOGLE_LOG(FATAL) << "Can't get here."; - break; - } -} - + break; + + case JAVATYPE_ENUM: + case JAVATYPE_MESSAGE: + default: + GOOGLE_LOG(FATAL) << "Can't get here."; + break; + } +} + void ImmutablePrimitiveFieldGenerator::GenerateHashCode( io::Printer* printer) const { printer->Print(variables_, "hash = (37 * hash) + $constant_name$;\n"); - switch (GetJavaType(descriptor_)) { - case JAVATYPE_INT: - printer->Print(variables_, + switch (GetJavaType(descriptor_)) { + case JAVATYPE_INT: + printer->Print(variables_, "hash = (53 * hash) + get$capitalized_name$();\n"); - break; - - case JAVATYPE_LONG: + break; + + case JAVATYPE_LONG: printer->Print( variables_, "hash = (53 * hash) + com.google.protobuf.Internal.hashLong(\n" " get$capitalized_name$());\n"); - break; - - case JAVATYPE_BOOLEAN: + break; + + case JAVATYPE_BOOLEAN: printer->Print( variables_, "hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(\n" " get$capitalized_name$());\n"); - break; - - case JAVATYPE_FLOAT: - printer->Print(variables_, + break; + + case JAVATYPE_FLOAT: + printer->Print(variables_, "hash = (53 * hash) + java.lang.Float.floatToIntBits(\n" " get$capitalized_name$());\n"); - break; - - case JAVATYPE_DOUBLE: + break; + + case JAVATYPE_DOUBLE: printer->Print( variables_, "hash = (53 * hash) + com.google.protobuf.Internal.hashLong(\n" " java.lang.Double.doubleToLongBits(get$capitalized_name$()));\n"); - break; - - case JAVATYPE_STRING: - case JAVATYPE_BYTES: + break; + + case JAVATYPE_STRING: + case JAVATYPE_BYTES: printer->Print( variables_, "hash = (53 * hash) + get$capitalized_name$().hashCode();\n"); - break; - - case JAVATYPE_ENUM: - case JAVATYPE_MESSAGE: - default: - GOOGLE_LOG(FATAL) << "Can't get here."; - break; - } -} - + break; + + case JAVATYPE_ENUM: + case JAVATYPE_MESSAGE: + default: + GOOGLE_LOG(FATAL) << "Can't get here."; + break; + } +} + TProtoStringType ImmutablePrimitiveFieldGenerator::GetBoxedType() const { - return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); -} - -// =================================================================== - + return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); +} + +// =================================================================== + ImmutablePrimitiveOneofFieldGenerator::ImmutablePrimitiveOneofFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : ImmutablePrimitiveFieldGenerator(descriptor, messageBitIndex, builderBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - -ImmutablePrimitiveOneofFieldGenerator:: + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + +ImmutablePrimitiveOneofFieldGenerator:: ~ImmutablePrimitiveOneofFieldGenerator() {} - + void ImmutablePrimitiveOneofFieldGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, @@ -539,9 +539,9 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateMembers( " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" @@ -550,20 +550,20 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateMembers( " return $default$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ($boxed_type$) $oneof_name$_;\n" @@ -571,10 +571,10 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers( " return $default$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" "$null_check$" @@ -598,32 +598,32 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutablePrimitiveOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($has_oneof_case_message$) {\n" " result.$oneof_name$_ = $oneof_name$_;\n" "}\n"); -} - +} + void ImmutablePrimitiveOneofFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "set$capitalized_name$(other.get$capitalized_name$());\n"); -} - +} + void ImmutablePrimitiveOneofFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "$set_oneof_case_message$;\n" "$oneof_name$_ = input.read$capitalized_type$();\n"); -} - +} + void ImmutablePrimitiveOneofFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($has_oneof_case_message$) {\n" " output.write$capitalized_type$(\n"); // $type$ and $boxed_type$ is the same for bytes fields so we don't need to @@ -636,11 +636,11 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateSerializationCode( " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n"); } printer->Print("}\n"); -} - +} + void ImmutablePrimitiveOneofFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($has_oneof_case_message$) {\n" " size += com.google.protobuf.CodedOutputStream\n" " .compute$capitalized_type$Size(\n"); @@ -654,52 +654,52 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateSerializedSizeCode( " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n"); } printer->Print("}\n"); -} - -// =================================================================== - -RepeatedImmutablePrimitiveFieldGenerator:: +} + +// =================================================================== + +RepeatedImmutablePrimitiveFieldGenerator:: RepeatedImmutablePrimitiveFieldGenerator(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_); -} - -RepeatedImmutablePrimitiveFieldGenerator:: + SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +RepeatedImmutablePrimitiveFieldGenerator:: ~RepeatedImmutablePrimitiveFieldGenerator() {} - -int RepeatedImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { - return 0; -} - -int RepeatedImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { - return 1; -} - + +int RepeatedImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { + return 0; +} + +int RepeatedImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { + return 1; +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$java.util.List<$boxed_type$> " "get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$(int index);\n"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private $field_list_type$ $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<$boxed_type$>\n" " ${$get$capitalized_name$List$}$() {\n" @@ -720,35 +720,35 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateMembers( " return $repeated_get$(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + if (descriptor_->is_packed()) { - printer->Print(variables_, + printer->Print(variables_, "private int $name$MemoizedSerializedSize = -1;\n"); - } -} - + } +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // One field is the list and the bit field keeps track of whether the - // list is immutable. If it's immutable, the invariant is that it must - // either an instance of Collections.emptyList() or it's an ArrayList - // wrapped in a Collections.unmodifiableList() wrapper and nobody else has + // One field is the list and the bit field keeps track of whether the + // list is immutable. If it's immutable, the invariant is that it must + // either an instance of Collections.emptyList() or it's an ArrayList + // wrapped in a Collections.unmodifiableList() wrapper and nobody else has // a reference to the underlying ArrayList. This invariant allows us to - // share instances of lists between protocol buffers avoiding expensive - // 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_, + // share instances of lists between protocol buffers avoiding expensive + // 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 $field_list_type$ $name$_ = $empty_list$;\n"); - - printer->Print(variables_, + + printer->Print(variables_, "private void ensure$capitalized_name$IsMutable() {\n" " if (!$get_mutable_bit_builder$) {\n" " $name$_ = $mutable_copy_list$;\n" " $set_mutable_bit_builder$;\n" " }\n" "}\n"); - + // Note: We return an unmodifiable list because otherwise the caller // could hold on to the returned list and modify it after the message // has been built, thus mutating the message which is supposed to be @@ -778,7 +778,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" "$null_check$" @@ -790,7 +790,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$$}$($type$ value) {\n" "$null_check$" @@ -802,7 +802,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $boxed_type$> values) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -823,8 +823,8 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -917,31 +917,31 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "}"); } -void RepeatedImmutablePrimitiveFieldGenerator:: +void RepeatedImmutablePrimitiveFieldGenerator:: GenerateFieldBuilderInitializationCode(io::Printer* printer) const { - // noop for primitives -} - + // noop for primitives +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = $empty_list$;\n"); -} - + printer->Print(variables_, "$name$_ = $empty_list$;\n"); +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "$name$_ = $empty_list$;\n" "$clear_mutable_bit_builder$;\n"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - // The code below does two optimizations: - // 1. If the other list is empty, there's nothing to do. This ensures we - // don't allocate a new array if we already have an immutable one. - // 2. If the other list is non-empty and our current list is empty, we can - // reuse the other list which is guaranteed to be immutable. - printer->Print(variables_, + // The code below does two optimizations: + // 1. If the other list is empty, there's nothing to do. This ensures we + // don't allocate a new array if we already have an immutable one. + // 2. If the other list is non-empty and our current list is empty, we can + // reuse the other list which is guaranteed to be immutable. + printer->Print(variables_, "if (!other.$name$_.isEmpty()) {\n" " if ($name$_.isEmpty()) {\n" " $name$_ = other.$name$_;\n" @@ -952,30 +952,30 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateMergingCode( " }\n" " $on_changed$\n" "}\n"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::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_, + // 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_make_immutable$;\n" " $clear_mutable_bit_builder$;\n" "}\n" "result.$name$_ = $name$_;\n"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - printer->Print(variables_, + 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"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateParsingCodeFromPacked( io::Printer* printer) const { printer->Print( @@ -990,23 +990,23 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateParsingCodeFromPacked( " $repeated_add$(input.read$capitalized_type$());\n" "}\n" "input.popLimit(limit);\n"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateParsingDoneCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($get_mutable_bit_parser$) {\n" " $name_make_immutable$; // C\n" "}\n"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - if (descriptor_->is_packed()) { - // We invoke getSerializedSize in writeTo for messages that have packed - // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods. - // That makes it safe to rely on the memoized size here. - printer->Print(variables_, + if (descriptor_->is_packed()) { + // We invoke getSerializedSize in writeTo for messages that have packed + // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods. + // That makes it safe to rely on the memoized size here. + printer->Print(variables_, "if (get$capitalized_name$List().size() > 0) {\n" " output.writeUInt32NoTag($tag$);\n" " output.writeUInt32NoTag($name$MemoizedSerializedSize);\n" @@ -1014,67 +1014,67 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateSerializationCode( "for (int i = 0; i < $name$_.size(); i++) {\n" " output.write$capitalized_type$NoTag($repeated_get$(i));\n" "}\n"); - } else { + } else { printer->Print( variables_, "for (int i = 0; i < $name$_.size(); i++) {\n" " output.write$capitalized_type$($number$, $repeated_get$(i));\n" "}\n"); - } -} - + } +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "{\n" " int dataSize = 0;\n"); - printer->Indent(); - - if (FixedSize(GetType(descriptor_)) == -1) { + printer->Indent(); + + if (FixedSize(GetType(descriptor_)) == -1) { printer->Print( variables_, "for (int i = 0; i < $name$_.size(); i++) {\n" " dataSize += com.google.protobuf.CodedOutputStream\n" " .compute$capitalized_type$SizeNoTag($repeated_get$(i));\n" "}\n"); - } else { + } else { printer->Print( variables_, "dataSize = $fixed_size$ * get$capitalized_name$List().size();\n"); - } - + } + printer->Print("size += dataSize;\n"); - - if (descriptor_->is_packed()) { - printer->Print(variables_, + + if (descriptor_->is_packed()) { + printer->Print(variables_, "if (!get$capitalized_name$List().isEmpty()) {\n" " size += $tag_size$;\n" " size += com.google.protobuf.CodedOutputStream\n" " .computeInt32SizeNoTag(dataSize);\n" "}\n"); - } else { + } else { printer->Print( variables_, "size += $tag_size$ * get$capitalized_name$List().size();\n"); - } - - // cache the data size for packed fields. - if (descriptor_->is_packed()) { + } + + // cache the data size for packed fields. + if (descriptor_->is_packed()) { printer->Print(variables_, "$name$MemoizedSerializedSize = dataSize;\n"); - } - - printer->Outdent(); - printer->Print("}\n"); -} - + } + + printer->Outdent(); + printer->Print("}\n"); +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { printer->Print( variables_, "if (!get$capitalized_name$List()\n" " .equals(other.get$capitalized_name$List())) return false;\n"); -} - +} + void RepeatedImmutablePrimitiveFieldGenerator::GenerateHashCode( io::Printer* printer) const { printer->Print( @@ -1083,13 +1083,13 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateHashCode( " hash = (37 * hash) + $constant_name$;\n" " hash = (53 * hash) + get$capitalized_name$List().hashCode();\n" "}\n"); -} - +} + TProtoStringType RepeatedImmutablePrimitiveFieldGenerator::GetBoxedType() const { - return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.h index b90ea89257..3eaf87810a 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field.h @@ -1,46 +1,46 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ - -#include <map> +// 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. + +#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/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -49,20 +49,20 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { - public: +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { + public: explicit ImmutablePrimitiveFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); ~ImmutablePrimitiveFieldGenerator() override; - + // implements ImmutableFieldGenerator // --------------------------------------- int GetNumBitsForMessage() const override; @@ -83,47 +83,47 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const override; void GenerateHashCode(io::Printer* printer) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - protected: - const FieldDescriptor* descriptor_; + + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveFieldGenerator); -}; - -class ImmutablePrimitiveOneofFieldGenerator - : public ImmutablePrimitiveFieldGenerator { - public: + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveFieldGenerator); +}; + +class ImmutablePrimitiveOneofFieldGenerator + : public ImmutablePrimitiveFieldGenerator { + public: ImmutablePrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); - ~ImmutablePrimitiveOneofFieldGenerator(); - - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldGenerator); -}; - -class RepeatedImmutablePrimitiveFieldGenerator - : public ImmutableFieldGenerator { - public: - explicit RepeatedImmutablePrimitiveFieldGenerator( - const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, Context* context); + ~ImmutablePrimitiveOneofFieldGenerator(); + + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldGenerator); +}; + +class RepeatedImmutablePrimitiveFieldGenerator + : public ImmutableFieldGenerator { + public: + explicit RepeatedImmutablePrimitiveFieldGenerator( + const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, Context* context); ~RepeatedImmutablePrimitiveFieldGenerator() override; - - // implements ImmutableFieldGenerator --------------------------------------- + + // implements ImmutableFieldGenerator --------------------------------------- int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -143,20 +143,20 @@ class RepeatedImmutablePrimitiveFieldGenerator void GenerateEqualsCode(io::Printer* printer) const override; void GenerateHashCode(io::Printer* printer) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; + + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.cc index 35f78fce9e..4a33227ea1 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.cc @@ -1,43 +1,43 @@ -// 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. - +// 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/java_primitive_field_lite.h> #include <cstdint> -#include <map> +#include <map> #include <string> - + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_context.h> @@ -47,16 +47,16 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -using internal::WireFormat; -using internal::WireFormatLite; - -namespace { + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +using internal::WireFormat; +using internal::WireFormatLite; + +namespace { bool EnableExperimentalRuntimeForLite() { #ifdef PROTOBUF_EXPERIMENT return PROTOBUF_EXPERIMENT; @@ -64,78 +64,78 @@ bool EnableExperimentalRuntimeForLite() { return false; #endif // !PROTOBUF_EXPERIMENT } - -void SetPrimitiveVariables(const FieldDescriptor* descriptor, + +void SetPrimitiveVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - JavaType javaType = GetJavaType(descriptor); - (*variables)["type"] = PrimitiveTypeName(javaType); - (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); + 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)["field_type"] = (*variables)["type"]; + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); + (*variables)["capitalized_type"] = + GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( - WireFormat::TagSize(descriptor->number(), GetType(descriptor))); + WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; - + TProtoStringType capitalized_type = UnderscoresToCamelCase( PrimitiveTypeName(javaType), true /* cap_next_letter */); - 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)["make_name_unmodifiable"] = - (*variables)["name"] + "_.makeImmutable()"; - (*variables)["repeated_get"] = - (*variables)["name"] + "_.get" + capitalized_type; - (*variables)["repeated_add"] = - (*variables)["name"] + "_.add" + capitalized_type; - (*variables)["repeated_set"] = - (*variables)["name"] + "_.set" + capitalized_type; - (*variables)["visit_type"] = capitalized_type; - (*variables)["visit_type_list"] = "visit" + capitalized_type + "List"; - break; - default: - (*variables)["field_list_type"] = - "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"; - (*variables)["visit_type"] = "ByteString"; - (*variables)["visit_type_list"] = "visitList"; - } - - if (javaType == JAVATYPE_BYTES) { - (*variables)["bytes_default"] = - ToUpper((*variables)["name"]) + "_DEFAULT_VALUE"; - } - - if (IsReferenceType(javaType)) { + 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)["make_name_unmodifiable"] = + (*variables)["name"] + "_.makeImmutable()"; + (*variables)["repeated_get"] = + (*variables)["name"] + "_.get" + capitalized_type; + (*variables)["repeated_add"] = + (*variables)["name"] + "_.add" + capitalized_type; + (*variables)["repeated_set"] = + (*variables)["name"] + "_.set" + capitalized_type; + (*variables)["visit_type"] = capitalized_type; + (*variables)["visit_type_list"] = "visit" + capitalized_type + "List"; + break; + default: + (*variables)["field_list_type"] = + "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"; + (*variables)["visit_type"] = "ByteString"; + (*variables)["visit_type_list"] = "visitList"; + } + + if (javaType == JAVATYPE_BYTES) { + (*variables)["bytes_default"] = + ToUpper((*variables)["name"]) + "_DEFAULT_VALUE"; + } + + if (IsReferenceType(javaType)) { // We use `x.getClass()` as a null check because it generates less bytecode // than an `if (x == null) { throw ... }` statement. (*variables)["null_check"] = " java.lang.Class<?> valueClass = value.getClass();\n"; - } else { - (*variables)["null_check"] = ""; - } - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + } else { + (*variables)["null_check"] = ""; + } + // 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"] = @@ -143,84 +143,84 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + " is deprecated\") " : ""; - int fixed_size = FixedSize(GetType(descriptor)); - if (fixed_size != -1) { + int fixed_size = FixedSize(GetType(descriptor)); + if (fixed_size != -1) { (*variables)["fixed_size"] = StrCat(fixed_size); - } - + } + if (HasHasbit(descriptor)) { - // 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) + ";"; - (*variables)["clear_has_field_bit_message"] = - GenerateClearBit(messageBitIndex) + ";"; - - (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); - } else { - (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_message"] = ""; - (*variables)["clear_has_field_bit_message"] = ""; - - if (descriptor->type() == FieldDescriptor::TYPE_BYTES) { - (*variables)["is_field_present_message"] = - "!" + (*variables)["name"] + "_.isEmpty()"; - } else { - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"]; - } - } - - (*variables)["get_has_field_bit_from_local"] = - GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); -} - -} // namespace - -// =================================================================== - + // 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) + ";"; + (*variables)["clear_has_field_bit_message"] = + GenerateClearBit(messageBitIndex) + ";"; + + (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); + } else { + (*variables)["set_has_field_bit_message"] = ""; + (*variables)["set_has_field_bit_message"] = ""; + (*variables)["clear_has_field_bit_message"] = ""; + + if (descriptor->type() == FieldDescriptor::TYPE_BYTES) { + (*variables)["is_field_present_message"] = + "!" + (*variables)["name"] + "_.isEmpty()"; + } else { + (*variables)["is_field_present_message"] = + (*variables)["name"] + "_ != " + (*variables)["default"]; + } + } + + (*variables)["get_has_field_bit_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); +} + +} // namespace + +// =================================================================== + ImmutablePrimitiveFieldLiteGenerator::ImmutablePrimitiveFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), messageBitIndex_(messageBitIndex), name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_); -} - -ImmutablePrimitiveFieldLiteGenerator::~ImmutablePrimitiveFieldLiteGenerator() {} - -int ImmutablePrimitiveFieldLiteGenerator::GetNumBitsForMessage() const { + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +ImmutablePrimitiveFieldLiteGenerator::~ImmutablePrimitiveFieldLiteGenerator() {} + +int ImmutablePrimitiveFieldLiteGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; -} - +} + void ImmutablePrimitiveFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); -} - +} + void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - if (IsByteStringWithCustomDefaultValue(descriptor_)) { - // allocate this once statically since we know ByteStrings are immutable - // values that can be reused. - printer->Print( - variables_, - "private static final $field_type$ $bytes_default$ = $default$;\n"); - } + if (IsByteStringWithCustomDefaultValue(descriptor_)) { + // allocate this once statically since we know ByteStrings are immutable + // values that can be reused. + printer->Print( + variables_, + "private static final $field_type$ $bytes_default$ = $default$;\n"); + } printer->Print(variables_, "private $field_type$ $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -230,41 +230,41 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$($type$ value) {\n" "$null_check$" " $set_has_field_bit_message$\n" " $name$_ = value;\n" "}\n"); - + WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " $clear_has_field_bit_message$\n"); - JavaType type = GetJavaType(descriptor_); - if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) { - // 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. + JavaType type = GetJavaType(descriptor_); + if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) { + // 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"); - } else { + } else { printer->Print(variables_, " $name$_ = $default$;\n"); - } + } printer->Print(variables_, "}\n"); -} - +} + void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { @@ -276,19 +276,19 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( " return instance.has$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -296,7 +296,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ true); printer->Print( @@ -307,8 +307,8 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -346,40 +346,40 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateFieldInfo( WriteIntToUtf16CharSequence(messageBitIndex_, output); } printer->Print(variables_, "\"$name$_\",\n"); -} - +} + void ImmutablePrimitiveFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - if (IsByteStringWithCustomDefaultValue(descriptor_)) { - printer->Print(variables_, "$name$_ = $bytes_default$;\n"); - } else if (!IsDefaultValueJavaDefault(descriptor_)) { - printer->Print(variables_, "$name$_ = $default$;\n"); - } -} - + if (IsByteStringWithCustomDefaultValue(descriptor_)) { + printer->Print(variables_, "$name$_ = $bytes_default$;\n"); + } else if (!IsDefaultValueJavaDefault(descriptor_)) { + printer->Print(variables_, "$name$_ = $default$;\n"); + } +} + TProtoStringType ImmutablePrimitiveFieldLiteGenerator::GetBoxedType() const { - return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); -} - -// =================================================================== - -ImmutablePrimitiveOneofFieldLiteGenerator:: + return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); +} + +// =================================================================== + +ImmutablePrimitiveOneofFieldLiteGenerator:: ImmutablePrimitiveOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : ImmutablePrimitiveFieldLiteGenerator(descriptor, messageBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - -ImmutablePrimitiveOneofFieldLiteGenerator:: + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + +ImmutablePrimitiveOneofFieldLiteGenerator:: ~ImmutablePrimitiveOneofFieldLiteGenerator() {} - + void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, @@ -388,9 +388,9 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers( " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" @@ -399,25 +399,25 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers( " return $default$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$($type$ value) {\n" "$null_check$" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" "}\n"); - + WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" " }\n" "}\n"); -} - +} + void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); @@ -425,29 +425,29 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateFieldInfo( output); WriteIntToUtf16CharSequence(descriptor_->containing_oneof()->index(), output); } - + void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -455,7 +455,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ true); printer->Print( @@ -466,11 +466,11 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - -// =================================================================== - -RepeatedImmutablePrimitiveFieldLiteGenerator:: +} + +// =================================================================== + +RepeatedImmutablePrimitiveFieldLiteGenerator:: RepeatedImmutablePrimitiveFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) @@ -478,37 +478,37 @@ RepeatedImmutablePrimitiveFieldLiteGenerator:: context_(context), name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_); -} - -RepeatedImmutablePrimitiveFieldLiteGenerator:: + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +RepeatedImmutablePrimitiveFieldLiteGenerator:: ~RepeatedImmutablePrimitiveFieldLiteGenerator() {} - -int RepeatedImmutablePrimitiveFieldLiteGenerator::GetNumBitsForMessage() const { - return 0; -} - + +int RepeatedImmutablePrimitiveFieldLiteGenerator::GetNumBitsForMessage() const { + return 0; +} + void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$java.util.List<$boxed_type$> " "get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$(int index);\n"); -} - +} + void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private $field_list_type$ $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<$boxed_type$>\n" " ${$get$capitalized_name$List$}$() {\n" @@ -531,13 +531,13 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateMembers( " return $repeated_get$(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + if (!EnableExperimentalRuntimeForLite() && descriptor_->is_packed() && - context_->HasGeneratedMethods(descriptor_->containing_type())) { - printer->Print(variables_, + context_->HasGeneratedMethods(descriptor_->containing_type())) { + printer->Print(variables_, "private int $name$MemoizedSerializedSize = -1;\n"); - } - + } + printer->Print( variables_, "private void ensure$capitalized_name$IsMutable() {\n" @@ -548,9 +548,9 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateMembers( " com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp);\n" " }\n" "}\n"); - + WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$(\n" " int index, $type$ value) {\n" "$null_check$" @@ -558,14 +558,14 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateMembers( " $repeated_set$(index, value);\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void add$capitalized_name$($type$ value) {\n" "$null_check$" " ensure$capitalized_name$IsMutable();\n" " $repeated_add$(value);\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void addAll$capitalized_name$(\n" " java.lang.Iterable<? extends $boxed_type$> values) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -573,16 +573,16 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateMembers( " values, $name$_);\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " $name$_ = $empty_list$;\n" "}\n"); -} - +} + void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<$boxed_type$>\n" " ${$get$capitalized_name$List$}$() {\n" @@ -608,7 +608,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" @@ -618,7 +618,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" @@ -628,7 +628,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $boxed_type$> values) {\n" " copyOnWrite();\n" @@ -646,8 +646,8 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -746,18 +746,18 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateFieldInfo( WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); printer->Print(variables_, "\"$name$_\",\n"); -} - +} + void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = $empty_list$;\n"); -} - + printer->Print(variables_, "$name$_ = $empty_list$;\n"); +} + TProtoStringType RepeatedImmutablePrimitiveFieldLiteGenerator::GetBoxedType() const { - return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.h index 1359c358df..32f113e0f2 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_primitive_field_lite.h @@ -1,48 +1,48 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ - +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ + #include <cstdint> -#include <map> +#include <map> #include <string> #include <google/protobuf/compiler/java/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -51,19 +51,19 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutablePrimitiveFieldLiteGenerator - : public ImmutableFieldLiteGenerator { - public: - explicit ImmutablePrimitiveFieldLiteGenerator( +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutablePrimitiveFieldLiteGenerator + : public ImmutableFieldLiteGenerator { + public: + explicit ImmutablePrimitiveFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~ImmutablePrimitiveFieldLiteGenerator() override; - + // implements ImmutableFieldLiteGenerator // ------------------------------------ int GetNumBitsForMessage() const override; @@ -74,45 +74,45 @@ class ImmutablePrimitiveFieldLiteGenerator void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - protected: - const FieldDescriptor* descriptor_; + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - const int messageBitIndex_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveFieldLiteGenerator); -}; - -class ImmutablePrimitiveOneofFieldLiteGenerator - : public ImmutablePrimitiveFieldLiteGenerator { - public: + const int messageBitIndex_; + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveFieldLiteGenerator); +}; + +class ImmutablePrimitiveOneofFieldLiteGenerator + : public ImmutablePrimitiveFieldLiteGenerator { + public: ImmutablePrimitiveOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ~ImmutablePrimitiveOneofFieldLiteGenerator(); - - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - + ~ImmutablePrimitiveOneofFieldLiteGenerator(); + + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const; - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldLiteGenerator); -}; - -class RepeatedImmutablePrimitiveFieldLiteGenerator - : public ImmutableFieldLiteGenerator { - public: - explicit RepeatedImmutablePrimitiveFieldLiteGenerator( + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldLiteGenerator); +}; + +class RepeatedImmutablePrimitiveFieldLiteGenerator + : public ImmutableFieldLiteGenerator { + public: + explicit RepeatedImmutablePrimitiveFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~RepeatedImmutablePrimitiveFieldLiteGenerator() override; - - // implements ImmutableFieldLiteGenerator ------------------------------------ + + // implements ImmutableFieldLiteGenerator ------------------------------------ int GetNumBitsForMessage() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; void GenerateMembers(io::Printer* printer) const override; @@ -121,21 +121,21 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - private: - const FieldDescriptor* descriptor_; + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - Context* context_; - ClassNameResolver* name_resolver_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + Context* context_; + ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.cc index 05748f5847..7d08703c17 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.cc @@ -1,88 +1,88 @@ -// 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. - +// 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/java_service.h> - + #include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor) + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor) : descriptor_(descriptor) {} - -ServiceGenerator::~ServiceGenerator() {} - -// =================================================================== -ImmutableServiceGenerator::ImmutableServiceGenerator( - const ServiceDescriptor* descriptor, Context* context) + +ServiceGenerator::~ServiceGenerator() {} + +// =================================================================== +ImmutableServiceGenerator::ImmutableServiceGenerator( + const ServiceDescriptor* descriptor, Context* context) : ServiceGenerator(descriptor), context_(context), name_resolver_(context->GetNameResolver()) {} - -ImmutableServiceGenerator::~ImmutableServiceGenerator() {} - -void ImmutableServiceGenerator::Generate(io::Printer* printer) { - bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - WriteServiceDocComment(printer, descriptor_); - MaybePrintGeneratedAnnotation(context_, printer, descriptor_, - /* immutable = */ true); - printer->Print( + +ImmutableServiceGenerator::~ImmutableServiceGenerator() {} + +void ImmutableServiceGenerator::Generate(io::Printer* printer) { + bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); + WriteServiceDocComment(printer, descriptor_); + MaybePrintGeneratedAnnotation(context_, printer, descriptor_, + /* immutable = */ true); + printer->Print( "public $static$ abstract class $classname$\n" " implements com.google.protobuf.Service {\n", "static", is_own_file ? "" : "static", "classname", descriptor_->name()); - printer->Indent(); - + printer->Indent(); + printer->Print("protected $classname$() {}\n\n", "classname", descriptor_->name()); - - GenerateInterface(printer); - - GenerateNewReflectiveServiceMethod(printer); - GenerateNewReflectiveBlockingServiceMethod(printer); - - GenerateAbstractMethods(printer); - - // Generate getDescriptor() and getDescriptorForType(). - printer->Print( + + GenerateInterface(printer); + + GenerateNewReflectiveServiceMethod(printer); + GenerateNewReflectiveBlockingServiceMethod(printer); + + GenerateAbstractMethods(printer); + + // Generate getDescriptor() and getDescriptorForType(). + printer->Print( "public static final\n" " com.google.protobuf.Descriptors.ServiceDescriptor\n" " getDescriptor() {\n" @@ -90,106 +90,106 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) { "}\n", "file", name_resolver_->GetImmutableClassName(descriptor_->file()), "index", StrCat(descriptor_->index())); - GenerateGetDescriptorForType(printer); - - // Generate more stuff. - GenerateCallMethod(printer); - GenerateGetPrototype(REQUEST, printer); - GenerateGetPrototype(RESPONSE, printer); - GenerateStub(printer); - GenerateBlockingStub(printer); - - // Add an insertion point. - printer->Print( + GenerateGetDescriptorForType(printer); + + // Generate more stuff. + GenerateCallMethod(printer); + GenerateGetPrototype(REQUEST, printer); + GenerateGetPrototype(RESPONSE, printer); + GenerateStub(printer); + GenerateBlockingStub(printer); + + // Add an insertion point. + printer->Print( "\n" "// @@protoc_insertion_point(class_scope:$full_name$)\n", "full_name", descriptor_->full_name()); - - printer->Outdent(); - printer->Print("}\n\n"); -} - -void ImmutableServiceGenerator::GenerateGetDescriptorForType( - io::Printer* printer) { - printer->Print( + + printer->Outdent(); + printer->Print("}\n\n"); +} + +void ImmutableServiceGenerator::GenerateGetDescriptorForType( + io::Printer* printer) { + printer->Print( "public final com.google.protobuf.Descriptors.ServiceDescriptor\n" " getDescriptorForType() {\n" " return getDescriptor();\n" "}\n"); -} - -void ImmutableServiceGenerator::GenerateInterface(io::Printer* printer) { - printer->Print("public interface Interface {\n"); - printer->Indent(); - GenerateAbstractMethods(printer); - printer->Outdent(); - printer->Print("}\n\n"); -} - -void ImmutableServiceGenerator::GenerateNewReflectiveServiceMethod( - io::Printer* printer) { - printer->Print( +} + +void ImmutableServiceGenerator::GenerateInterface(io::Printer* printer) { + printer->Print("public interface Interface {\n"); + printer->Indent(); + GenerateAbstractMethods(printer); + printer->Outdent(); + printer->Print("}\n\n"); +} + +void ImmutableServiceGenerator::GenerateNewReflectiveServiceMethod( + io::Printer* printer) { + printer->Print( "public static com.google.protobuf.Service newReflectiveService(\n" " final Interface impl) {\n" " return new $classname$() {\n", "classname", descriptor_->name()); - printer->Indent(); - printer->Indent(); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); - printer->Print("@java.lang.Override\n"); - GenerateMethodSignature(printer, method, IS_CONCRETE); - printer->Print( + printer->Indent(); + printer->Indent(); + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + printer->Print("@java.lang.Override\n"); + GenerateMethodSignature(printer, method, IS_CONCRETE); + printer->Print( " {\n" " impl.$method$(controller, request, done);\n" "}\n\n", "method", UnderscoresToCamelCase(method)); - } - - printer->Outdent(); - printer->Print("};\n"); - printer->Outdent(); - printer->Print("}\n\n"); -} - -void ImmutableServiceGenerator::GenerateNewReflectiveBlockingServiceMethod( - io::Printer* printer) { - printer->Print( + } + + printer->Outdent(); + printer->Print("};\n"); + printer->Outdent(); + printer->Print("}\n\n"); +} + +void ImmutableServiceGenerator::GenerateNewReflectiveBlockingServiceMethod( + io::Printer* printer) { + printer->Print( "public static com.google.protobuf.BlockingService\n" " newReflectiveBlockingService(final BlockingInterface impl) {\n" " return new com.google.protobuf.BlockingService() {\n"); - printer->Indent(); - printer->Indent(); - - GenerateGetDescriptorForType(printer); - - GenerateCallBlockingMethod(printer); - GenerateGetPrototype(REQUEST, printer); - GenerateGetPrototype(RESPONSE, printer); - - printer->Outdent(); - printer->Print("};\n"); - printer->Outdent(); - printer->Print("}\n\n"); -} - -void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); - WriteMethodDocComment(printer, method); - GenerateMethodSignature(printer, method, IS_ABSTRACT); - printer->Print(";\n\n"); - } -} - + printer->Indent(); + printer->Indent(); + + GenerateGetDescriptorForType(printer); + + GenerateCallBlockingMethod(printer); + GenerateGetPrototype(REQUEST, printer); + GenerateGetPrototype(RESPONSE, printer); + + printer->Outdent(); + printer->Print("};\n"); + printer->Outdent(); + printer->Print("}\n\n"); +} + +void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) { + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + WriteMethodDocComment(printer, method); + GenerateMethodSignature(printer, method, IS_ABSTRACT); + printer->Print(";\n\n"); + } +} + TProtoStringType ImmutableServiceGenerator::GetOutput( const MethodDescriptor* method) { return name_resolver_->GetImmutableClassName(method->output_type()); } -void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { - printer->Print( +void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { + printer->Print( "\n" "public final void callMethod(\n" " com.google.protobuf.Descriptors.MethodDescriptor method,\n" @@ -203,14 +203,14 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { " \"service type.\");\n" " }\n" " switch(method.getIndex()) {\n"); - printer->Indent(); - printer->Indent(); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); + printer->Indent(); + printer->Indent(); + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); std::map<TProtoStringType, TProtoStringType> vars; vars["index"] = StrCat(i); - vars["method"] = UnderscoresToCamelCase(method); + vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); printer->Print( @@ -220,24 +220,24 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { " com.google.protobuf.RpcUtil.<$output$>specializeCallback(\n" " done));\n" " return;\n"); - } - - printer->Print( + } + + printer->Print( "default:\n" " throw new java.lang.AssertionError(\"Can't get here.\");\n"); - - printer->Outdent(); - printer->Outdent(); - - printer->Print( + + printer->Outdent(); + printer->Outdent(); + + printer->Print( " }\n" "}\n" "\n"); -} - -void ImmutableServiceGenerator::GenerateCallBlockingMethod( - io::Printer* printer) { - printer->Print( +} + +void ImmutableServiceGenerator::GenerateCallBlockingMethod( + io::Printer* printer) { + printer->Print( "\n" "public final com.google.protobuf.Message callBlockingMethod(\n" " com.google.protobuf.Descriptors.MethodDescriptor method,\n" @@ -250,41 +250,41 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod( " \"wrong service type.\");\n" " }\n" " switch(method.getIndex()) {\n"); - printer->Indent(); - printer->Indent(); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); + printer->Indent(); + printer->Indent(); + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); std::map<TProtoStringType, TProtoStringType> vars; vars["index"] = StrCat(i); - vars["method"] = UnderscoresToCamelCase(method); + vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); - printer->Print(vars, + printer->Print(vars, "case $index$:\n" " return impl.$method$(controller, ($input$)request);\n"); - } - - printer->Print( + } + + printer->Print( "default:\n" " throw new java.lang.AssertionError(\"Can't get here.\");\n"); - - printer->Outdent(); - printer->Outdent(); - - printer->Print( + + printer->Outdent(); + printer->Outdent(); + + printer->Print( " }\n" "}\n" "\n"); -} - -void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, +} + +void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, io::Printer* printer) { - /* - * TODO(cpovirk): The exception message says "Service.foo" when it may be - * "BlockingService.foo." Consider fixing. - */ - printer->Print( + /* + * TODO(cpovirk): The exception message says "Service.foo" when it may be + * "BlockingService.foo." Consider fixing. + */ + printer->Print( "public final com.google.protobuf.Message\n" " get$request_or_response$Prototype(\n" " com.google.protobuf.Descriptors.MethodDescriptor method) {\n" @@ -295,37 +295,37 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, " }\n" " switch(method.getIndex()) {\n", "request_or_response", (which == REQUEST) ? "Request" : "Response"); - printer->Indent(); - printer->Indent(); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); + printer->Indent(); + printer->Indent(); + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); std::map<TProtoStringType, TProtoStringType> vars; vars["index"] = StrCat(i); vars["type"] = (which == REQUEST) ? name_resolver_->GetImmutableClassName(method->input_type()) : GetOutput(method); - printer->Print(vars, + printer->Print(vars, "case $index$:\n" " return $type$.getDefaultInstance();\n"); - } - - printer->Print( + } + + printer->Print( "default:\n" " throw new java.lang.AssertionError(\"Can't get here.\");\n"); - - printer->Outdent(); - printer->Outdent(); - - printer->Print( + + printer->Outdent(); + printer->Outdent(); + + printer->Print( " }\n" "}\n" "\n"); -} - -void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { - printer->Print( +} + +void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { + printer->Print( "public static Stub newStub(\n" " com.google.protobuf.RpcChannel channel) {\n" " return new Stub(channel);\n" @@ -335,9 +335,9 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { "{" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - printer->Indent(); - - printer->Print( + printer->Indent(); + + printer->Print( "private Stub(com.google.protobuf.RpcChannel channel) {\n" " this.channel = channel;\n" "}\n" @@ -347,18 +347,18 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { "public com.google.protobuf.RpcChannel getChannel() {\n" " return channel;\n" "}\n"); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); - printer->Print("\n"); - GenerateMethodSignature(printer, method, IS_CONCRETE); - printer->Print(" {\n"); - printer->Indent(); - + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + printer->Print("\n"); + GenerateMethodSignature(printer, method, IS_CONCRETE); + printer->Print(" {\n"); + printer->Indent(); + std::map<TProtoStringType, TProtoStringType> vars; vars["index"] = StrCat(i); vars["output"] = GetOutput(method); - printer->Print(vars, + printer->Print(vars, "channel.callMethod(\n" " getDescriptor().getMethods().get($index$),\n" " controller,\n" @@ -368,107 +368,107 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { " done,\n" " $output$.class,\n" " $output$.getDefaultInstance()));\n"); - - printer->Outdent(); - printer->Print("}\n"); - } - - printer->Outdent(); - printer->Print( + + printer->Outdent(); + printer->Print("}\n"); + } + + printer->Outdent(); + printer->Print( "}\n" "\n"); -} - -void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { - printer->Print( +} + +void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { + printer->Print( "public static BlockingInterface newBlockingStub(\n" " com.google.protobuf.BlockingRpcChannel channel) {\n" " return new BlockingStub(channel);\n" "}\n" "\n"); - + printer->Print("public interface BlockingInterface {"); - printer->Indent(); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); - GenerateBlockingMethodSignature(printer, method); - printer->Print(";\n"); - } - - printer->Outdent(); - printer->Print( + printer->Indent(); + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + GenerateBlockingMethodSignature(printer, method); + printer->Print(";\n"); + } + + printer->Outdent(); + printer->Print( "}\n" "\n"); - - printer->Print( + + printer->Print( "private static final class BlockingStub implements BlockingInterface " "{\n"); - printer->Indent(); - - printer->Print( + printer->Indent(); + + printer->Print( "private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {\n" " this.channel = channel;\n" "}\n" "\n" "private final com.google.protobuf.BlockingRpcChannel channel;\n"); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); - GenerateBlockingMethodSignature(printer, method); - printer->Print(" {\n"); - printer->Indent(); - + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + GenerateBlockingMethodSignature(printer, method); + printer->Print(" {\n"); + printer->Indent(); + std::map<TProtoStringType, TProtoStringType> vars; vars["index"] = StrCat(i); vars["output"] = GetOutput(method); - printer->Print(vars, + printer->Print(vars, "return ($output$) channel.callBlockingMethod(\n" " getDescriptor().getMethods().get($index$),\n" " controller,\n" " request,\n" " $output$.getDefaultInstance());\n"); - - printer->Outdent(); - printer->Print( + + printer->Outdent(); + printer->Print( "}\n" "\n"); - } - - printer->Outdent(); - printer->Print("}\n"); -} - + } + + printer->Outdent(); + printer->Print("}\n"); +} + void ImmutableServiceGenerator::GenerateMethodSignature( io::Printer* printer, const MethodDescriptor* method, IsAbstract is_abstract) { std::map<TProtoStringType, TProtoStringType> vars; - vars["name"] = UnderscoresToCamelCase(method); - vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); + vars["name"] = UnderscoresToCamelCase(method); + vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); - vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : ""; - printer->Print(vars, + vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : ""; + printer->Print(vars, "public $abstract$ void $name$(\n" " com.google.protobuf.RpcController controller,\n" " $input$ request,\n" " com.google.protobuf.RpcCallback<$output$> done)"); -} - -void ImmutableServiceGenerator::GenerateBlockingMethodSignature( +} + +void ImmutableServiceGenerator::GenerateBlockingMethodSignature( io::Printer* printer, const MethodDescriptor* method) { std::map<TProtoStringType, TProtoStringType> vars; - vars["method"] = UnderscoresToCamelCase(method); - vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); + vars["method"] = UnderscoresToCamelCase(method); + vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); - printer->Print(vars, + printer->Print(vars, "\n" "public $output$ $method$(\n" " com.google.protobuf.RpcController controller,\n" " $input$ request)\n" " throws com.google.protobuf.ServiceException"); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.h index e3d52a40ca..971efd5fc9 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_service.h @@ -1,45 +1,45 @@ -// 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. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ - -#include <map> +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ + +#include <map> #include <google/protobuf/descriptor.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -48,92 +48,92 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler namespace io { class Printer; // printer.h -} +} } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ServiceGenerator { - public: - explicit ServiceGenerator(const ServiceDescriptor* descriptor); - virtual ~ServiceGenerator(); - - virtual void Generate(io::Printer* printer) = 0; - - enum RequestOrResponse { REQUEST, RESPONSE }; - enum IsAbstract { IS_ABSTRACT, IS_CONCRETE }; - - protected: - const ServiceDescriptor* descriptor_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); -}; - -class ImmutableServiceGenerator : public ServiceGenerator { - public: - ImmutableServiceGenerator(const ServiceDescriptor* descriptor, - Context* context); - virtual ~ImmutableServiceGenerator(); - - virtual void Generate(io::Printer* printer); - - private: - // Generate the getDescriptorForType() method. - void GenerateGetDescriptorForType(io::Printer* printer); - - // Generate a Java interface for the service. - void GenerateInterface(io::Printer* printer); - - // Generate newReflectiveService() method. - void GenerateNewReflectiveServiceMethod(io::Printer* printer); - - // Generate newReflectiveBlockingService() method. - void GenerateNewReflectiveBlockingServiceMethod(io::Printer* printer); - - // Generate abstract method declarations for all methods. - void GenerateAbstractMethods(io::Printer* printer); - - // Generate the implementation of Service.callMethod(). - void GenerateCallMethod(io::Printer* printer); - - // Generate the implementation of BlockingService.callBlockingMethod(). - void GenerateCallBlockingMethod(io::Printer* printer); - - // Generate the implementations of Service.get{Request,Response}Prototype(). - void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); - - // Generate a stub implementation of the service. - void GenerateStub(io::Printer* printer); - - // Generate a method signature, possibly abstract, without body or trailing - // semicolon. - void GenerateMethodSignature(io::Printer* printer, - const MethodDescriptor* method, - IsAbstract is_abstract); - - // Generate a blocking stub interface and implementation of the service. - void GenerateBlockingStub(io::Printer* printer); - - // Generate the method signature for one method of a blocking stub. - void GenerateBlockingMethodSignature(io::Printer* printer, - const MethodDescriptor* method); - +namespace protobuf { +namespace compiler { +namespace java { + +class ServiceGenerator { + public: + explicit ServiceGenerator(const ServiceDescriptor* descriptor); + virtual ~ServiceGenerator(); + + virtual void Generate(io::Printer* printer) = 0; + + enum RequestOrResponse { REQUEST, RESPONSE }; + enum IsAbstract { IS_ABSTRACT, IS_CONCRETE }; + + protected: + const ServiceDescriptor* descriptor_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); +}; + +class ImmutableServiceGenerator : public ServiceGenerator { + public: + ImmutableServiceGenerator(const ServiceDescriptor* descriptor, + Context* context); + virtual ~ImmutableServiceGenerator(); + + virtual void Generate(io::Printer* printer); + + private: + // Generate the getDescriptorForType() method. + void GenerateGetDescriptorForType(io::Printer* printer); + + // Generate a Java interface for the service. + void GenerateInterface(io::Printer* printer); + + // Generate newReflectiveService() method. + void GenerateNewReflectiveServiceMethod(io::Printer* printer); + + // Generate newReflectiveBlockingService() method. + void GenerateNewReflectiveBlockingServiceMethod(io::Printer* printer); + + // Generate abstract method declarations for all methods. + void GenerateAbstractMethods(io::Printer* printer); + + // Generate the implementation of Service.callMethod(). + void GenerateCallMethod(io::Printer* printer); + + // Generate the implementation of BlockingService.callBlockingMethod(). + void GenerateCallBlockingMethod(io::Printer* printer); + + // Generate the implementations of Service.get{Request,Response}Prototype(). + void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); + + // Generate a stub implementation of the service. + void GenerateStub(io::Printer* printer); + + // Generate a method signature, possibly abstract, without body or trailing + // semicolon. + void GenerateMethodSignature(io::Printer* printer, + const MethodDescriptor* method, + IsAbstract is_abstract); + + // Generate a blocking stub interface and implementation of the service. + void GenerateBlockingStub(io::Printer* printer); + + // Generate the method signature for one method of a blocking stub. + void GenerateBlockingMethodSignature(io::Printer* printer, + const MethodDescriptor* method); + // Return the output type of the method. TProtoStringType GetOutput(const MethodDescriptor* method); - Context* context_; - ClassNameResolver* name_resolver_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableServiceGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + Context* context_; + ClassNameResolver* name_resolver_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableServiceGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // NET_PROTO2_COMPILER_JAVA_SERVICE_H__ + +#endif // NET_PROTO2_COMPILER_JAVA_SERVICE_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.cc index a0d5e2b45f..50683b6108 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.cc @@ -1,39 +1,39 @@ -// 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: xiaofeng@google.com (Feng Xiao) - +// 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: xiaofeng@google.com (Feng Xiao) + #include <google/protobuf/compiler/java/java_shared_code_generator.h> - -#include <memory> - + +#include <memory> + #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/compiler/java/java_names.h> @@ -43,125 +43,125 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -SharedCodeGenerator::SharedCodeGenerator(const FileDescriptor* file, - const Options& options) - : name_resolver_(new ClassNameResolver), file_(file), options_(options) {} - + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +SharedCodeGenerator::SharedCodeGenerator(const FileDescriptor* file, + const Options& options) + : name_resolver_(new ClassNameResolver), 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 package_dir = JavaPackageToDir(java_package); - - if (HasDescriptorMethods(file_, options_.enforce_lite)) { - // Generate descriptors. + + if (HasDescriptorMethods(file_, options_.enforce_lite)) { + // Generate descriptors. TProtoStringType classname = name_resolver_->GetDescriptorClassName(file_); TProtoStringType filename = package_dir + classname + ".java"; - file_list->push_back(filename); + file_list->push_back(filename); std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename)); - GeneratedCodeInfo annotations; - io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( - &annotations); + GeneratedCodeInfo annotations; + io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( + &annotations); std::unique_ptr<io::Printer> printer( - new io::Printer(output.get(), '$', - options_.annotate_code ? &annotation_collector : NULL)); + 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"; - printer->Print( - "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" - "// source: $filename$\n" - "\n", - "filename", file_->name()); - if (!java_package.empty()) { - printer->Print( + printer->Print( + "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" + "// source: $filename$\n" + "\n", + "filename", file_->name()); + if (!java_package.empty()) { + printer->Print( "package $package$;\n" "\n", "package", java_package); - } - PrintGeneratedAnnotation(printer.get(), '$', - options_.annotate_code ? info_relative_path : ""); - printer->Print( - "public final class $classname$ {\n" - " public static com.google.protobuf.Descriptors.FileDescriptor\n" - " descriptor;\n" - " static {\n", - "classname", classname); - printer->Annotate("classname", file_->name()); - printer->Indent(); - printer->Indent(); - GenerateDescriptors(printer.get()); - printer->Outdent(); - printer->Outdent(); - printer->Print( + } + PrintGeneratedAnnotation(printer.get(), '$', + options_.annotate_code ? info_relative_path : ""); + printer->Print( + "public final class $classname$ {\n" + " public static com.google.protobuf.Descriptors.FileDescriptor\n" + " descriptor;\n" + " static {\n", + "classname", classname); + printer->Annotate("classname", file_->name()); + printer->Indent(); + printer->Indent(); + GenerateDescriptors(printer.get()); + printer->Outdent(); + printer->Outdent(); + printer->Print( " }\n" "}\n"); - - if (options_.annotate_code) { + + if (options_.annotate_code) { std::unique_ptr<io::ZeroCopyOutputStream> info_output( - context->Open(info_full_path)); - annotations.SerializeToZeroCopyStream(info_output.get()); - annotation_file_list->push_back(info_full_path); - } - - printer.reset(); - output.reset(); - } -} - -void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { - // Embed the descriptor. We simply serialize the entire FileDescriptorProto - // and embed it as a string literal, which is parsed and built into real - // descriptors at initialization time. We unfortunately have to put it in - // a string literal, not a byte array, because apparently using a literal - // byte array causes the Java compiler to generate *instructions* to - // initialize each and every byte of the array, e.g. as if you typed: - // b[0] = 123; b[1] = 456; b[2] = 789; - // 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); - + context->Open(info_full_path)); + annotations.SerializeToZeroCopyStream(info_output.get()); + annotation_file_list->push_back(info_full_path); + } + + printer.reset(); + output.reset(); + } +} + +void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { + // Embed the descriptor. We simply serialize the entire FileDescriptorProto + // and embed it as a string literal, which is parsed and built into real + // descriptors at initialization time. We unfortunately have to put it in + // a string literal, not a byte array, because apparently using a literal + // byte array causes the Java compiler to generate *instructions* to + // initialize each and every byte of the array, e.g. as if you typed: + // b[0] = 123; b[1] = 456; b[2] = 789; + // 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); + TProtoStringType file_data; - file_proto.SerializeToString(&file_data); - + file_proto.SerializeToString(&file_data); + printer->Print("java.lang.String[] descriptorData = {\n"); - printer->Indent(); - + printer->Indent(); + // Limit the number of bytes per line. - static const int kBytesPerLine = 40; + static const int kBytesPerLine = 40; // Limit the number of lines per string part. static const int kLinesPerPart = 400; // Every block of bytes, start a new string literal, in order to avoid the // 64k length limit. Note that this value needs to be <64k. static const int kBytesPerPart = kBytesPerLine * kLinesPerPart; - for (int i = 0; i < file_data.size(); i += kBytesPerLine) { - if (i > 0) { + for (int i = 0; i < file_data.size(); i += kBytesPerLine) { + if (i > 0) { if (i % kBytesPerPart == 0) { - printer->Print(",\n"); - } else { - printer->Print(" +\n"); - } - } + printer->Print(",\n"); + } else { + printer->Print(" +\n"); + } + } printer->Print("\"$data$\"", "data", CEscape(file_data.substr(i, kBytesPerLine))); - } - - printer->Outdent(); - printer->Print("\n};\n"); - - // ----------------------------------------------------------------- - // Find out all dependencies. + } + + printer->Outdent(); + printer->Print("\n};\n"); + + // ----------------------------------------------------------------- + // Find out all dependencies. std::vector<std::pair<TProtoStringType, TProtoStringType> > dependencies; - for (int i = 0; i < file_->dependency_count(); i++) { + for (int i = 0; i < file_->dependency_count(); i++) { TProtoStringType filename = file_->dependency(i)->name(); TProtoStringType package = FileJavaPackage(file_->dependency(i)); TProtoStringType classname = @@ -173,26 +173,26 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { full_name = package + "." + classname; } dependencies.push_back(std::make_pair(filename, full_name)); - } - - // ----------------------------------------------------------------- - // Invoke internalBuildGeneratedFileFrom() to build the file. - printer->Print( + } + + // ----------------------------------------------------------------- + // Invoke internalBuildGeneratedFileFrom() to build the file. + printer->Print( "descriptor = com.google.protobuf.Descriptors.FileDescriptor\n" " .internalBuildGeneratedFileFrom(descriptorData,\n"); - printer->Print( + printer->Print( " new com.google.protobuf.Descriptors.FileDescriptor[] {\n"); - - for (int i = 0; i < dependencies.size(); i++) { + + for (int i = 0; i < dependencies.size(); i++) { const TProtoStringType& dependency = dependencies[i].second; printer->Print(" $dependency$.getDescriptor(),\n", "dependency", dependency); - } - + } + printer->Print(" });\n"); -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.h index 93fe6d7996..85bab9ed52 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_shared_code_generator.h @@ -1,90 +1,90 @@ -// 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: xiaofeng@google.com (Feng Xiao) -// -// Generators that generate shared code between immutable API and mutable API. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__ - -#include <memory> +// 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: xiaofeng@google.com (Feng Xiao) +// +// Generators that generate shared code between immutable API and mutable API. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__ + +#include <memory> #include <string> -#include <vector> - +#include <vector> + #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_options.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { class FileDescriptor; // descriptor.h namespace compiler { class GeneratorContext; // code_generator.h namespace java { class ClassNameResolver; // name_resolver.h -} +} } // namespace compiler namespace io { class Printer; // printer.h } } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// A generator that generates code that are shared between immutable API -// and mutable API. Currently only descriptors are shared. -class SharedCodeGenerator { - public: - SharedCodeGenerator(const FileDescriptor* file, const Options& options); - ~SharedCodeGenerator(); - +namespace protobuf { +namespace compiler { +namespace java { + +// A generator that generates code that are shared between immutable API +// and mutable API. Currently only descriptors are shared. +class SharedCodeGenerator { + public: + SharedCodeGenerator(const FileDescriptor* file, const Options& options); + ~SharedCodeGenerator(); + void Generate(GeneratorContext* generator_context, std::vector<TProtoStringType>* file_list, std::vector<TProtoStringType>* annotation_file_list); - - void GenerateDescriptors(io::Printer* printer); - - private: + + void GenerateDescriptors(io::Printer* printer); + + private: std::unique_ptr<ClassNameResolver> name_resolver_; - const FileDescriptor* file_; - const Options options_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SharedCodeGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + const FileDescriptor* file_; + const Options options_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SharedCodeGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.cc index e0019a5ffe..04acfc1461 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.cc @@ -1,44 +1,44 @@ -// 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) -// Author: jonp@google.com (Jon Perlow) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - +// 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) +// Author: jonp@google.com (Jon Perlow) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + #include <google/protobuf/compiler/java/java_string_field.h> #include <cstdint> -#include <map> +#include <map> #include <string> - + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_context.h> @@ -48,46 +48,46 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -using internal::WireFormat; -using internal::WireFormatLite; - -namespace { - -void SetPrimitiveVariables(const FieldDescriptor* descriptor, + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +using internal::WireFormat; +using internal::WireFormatLite; + +namespace { + +void SetPrimitiveVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - SetCommonFieldVariables(descriptor, info, variables); - - (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; - - (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); - (*variables)["default_init"] = - "= " + ImmutableDefaultValue(descriptor, name_resolver); - (*variables)["capitalized_type"] = "String"; + SetCommonFieldVariables(descriptor, info, variables); + + (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; + + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); + (*variables)["default_init"] = + "= " + ImmutableDefaultValue(descriptor, name_resolver); + (*variables)["capitalized_type"] = "String"; (*variables)["tag"] = StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( - WireFormat::TagSize(descriptor->number(), GetType(descriptor))); - (*variables)["null_check"] = - " if (value == null) {\n" - " throw new NullPointerException();\n" - " }\n"; + WireFormat::TagSize(descriptor->number(), GetType(descriptor))); + (*variables)["null_check"] = + " if (value == null) {\n" + " throw new NullPointerException();\n" + " }\n"; (*variables)["writeString"] = "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + ".writeString"; (*variables)["computeStringSize"] = "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + ".computeStringSize"; - - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + + // 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"] = @@ -95,125 +95,125 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + " is deprecated\") " : ""; - (*variables)["on_changed"] = "onChanged();"; - + (*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)["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"] = - "!get" + (*variables)["capitalized_name"] + "Bytes().isEmpty()"; - } - - // 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_from_local"] = - GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); -} - -} // namespace - -// =================================================================== - + // 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)["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"] = + "!get" + (*variables)["capitalized_name"] + "Bytes().isEmpty()"; + } + + // 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_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); +} + +} // namespace + +// =================================================================== + ImmutableStringFieldGenerator::ImmutableStringFieldGenerator( 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::~ImmutableStringFieldGenerator() {} - -int ImmutableStringFieldGenerator::GetNumBitsForMessage() const { + SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +ImmutableStringFieldGenerator::~ImmutableStringFieldGenerator() {} + +int ImmutableStringFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; -} - -int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const { +} + +int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const { return GetNumBitsForMessage(); -} - -// A note about how strings are handled. This code used to just store a String -// in the Message. This had two issues: -// +} + +// A note about how strings are handled. This code used to just store a String +// in the Message. This had two issues: +// // 1. It wouldn't roundtrip byte arrays that were not valid UTF-8 encoded -// strings, but rather fields that were raw bytes incorrectly marked -// as strings in the proto file. This is common because in the proto1 -// syntax, string was the way to indicate bytes and C++ engineers can -// easily make this mistake without affecting the C++ API. By converting to -// strings immediately, some java code might corrupt these byte arrays as -// it passes through a java server even if the field was never accessed by -// application code. -// -// 2. There's a performance hit to converting between bytes and strings and -// it many cases, the field is never even read by the application code. This -// avoids unnecessary conversions in the common use cases. -// -// So now, the field for String is maintained as an Object reference which can -// either store a String or a ByteString. The code uses an instanceof check -// to see which one it has and converts to the other one if needed. It remembers -// the last value requested (in a thread safe manner) as this is most likely -// the one needed next. The thread safety is such that if two threads both -// convert the field because the changes made by each thread were not visible to -// the other, they may cause a conversion to happen more times than would -// otherwise be necessary. This was deemed better than adding synchronization -// overhead. It will not cause any corruption issues or affect the behavior of -// the API. The instanceof check is also highly optimized in the JVM and we -// decided it was better to reduce the memory overhead by not having two -// 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. +// strings, but rather fields that were raw bytes incorrectly marked +// as strings in the proto file. This is common because in the proto1 +// syntax, string was the way to indicate bytes and C++ engineers can +// easily make this mistake without affecting the C++ API. By converting to +// strings immediately, some java code might corrupt these byte arrays as +// it passes through a java server even if the field was never accessed by +// application code. +// +// 2. There's a performance hit to converting between bytes and strings and +// it many cases, the field is never even read by the application code. This +// avoids unnecessary conversions in the common use cases. +// +// So now, the field for String is maintained as an Object reference which can +// either store a String or a ByteString. The code uses an instanceof check +// to see which one it has and converts to the other one if needed. It remembers +// the last value requested (in a thread safe manner) as this is most likely +// the one needed next. The thread safety is such that if two threads both +// convert the field because the changes made by each thread were not visible to +// the other, they may cause a conversion to happen more times than would +// otherwise be necessary. This was deemed better than adding synchronization +// overhead. It will not cause any corruption issues or affect the behavior of +// the API. The instanceof check is also highly optimized in the JVM and we +// decided it was better to reduce the memory overhead by not having two +// 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. void ImmutableStringFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$java.lang.String get$capitalized_name$();\n"); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$com.google.protobuf.ByteString\n" " get$capitalized_name$Bytes();\n"); -} - +} + void ImmutableStringFieldGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private volatile java.lang.Object $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); - + PrintExtraFieldInfo(variables_, printer); + if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -223,8 +223,8 @@ void ImmutableStringFieldGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -236,22 +236,22 @@ void ImmutableStringFieldGenerator::GenerateMembers( " } else {\n" " com.google.protobuf.ByteString bs = \n" " (com.google.protobuf.ByteString) ref;\n" - " java.lang.String s = bs.toStringUtf8();\n"); + " java.lang.String s = bs.toStringUtf8();\n"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " $name$_ = s;\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, " if (bs.isValidUtf8()) {\n" " $name$_ = s;\n" " }\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " return s;\n" " }\n" "}\n"); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$() {\n" @@ -267,11 +267,11 @@ void ImmutableStringFieldGenerator::GenerateMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableStringFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "private java.lang.Object $name$_ $default_init$;\n"); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); @@ -281,8 +281,8 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( " return $get_has_field_bit_builder$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -293,23 +293,23 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( " (com.google.protobuf.ByteString) ref;\n" " java.lang.String s = bs.toStringUtf8();\n"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " $name$_ = s;\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, " if (bs.isValidUtf8()) {\n" " $name$_ = s;\n" " }\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " return s;\n" " } else {\n" " return (java.lang.String) ref;\n" " }\n" "}\n"); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$() {\n" " java.lang.Object ref = $name$_;\n" @@ -324,10 +324,10 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" @@ -344,15 +344,15 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $clear_has_field_bit_builder$\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_, + // 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_, + printer->Print(variables_, " $on_changed$\n" " return this;\n" "}\n"); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); printer->Print( @@ -361,17 +361,17 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( " com.google.protobuf.ByteString value) {\n" "$null_check$"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " $set_has_field_bit_builder$\n" " $name$_ = value;\n" " $on_changed$\n" " return this;\n" "}\n"); -} - +} + void ImmutableStringFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -402,131 +402,131 @@ void ImmutableStringFieldGenerator::GenerateKotlinDslMembers( void ImmutableStringFieldGenerator::GenerateFieldBuilderInitializationCode( io::Printer* printer) const { - // noop for primitives -} - + // noop for primitives +} + void ImmutableStringFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = $default$;\n"); -} - + printer->Print(variables_, "$name$_ = $default$;\n"); +} + void ImmutableStringFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "$name$_ = $default$;\n" "$clear_has_field_bit_builder$\n"); -} - +} + void ImmutableStringFieldGenerator::GenerateMergingCode( io::Printer* printer) const { if (HasHazzer(descriptor_)) { - // Allow a slight breach of abstraction here in order to avoid forcing - // all string fields to Strings when copying fields from a Message. - printer->Print(variables_, + // Allow a slight breach of abstraction here in order to avoid forcing + // 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" " $on_changed$\n" "}\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "if (!other.get$capitalized_name$().isEmpty()) {\n" " $name$_ = other.$name$_;\n" " $on_changed$\n" "}\n"); - } -} - + } +} + void ImmutableStringFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { if (HasHazzer(descriptor_)) { - printer->Print(variables_, + printer->Print(variables_, "if ($get_has_field_bit_from_local$) {\n" " $set_has_field_bit_to_local$;\n" "}\n"); - } + } printer->Print(variables_, "result.$name$_ = $name$_;\n"); -} - +} + void ImmutableStringFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - if (CheckUtf8(descriptor_)) { - printer->Print(variables_, + if (CheckUtf8(descriptor_)) { + printer->Print(variables_, "java.lang.String s = input.readStringRequireUtf8();\n" "$set_has_field_bit_message$\n" "$name$_ = s;\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "com.google.protobuf.ByteString bs = input.readBytes();\n" "$set_has_field_bit_message$\n" "$name$_ = bs;\n"); - } -} - + } +} + void ImmutableStringFieldGenerator::GenerateParsingDoneCode( io::Printer* printer) const { - // noop for strings. -} - + // noop for strings. +} + void ImmutableStringFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($is_field_present_message$) {\n" " $writeString$(output, $number$, $name$_);\n" "}\n"); -} - +} + void ImmutableStringFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($is_field_present_message$) {\n" " size += $computeStringSize$($number$, $name$_);\n" "}\n"); -} - +} + void ImmutableStringFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if (!get$capitalized_name$()\n" " .equals(other.get$capitalized_name$())) return false;\n"); -} - +} + void ImmutableStringFieldGenerator::GenerateHashCode( io::Printer* printer) const { printer->Print(variables_, "hash = (37 * hash) + $constant_name$;\n"); - printer->Print(variables_, + printer->Print(variables_, "hash = (53 * hash) + get$capitalized_name$().hashCode();\n"); -} - +} + TProtoStringType ImmutableStringFieldGenerator::GetBoxedType() const { - return "java.lang.String"; -} - -// =================================================================== - + return "java.lang.String"; +} + +// =================================================================== + ImmutableStringOneofFieldGenerator::ImmutableStringOneofFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : ImmutableStringFieldGenerator(descriptor, messageBitIndex, builderBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + ImmutableStringOneofFieldGenerator::~ImmutableStringOneofFieldGenerator() {} - + void ImmutableStringOneofFieldGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -542,24 +542,24 @@ void ImmutableStringOneofFieldGenerator::GenerateMembers( " (com.google.protobuf.ByteString) ref;\n" " java.lang.String s = bs.toStringUtf8();\n"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { - printer->Print(variables_, + if (CheckUtf8(descriptor_)) { + printer->Print(variables_, " if ($has_oneof_case_message$) {\n" " $oneof_name$_ = s;\n" " }\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, " if (bs.isValidUtf8() && ($has_oneof_case_message$)) {\n" " $oneof_name$_ = s;\n" " }\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " return s;\n" " }\n" "}\n"); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - - printer->Print(variables_, + + printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$() {\n" " java.lang.Object ref $default_init$;\n" @@ -579,13 +579,13 @@ void ImmutableStringOneofFieldGenerator::GenerateMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" @@ -607,24 +607,24 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( " java.lang.String s = bs.toStringUtf8();\n" " if ($has_oneof_case_message$) {\n"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " $oneof_name$_ = s;\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, " if (bs.isValidUtf8()) {\n" " $oneof_name$_ = s;\n" " }\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " }\n" " return s;\n" " } else {\n" " return (java.lang.String) ref;\n" " }\n" "}\n"); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$() {\n" @@ -645,10 +645,10 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" @@ -671,7 +671,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); printer->Print( @@ -680,88 +680,88 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( " com.google.protobuf.ByteString value) {\n" "$null_check$"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" " $on_changed$\n" " return this;\n" "}\n"); -} - +} + void ImmutableStringOneofFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - // Allow a slight breach of abstraction here in order to avoid forcing - // all string fields to Strings when copying fields from a Message. - printer->Print(variables_, + // Allow a slight breach of abstraction here in order to avoid forcing + // all string fields to Strings when copying fields from a Message. + printer->Print(variables_, "$set_oneof_case_message$;\n" "$oneof_name$_ = other.$oneof_name$_;\n" "$on_changed$\n"); -} - +} + void ImmutableStringOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($has_oneof_case_message$) {\n" " result.$oneof_name$_ = $oneof_name$_;\n" "}\n"); -} - +} + void ImmutableStringOneofFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - if (CheckUtf8(descriptor_)) { - printer->Print(variables_, + if (CheckUtf8(descriptor_)) { + printer->Print(variables_, "java.lang.String s = input.readStringRequireUtf8();\n" "$set_oneof_case_message$;\n" "$oneof_name$_ = s;\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "com.google.protobuf.ByteString bs = input.readBytes();\n" "$set_oneof_case_message$;\n" "$oneof_name$_ = bs;\n"); - } -} - + } +} + void ImmutableStringOneofFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($has_oneof_case_message$) {\n" " $writeString$(output, $number$, $oneof_name$_);\n" "}\n"); -} - +} + void ImmutableStringOneofFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($has_oneof_case_message$) {\n" " size += $computeStringSize$($number$, $oneof_name$_);\n" "}\n"); -} - -// =================================================================== - +} + +// =================================================================== + 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_); -} - -RepeatedImmutableStringFieldGenerator:: + SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +RepeatedImmutableStringFieldGenerator:: ~RepeatedImmutableStringFieldGenerator() {} - -int RepeatedImmutableStringFieldGenerator::GetNumBitsForMessage() const { - return 0; -} - -int RepeatedImmutableStringFieldGenerator::GetNumBitsForBuilder() const { - return 1; -} - + +int RepeatedImmutableStringFieldGenerator::GetNumBitsForMessage() const { + return 0; +} + +int RepeatedImmutableStringFieldGenerator::GetNumBitsForBuilder() const { + return 1; +} + void RepeatedImmutableStringFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); @@ -776,7 +776,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateInterfaceMembers( "$deprecation$java.util.List<java.lang.String>\n" " get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); printer->Print( @@ -784,18 +784,18 @@ void RepeatedImmutableStringFieldGenerator::GenerateInterfaceMembers( "$deprecation$java.lang.String get$capitalized_name$(int index);\n"); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$com.google.protobuf.ByteString\n" " get$capitalized_name$Bytes(int index);\n"); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateMembers( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "private com.google.protobuf.LazyStringList $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public com.google.protobuf.ProtocolStringList\n" " ${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list @@ -809,7 +809,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public java.lang.String " "${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" @@ -817,29 +817,29 @@ void RepeatedImmutableStringFieldGenerator::GenerateMembers( printer->Annotate("{", "}", descriptor_); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$(int index) {\n" " return $name$_.getByteString(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - // One field is the list and the bit field keeps track of whether the - // list is immutable. If it's immutable, the invariant is that it must - // either an instance of Collections.emptyList() or it's an ArrayList - // wrapped in a Collections.unmodifiableList() wrapper and nobody else has + // One field is the list and the bit field keeps track of whether the + // list is immutable. If it's immutable, the invariant is that it must + // either an instance of Collections.emptyList() or it's an ArrayList + // wrapped in a Collections.unmodifiableList() wrapper and nobody else has // a reference to the underlying ArrayList. This invariant allows us to - // share instances of lists between protocol buffers avoiding expensive - // 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. + // share instances of lists between protocol buffers avoiding expensive + // 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 void ensure$capitalized_name$IsMutable() {\n" @@ -848,13 +848,13 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( " $set_mutable_bit_builder$;\n" " }\n" "}\n"); - + // Note: We return an unmodifiable list because otherwise the caller // could hold on to the returned list and modify it after the message // has been built, thus mutating the message which is supposed to be // immutable. WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public com.google.protobuf.ProtocolStringList\n" " ${$get$capitalized_name$List$}$() {\n" " return $name$_.getUnmodifiableView();\n" @@ -868,7 +868,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public java.lang.String " "${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" @@ -876,7 +876,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$(int index) {\n" " return $name$_.getByteString(index);\n" @@ -884,7 +884,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, java.lang.String value) {\n" "$null_check$" @@ -896,7 +896,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" @@ -908,7 +908,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<java.lang.String> values) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -929,7 +929,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); printer->Print( @@ -938,17 +938,17 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( " com.google.protobuf.ByteString value) {\n" "$null_check$"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " ensure$capitalized_name$IsMutable();\n" " $name$_.add(value);\n" " $on_changed$\n" " return this;\n" "}\n"); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -1050,31 +1050,31 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( "}"); } -void RepeatedImmutableStringFieldGenerator:: +void RepeatedImmutableStringFieldGenerator:: GenerateFieldBuilderInitializationCode(io::Printer* printer) const { - // noop for primitives -} - + // noop for primitives +} + void RepeatedImmutableStringFieldGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = $empty_list$;\n"); -} - + printer->Print(variables_, "$name$_ = $empty_list$;\n"); +} + void RepeatedImmutableStringFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "$name$_ = $empty_list$;\n" "$clear_mutable_bit_builder$;\n"); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - // The code below does two optimizations: - // 1. If the other list is empty, there's nothing to do. This ensures we - // don't allocate a new array if we already have an immutable one. - // 2. If the other list is non-empty and our current list is empty, we can - // reuse the other list which is guaranteed to be immutable. - printer->Print(variables_, + // The code below does two optimizations: + // 1. If the other list is empty, there's nothing to do. This ensures we + // don't allocate a new array if we already have an immutable one. + // 2. If the other list is non-empty and our current list is empty, we can + // reuse the other list which is guaranteed to be immutable. + printer->Print(variables_, "if (!other.$name$_.isEmpty()) {\n" " if ($name$_.isEmpty()) {\n" " $name$_ = other.$name$_;\n" @@ -1085,87 +1085,87 @@ void RepeatedImmutableStringFieldGenerator::GenerateMergingCode( " }\n" " $on_changed$\n" "}\n"); -} - +} + 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_, + // 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"); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateParsingCode( io::Printer* printer) const { - if (CheckUtf8(descriptor_)) { - printer->Print(variables_, + if (CheckUtf8(descriptor_)) { + printer->Print(variables_, "java.lang.String s = input.readStringRequireUtf8();\n"); - } else { - printer->Print(variables_, + } else { + printer->Print(variables_, "com.google.protobuf.ByteString bs = input.readBytes();\n"); - } - printer->Print(variables_, + } + 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_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, "$name$_.add(s);\n"); - } else { + } else { printer->Print(variables_, "$name$_.add(bs);\n"); - } -} - + } +} + void RepeatedImmutableStringFieldGenerator::GenerateParsingDoneCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "if ($get_mutable_bit_parser$) {\n" " $name$_ = $name$_.getUnmodifiableView();\n" "}\n"); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "for (int i = 0; i < $name$_.size(); i++) {\n" " $writeString$(output, $number$, $name$_.getRaw(i));\n" "}\n"); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateSerializedSizeCode( io::Printer* printer) const { - printer->Print(variables_, + printer->Print(variables_, "{\n" " int dataSize = 0;\n"); - printer->Indent(); - - printer->Print(variables_, + printer->Indent(); + + printer->Print(variables_, "for (int i = 0; i < $name$_.size(); i++) {\n" " dataSize += computeStringSizeNoTag($name$_.getRaw(i));\n" "}\n"); - + printer->Print("size += dataSize;\n"); - - printer->Print(variables_, + + printer->Print(variables_, "size += $tag_size$ * get$capitalized_name$List().size();\n"); - - printer->Outdent(); - printer->Print("}\n"); -} - + + printer->Outdent(); + printer->Print("}\n"); +} + void RepeatedImmutableStringFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { printer->Print( variables_, "if (!get$capitalized_name$List()\n" " .equals(other.get$capitalized_name$List())) return false;\n"); -} - +} + void RepeatedImmutableStringFieldGenerator::GenerateHashCode( io::Printer* printer) const { printer->Print( @@ -1174,13 +1174,13 @@ void RepeatedImmutableStringFieldGenerator::GenerateHashCode( " hash = (37 * hash) + $constant_name$;\n" " hash = (53 * hash) + get$capitalized_name$List().hashCode();\n" "}\n"); -} - +} + TProtoStringType RepeatedImmutableStringFieldGenerator::GetBoxedType() const { - return "String"; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google + return "String"; +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.h index d209975918..f6fb38b354 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field.h @@ -1,47 +1,47 @@ -// 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) -// Author: jonp@google.com (Jon Perlow) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ - -#include <map> +// 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) +// Author: jonp@google.com (Jon Perlow) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#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/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -50,78 +50,78 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { - public: +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { + public: explicit ImmutableStringFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); - ~ImmutableStringFieldGenerator(); - + ~ImmutableStringFieldGenerator(); + // implements ImmutableFieldGenerator // --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateParsingDoneCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateParsingDoneCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; void GenerateKotlinDslMembers(io::Printer* printer) const; - + TProtoStringType GetBoxedType() const; - - protected: - const FieldDescriptor* descriptor_; + + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldGenerator); -}; - -class ImmutableStringOneofFieldGenerator - : public ImmutableStringFieldGenerator { - public: + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldGenerator); +}; + +class ImmutableStringOneofFieldGenerator + : public ImmutableStringFieldGenerator { + public: ImmutableStringOneofFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context); - ~ImmutableStringOneofFieldGenerator(); - - private: - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldGenerator); -}; - -class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { - public: - explicit RepeatedImmutableStringFieldGenerator( - const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, Context* context); + ~ImmutableStringOneofFieldGenerator(); + + private: + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldGenerator); +}; + +class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { + public: + explicit RepeatedImmutableStringFieldGenerator( + const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, Context* context); ~RepeatedImmutableStringFieldGenerator() override; - - // implements ImmutableFieldGenerator --------------------------------------- + + // implements ImmutableFieldGenerator --------------------------------------- int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -140,20 +140,20 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const override; void GenerateHashCode(io::Printer* printer) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; + + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.cc index bfaedeba9a..dedd68fa9b 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -1,44 +1,44 @@ -// 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) -// Author: jonp@google.com (Jon Perlow) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - +// 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) +// Author: jonp@google.com (Jon Perlow) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + #include <google/protobuf/compiler/java/java_string_field_lite.h> #include <cstdint> -#include <map> +#include <map> #include <string> - + #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/java/java_context.h> @@ -48,42 +48,42 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -using internal::WireFormat; -using internal::WireFormatLite; - -namespace { - -void SetPrimitiveVariables(const FieldDescriptor* descriptor, + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +using internal::WireFormat; +using internal::WireFormatLite; + +namespace { + +void SetPrimitiveVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, std::map<TProtoStringType, TProtoStringType>* variables) { - 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); + 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)["capitalized_type"] = "java.lang.String"; (*variables)["tag"] = StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( - WireFormat::TagSize(descriptor->number(), GetType(descriptor))); + 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. (*variables)["null_check"] = " java.lang.Class<?> valueClass = value.getClass();\n"; - - // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported - // by the proto compiler + + // 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"] = @@ -92,98 +92,98 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, " is deprecated\") " : ""; (*variables)["required"] = descriptor->is_required() ? "true" : "false"; - + if (HasHasbit(descriptor)) { - // 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) + ";"; - (*variables)["clear_has_field_bit_message"] = - 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)["get_has_field_bit_from_local"] = - GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); -} - -} // namespace - -// =================================================================== - + // 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) + ";"; + (*variables)["clear_has_field_bit_message"] = + 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)["get_has_field_bit_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); +} + +} // namespace + +// =================================================================== + ImmutableStringFieldLiteGenerator::ImmutableStringFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), messageBitIndex_(messageBitIndex), name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_); -} - -ImmutableStringFieldLiteGenerator::~ImmutableStringFieldLiteGenerator() {} - -int ImmutableStringFieldLiteGenerator::GetNumBitsForMessage() const { + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +ImmutableStringFieldLiteGenerator::~ImmutableStringFieldLiteGenerator() {} + +int ImmutableStringFieldLiteGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; -} - -// A note about how strings are handled. In the SPEED and CODE_SIZE runtimes, -// strings are not stored as java.lang.String in the Message because of two -// issues: -// +} + +// A note about how strings are handled. In the SPEED and CODE_SIZE runtimes, +// strings are not stored as java.lang.String in the Message because of two +// issues: +// // 1. It wouldn't roundtrip byte arrays that were not valid UTF-8 encoded -// strings, but rather fields that were raw bytes incorrectly marked -// as strings in the proto file. This is common because in the proto1 -// syntax, string was the way to indicate bytes and C++ engineers can -// easily make this mistake without affecting the C++ API. By converting to -// strings immediately, some java code might corrupt these byte arrays as -// it passes through a java server even if the field was never accessed by -// application code. -// -// 2. There's a performance hit to converting between bytes and strings and -// it many cases, the field is never even read by the application code. This -// avoids unnecessary conversions in the common use cases. -// -// In the LITE_RUNTIME, we store strings as java.lang.String because we assume -// that the users of this runtime are not subject to proto1 constraints and are -// running code on devices that are user facing. That is, the developers are -// properly incentivized to only fetch the data they need to read and wish to -// reduce the number of allocations incurred when running on a user's device. - -// TODO(dweis): Consider dropping all of the *Bytes() methods. They really -// shouldn't be necessary or used on devices. +// strings, but rather fields that were raw bytes incorrectly marked +// as strings in the proto file. This is common because in the proto1 +// syntax, string was the way to indicate bytes and C++ engineers can +// easily make this mistake without affecting the C++ API. By converting to +// strings immediately, some java code might corrupt these byte arrays as +// it passes through a java server even if the field was never accessed by +// application code. +// +// 2. There's a performance hit to converting between bytes and strings and +// it many cases, the field is never even read by the application code. This +// avoids unnecessary conversions in the common use cases. +// +// In the LITE_RUNTIME, we store strings as java.lang.String because we assume +// that the users of this runtime are not subject to proto1 constraints and are +// running code on devices that are user facing. That is, the developers are +// properly incentivized to only fetch the data they need to read and wish to +// reduce the number of allocations incurred when running on a user's device. + +// TODO(dweis): Consider dropping all of the *Bytes() methods. They really +// shouldn't be necessary or used on devices. void ImmutableStringFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); - } + } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$java.lang.String get$capitalized_name$();\n"); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$com.google.protobuf.ByteString\n" " get$capitalized_name$Bytes();\n"); -} - +} + void ImmutableStringFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { printer->Print(variables_, "private java.lang.String $name$_;\n"); - PrintExtraFieldInfo(variables_, printer); - + PrintExtraFieldInfo(variables_, printer); + if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -193,8 +193,8 @@ void ImmutableStringFieldLiteGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -212,9 +212,9 @@ void ImmutableStringFieldLiteGenerator::GenerateMembers( " return com.google.protobuf.ByteString.copyFromUtf8($name$_);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$(\n" " java.lang.String value) {\n" "$null_check$" @@ -222,7 +222,7 @@ void ImmutableStringFieldLiteGenerator::GenerateMembers( " $name$_ = value;\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " $clear_has_field_bit_message$\n" // The default value is not a simple literal so we want to @@ -230,20 +230,20 @@ void ImmutableStringFieldLiteGenerator::GenerateMembers( // out of the default instance. " $name$_ = getDefaultInstance().get$capitalized_name$();\n" "}\n"); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$Bytes(\n" " com.google.protobuf.ByteString value) {\n"); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " $name$_ = value.toStringUtf8();\n" " $set_has_field_bit_message$\n" "}\n"); -} - +} + void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { if (HasHazzer(descriptor_)) { @@ -255,8 +255,8 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( " return instance.has$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - } - + } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -265,19 +265,19 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( " return instance.get$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$() {\n" " return instance.get$capitalized_name$Bytes();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" " copyOnWrite();\n" @@ -295,7 +295,7 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); printer->Print( @@ -307,8 +307,8 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); @@ -346,42 +346,42 @@ void ImmutableStringFieldLiteGenerator::GenerateFieldInfo( WriteIntToUtf16CharSequence(messageBitIndex_, output); } printer->Print(variables_, "\"$name$_\",\n"); -} - +} + void ImmutableStringFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = $default$;\n"); -} - + printer->Print(variables_, "$name$_ = $default$;\n"); +} + TProtoStringType ImmutableStringFieldLiteGenerator::GetBoxedType() const { - return "java.lang.String"; -} - -// =================================================================== - + return "java.lang.String"; +} + +// =================================================================== + ImmutableStringOneofFieldLiteGenerator::ImmutableStringOneofFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : ImmutableStringFieldLiteGenerator(descriptor, messageBitIndex, context) { - const OneofGeneratorInfo* info = - context->GetOneofGeneratorInfo(descriptor->containing_oneof()); - SetCommonOneofVariables(descriptor, info, &variables_); -} - -ImmutableStringOneofFieldLiteGenerator:: + const OneofGeneratorInfo* info = + context->GetOneofGeneratorInfo(descriptor->containing_oneof()); + SetCommonOneofVariables(descriptor, info, &variables_); +} + +ImmutableStringOneofFieldLiteGenerator:: ~ImmutableStringOneofFieldLiteGenerator() {} - + void ImmutableStringOneofFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -394,9 +394,9 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateMembers( " return ref;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$() {\n" @@ -407,9 +407,9 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateMembers( " return com.google.protobuf.ByteString.copyFromUtf8(ref);\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" @@ -418,7 +418,7 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void ${$clear$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" @@ -426,21 +426,21 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n"); printer->Annotate("{", "}", descriptor_); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " $oneof_name$_ = value.toStringUtf8();\n" " $set_oneof_case_message$;\n" "}\n"); -} - +} + void ImmutableStringOneofFieldLiteGenerator::GenerateFieldInfo( io::Printer* printer, std::vector<uint16_t>* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); @@ -453,13 +453,13 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { GOOGLE_DCHECK(HasHazzer(descriptor_)); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -468,9 +468,9 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateBuilderMembers( " return instance.get$capitalized_name$();\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$() {\n" @@ -480,7 +480,7 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateBuilderMembers( WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" " copyOnWrite();\n" @@ -498,7 +498,7 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); printer->Print( @@ -510,55 +510,55 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - -// =================================================================== - -RepeatedImmutableStringFieldLiteGenerator:: +} + +// =================================================================== + +RepeatedImmutableStringFieldLiteGenerator:: RepeatedImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_); -} - -RepeatedImmutableStringFieldLiteGenerator:: + context->GetFieldGeneratorInfo(descriptor), + name_resolver_, &variables_); +} + +RepeatedImmutableStringFieldLiteGenerator:: ~RepeatedImmutableStringFieldLiteGenerator() {} - -int RepeatedImmutableStringFieldLiteGenerator::GetNumBitsForMessage() const { - return 0; -} - + +int RepeatedImmutableStringFieldLiteGenerator::GetNumBitsForMessage() const { + return 0; +} + void RepeatedImmutableStringFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$java.util.List<java.lang.String>\n" " get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); printer->Print( variables_, "$deprecation$java.lang.String get$capitalized_name$(int index);\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$com.google.protobuf.ByteString\n" " get$capitalized_name$Bytes(int index);\n"); -} - +} + void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { printer->Print( variables_, "private com.google.protobuf.Internal.ProtobufList<java.lang.String> " "$name$_;\n"); - PrintExtraFieldInfo(variables_, printer); + PrintExtraFieldInfo(variables_, printer); WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<java.lang.String> " "${$get$capitalized_name$List$}$() {\n" @@ -574,7 +574,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.lang.String " "${$get$capitalized_name$$}$(int index) {\n" @@ -583,7 +583,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( printer->Annotate("{", "}", descriptor_); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$(int index) {\n" @@ -591,7 +591,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( " $name$_.get(index));\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + printer->Print( variables_, "private void ensure$capitalized_name$IsMutable() {\n" @@ -603,9 +603,9 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( " com.google.protobuf.GeneratedMessageLite.mutableCopy(tmp);\n" " }\n" "}\n"); - + WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER); - printer->Print(variables_, + printer->Print(variables_, "private void set$capitalized_name$(\n" " int index, java.lang.String value) {\n" "$null_check$" @@ -613,7 +613,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( " $name$_.set(index, value);\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void add$capitalized_name$(\n" " java.lang.String value) {\n" "$null_check$" @@ -621,7 +621,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( " $name$_.add(value);\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void addAll$capitalized_name$(\n" " java.lang.Iterable<java.lang.String> values) {\n" " ensure$capitalized_name$IsMutable();\n" @@ -629,28 +629,28 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( " values, $name$_);\n" "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER); - printer->Print(variables_, + printer->Print(variables_, "private void clear$capitalized_name$() {\n" " $name$_ = $empty_list$;\n" "}\n"); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_ADDER); - printer->Print(variables_, + printer->Print(variables_, "private void add$capitalized_name$Bytes(\n" " com.google.protobuf.ByteString value) {\n"); - if (CheckUtf8(descriptor_)) { + if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); - } - printer->Print(variables_, + } + printer->Print(variables_, " ensure$capitalized_name$IsMutable();\n" " $name$_.add(value.toStringUtf8());\n" "}\n"); -} - +} + void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.util.List<java.lang.String>\n" " ${$get$capitalized_name$List$}$() {\n" @@ -667,7 +667,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public java.lang.String " "${$get$capitalized_name$$}$(int index) {\n" @@ -676,7 +676,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, + printer->Print(variables_, "@java.lang.Override\n" "$deprecation$public com.google.protobuf.ByteString\n" " ${$get$capitalized_name$Bytes$}$(int index) {\n" @@ -685,7 +685,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, java.lang.String value) {\n" " copyOnWrite();\n" @@ -695,7 +695,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " java.lang.String value) {\n" " copyOnWrite();\n" @@ -705,7 +705,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ true); - printer->Print(variables_, + printer->Print(variables_, "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<java.lang.String> values) {\n" " copyOnWrite();\n" @@ -723,7 +723,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - + WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ true); printer->Print( @@ -735,8 +735,8 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); -} - +} + void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { printer->Print( @@ -844,18 +844,18 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateFieldInfo( WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); printer->Print(variables_, "\"$name$_\",\n"); -} - +} + void RepeatedImmutableStringFieldLiteGenerator::GenerateInitializationCode( io::Printer* printer) const { - printer->Print(variables_, "$name$_ = $empty_list$;\n"); -} - + printer->Print(variables_, "$name$_ = $empty_list$;\n"); +} + TProtoStringType RepeatedImmutableStringFieldLiteGenerator::GetBoxedType() const { return "java.lang.String"; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google +} + +} // namespace java +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.h b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.h index 02cf5c1657..1e6e5f3dfb 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/java_string_field_lite.h @@ -1,49 +1,49 @@ -// 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) -// Author: jonp@google.com (Jon Perlow) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ - +// 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) +// Author: jonp@google.com (Jon Perlow) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ + #include <cstdint> -#include <map> +#include <map> #include <string> #include <google/protobuf/compiler/java/java_field.h> - -namespace google { -namespace protobuf { + +namespace google { +namespace protobuf { namespace compiler { namespace java { class Context; // context.h @@ -52,19 +52,19 @@ class ClassNameResolver; // name_resolver.h } // namespace compiler } // namespace protobuf } // namespace google - + namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { - public: +namespace protobuf { +namespace compiler { +namespace java { + +class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { + public: explicit ImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~ImmutableStringFieldLiteGenerator() override; - + // implements ImmutableFieldLiteGenerator // ------------------------------------ int GetNumBitsForMessage() const override; @@ -75,43 +75,43 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - protected: - const FieldDescriptor* descriptor_; + protected: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - const int messageBitIndex_; - ClassNameResolver* name_resolver_; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldLiteGenerator); -}; - -class ImmutableStringOneofFieldLiteGenerator - : public ImmutableStringFieldLiteGenerator { - public: + const int messageBitIndex_; + ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldLiteGenerator); +}; + +class ImmutableStringOneofFieldLiteGenerator + : public ImmutableStringFieldLiteGenerator { + public: ImmutableStringOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~ImmutableStringOneofFieldLiteGenerator() override; - - private: + + private: 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; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator); -}; - -class RepeatedImmutableStringFieldLiteGenerator - : public ImmutableFieldLiteGenerator { - public: - explicit RepeatedImmutableStringFieldLiteGenerator( + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator); +}; + +class RepeatedImmutableStringFieldLiteGenerator + : public ImmutableFieldLiteGenerator { + public: + explicit RepeatedImmutableStringFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); ~RepeatedImmutableStringFieldLiteGenerator() override; - - // implements ImmutableFieldLiteGenerator ------------------------------------ + + // implements ImmutableFieldLiteGenerator ------------------------------------ int GetNumBitsForMessage() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; void GenerateMembers(io::Printer* printer) const override; @@ -120,20 +120,20 @@ class RepeatedImmutableStringFieldLiteGenerator void GenerateFieldInfo(io::Printer* printer, std::vector<uint16_t>* output) const override; void GenerateKotlinDslMembers(io::Printer* printer) const override; - + TProtoStringType GetBoxedType() const override; - private: - const FieldDescriptor* descriptor_; + private: + const FieldDescriptor* descriptor_; std::map<TProtoStringType, TProtoStringType> variables_; - ClassNameResolver* name_resolver_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldLiteGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf + ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldLiteGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ |