From d9ff109888b60a37de1c4f69cea023f89886e86b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 May 2024 21:46:06 -0700 Subject: [PATCH] internal change PiperOrigin-RevId: 630273635 --- .../protobuf/compiler/java/immutable/BUILD.bazel | 2 ++ src/google/protobuf/compiler/java/immutable/enum.cc | 10 ++++++++++ src/google/protobuf/compiler/java/immutable/enum.h | 1 + src/google/protobuf/compiler/java/internal_helpers.h | 1 + 4 files changed, 14 insertions(+) diff --git a/src/google/protobuf/compiler/java/immutable/BUILD.bazel b/src/google/protobuf/compiler/java/immutable/BUILD.bazel index baa679ef42..0f01091bcd 100644 --- a/src/google/protobuf/compiler/java/immutable/BUILD.bazel +++ b/src/google/protobuf/compiler/java/immutable/BUILD.bazel @@ -85,9 +85,11 @@ cc_library( "//src/google/protobuf:port", "//src/google/protobuf/compiler/java:generator_common", "//src/google/protobuf/compiler/java:helpers", + "//src/google/protobuf/compiler/java:internal_helpers", "//src/google/protobuf/io:printer", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) diff --git a/src/google/protobuf/compiler/java/immutable/enum.cc b/src/google/protobuf/compiler/java/immutable/enum.cc index 61b307914c..9ceefcb1a8 100644 --- a/src/google/protobuf/compiler/java/immutable/enum.cc +++ b/src/google/protobuf/compiler/java/immutable/enum.cc @@ -11,13 +11,20 @@ #include "google/protobuf/compiler/java/immutable/enum.h" +#include +#include #include +#include #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_format.h" +#include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/internal_helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/printer.h" @@ -30,6 +37,7 @@ namespace protobuf { namespace compiler { namespace java { + EnumNonLiteGenerator::EnumNonLiteGenerator(const EnumDescriptor* descriptor, bool immutable_api, Context* context) : descriptor_(descriptor), @@ -56,6 +64,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) { WriteEnumDocComment(printer, descriptor_, context_->options()); MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_); + if (!context_->options().opensource_runtime) { printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); } @@ -374,6 +383,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) { printer->Print("}\n\n"); } + bool EnumNonLiteGenerator::CanUseEnumValues() { if (canonical_values_.size() != descriptor_->value_count()) { return false; diff --git a/src/google/protobuf/compiler/java/immutable/enum.h b/src/google/protobuf/compiler/java/immutable/enum.h index 18ccc01e95..8528d7f81f 100644 --- a/src/google/protobuf/compiler/java/immutable/enum.h +++ b/src/google/protobuf/compiler/java/immutable/enum.h @@ -71,6 +71,7 @@ class EnumNonLiteGenerator : public EnumGenerator { ClassNameResolver* name_resolver_; bool CanUseEnumValues(); + }; } // namespace java diff --git a/src/google/protobuf/compiler/java/internal_helpers.h b/src/google/protobuf/compiler/java/internal_helpers.h index e2534b95bf..607669b26a 100644 --- a/src/google/protobuf/compiler/java/internal_helpers.h +++ b/src/google/protobuf/compiler/java/internal_helpers.h @@ -50,6 +50,7 @@ inline bool CheckUtf8(const FieldDescriptor* descriptor) { descriptor->file()->options().java_string_check_utf8(); } + // Only the lowest two bytes of the return value are used. The lowest byte // is the integer value of a j/c/g/protobuf/FieldType enum. For the other // byte: