Implement Java feature `use_old_outer_classname_default` for edition 2024.

PiperOrigin-RevId: 687389326
pull/18899/head
Protobuf Team Bot 1 month ago committed by Copybara-Service
parent 5599f2ceec
commit 18903c4a4c
  1. 5
      java/core/BUILD.bazel
  2. 17
      java/core/src/main/resources/google/protobuf/java_features.proto
  3. 2
      src/google/protobuf/compiler/java/BUILD.bazel
  4. 114
      src/google/protobuf/compiler/java/java_features.pb.cc
  5. 73
      src/google/protobuf/compiler/java/java_features.pb.h
  6. 26
      src/google/protobuf/compiler/java/name_resolver.cc

@ -198,7 +198,10 @@ proto_library(
cc_proto_library( cc_proto_library(
name = "java_features_cc_proto", name = "java_features_cc_proto",
visibility = ["//editions:__pkg__"], visibility = [
"//editions:__pkg__",
"//src/google/protobuf/compiler/java:__pkg__", # For java/names.h
],
deps = [":java_features_proto"], deps = [":java_features_proto"],
) )

@ -66,4 +66,21 @@ message JavaFeatures {
}, },
edition_defaults = { edition: EDITION_LEGACY, value: "DEFAULT" } edition_defaults = { edition: EDITION_LEGACY, value: "DEFAULT" }
]; ];
// Whether to use the old default outer class name scheme, or the new feature
// which adds a "Proto" suffix to the outer class name.
//
// Users will not be able to set this option, because we removed it in the
// same edition that it was introduced. But we use it to determine which
// naming scheme to use for outer class name defaults.
optional bool use_old_outer_classname_default = 4 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FILE,
feature_support = {
edition_introduced: EDITION_2024,
edition_removed: EDITION_2024,
},
edition_defaults = { edition: EDITION_LEGACY, value: "true" },
edition_defaults = { edition: EDITION_2024, value: "false" }
];
} }

@ -35,6 +35,7 @@ cc_library(
hdrs = [ hdrs = [
"context.h", "context.h",
"doc_comment.h", "doc_comment.h",
"generator.h",
"helpers.h", "helpers.h",
"name_resolver.h", "name_resolver.h",
"names.h", "names.h",
@ -48,6 +49,7 @@ cc_library(
"//src/google/protobuf/compiler/kotlin:__subpackages__", "//src/google/protobuf/compiler/kotlin:__subpackages__",
], ],
deps = [ deps = [
":java_features_bootstrap",
"//src/google/protobuf", "//src/google/protobuf",
"//src/google/protobuf:port", "//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:code_generator",

@ -29,8 +29,9 @@ namespace pb {
inline constexpr JavaFeatures::Impl_::Impl_( inline constexpr JavaFeatures::Impl_::Impl_(
::_pbi::ConstantInitialized) noexcept ::_pbi::ConstantInitialized) noexcept
: _cached_size_{0}, : _cached_size_{0},
utf8_validation_{static_cast< ::pb::JavaFeatures_Utf8Validation >(0)},
legacy_closed_enum_{false}, legacy_closed_enum_{false},
utf8_validation_{static_cast< ::pb::JavaFeatures_Utf8Validation >(0)} {} use_old_outer_classname_default_{false} {}
template <typename> template <typename>
PROTOBUF_CONSTEXPR JavaFeatures::JavaFeatures(::_pbi::ConstantInitialized) PROTOBUF_CONSTEXPR JavaFeatures::JavaFeatures(::_pbi::ConstantInitialized)
@ -68,13 +69,15 @@ const ::uint32_t
~0u, // no sizeof(Split) ~0u, // no sizeof(Split)
PROTOBUF_FIELD_OFFSET(::pb::JavaFeatures, _impl_.legacy_closed_enum_), PROTOBUF_FIELD_OFFSET(::pb::JavaFeatures, _impl_.legacy_closed_enum_),
PROTOBUF_FIELD_OFFSET(::pb::JavaFeatures, _impl_.utf8_validation_), PROTOBUF_FIELD_OFFSET(::pb::JavaFeatures, _impl_.utf8_validation_),
0, PROTOBUF_FIELD_OFFSET(::pb::JavaFeatures, _impl_.use_old_outer_classname_default_),
1, 1,
0,
2,
}; };
static const ::_pbi::MigrationSchema static const ::_pbi::MigrationSchema
schemas[] ABSL_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { schemas[] ABSL_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{0, 10, -1, sizeof(::pb::JavaFeatures)}, {0, 11, -1, sizeof(::pb::JavaFeatures)},
}; };
static const ::_pb::Message* const file_default_instances[] = { static const ::_pb::Message* const file_default_instances[] = {
&::pb::_JavaFeatures_default_instance_._instance, &::pb::_JavaFeatures_default_instance_._instance,
@ -83,7 +86,7 @@ const char descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fjava_2fjava_
protodesc_cold) = { protodesc_cold) = {
"\n1google/protobuf/compiler/java/java_fea" "\n1google/protobuf/compiler/java/java_fea"
"tures.proto\022\002pb\032 google/protobuf/descrip" "tures.proto\022\002pb\032 google/protobuf/descrip"
"tor.proto\"\371\004\n\014JavaFeatures\022\376\001\n\022legacy_cl" "tor.proto\"\314\005\n\014JavaFeatures\022\376\001\n\022legacy_cl"
"osed_enum\030\001 \001(\010B\341\001\210\001\001\230\001\004\230\001\001\242\001\t\022\004true\030\204\007\242" "osed_enum\030\001 \001(\010B\341\001\210\001\001\230\001\004\230\001\001\242\001\t\022\004true\030\204\007\242"
"\001\n\022\005false\030\347\007\262\001\273\001\010\350\007\020\350\007\032\262\001The legacy clos" "\001\n\022\005false\030\347\007\262\001\273\001\010\350\007\020\350\007\032\262\001The legacy clos"
"ed enum behavior in Java is deprecated a" "ed enum behavior in Java is deprecated a"
@ -97,11 +100,13 @@ const char descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fjava_2fjava_
"d is scheduled to be removed in edition " "d is scheduled to be removed in edition "
"2025. Utf8 validation behavior should u" "2025. Utf8 validation behavior should u"
"se the global cross-language utf8_valida" "se the global cross-language utf8_valida"
"tion feature.\"F\n\016Utf8Validation\022\033\n\027UTF8_" "tion feature.\022Q\n\037use_old_outer_classname"
"VALIDATION_UNKNOWN\020\000\022\013\n\007DEFAULT\020\001\022\n\n\006VER" "_default\030\004 \001(\010B(\210\001\001\230\001\001\242\001\t\022\004true\030\204\007\242\001\n\022\005f"
"IFY\020\002:<\n\004java\022\033.google.protobuf.FeatureS" "alse\030\351\007\262\001\006\010\351\007 \351\007\"F\n\016Utf8Validation\022\033\n\027UT"
"et\030\351\007 \001(\0132\020.pb.JavaFeaturesB(\n\023com.googl" "F8_VALIDATION_UNKNOWN\020\000\022\013\n\007DEFAULT\020\001\022\n\n\006"
"e.protobufB\021JavaFeaturesProto" "VERIFY\020\002:<\n\004java\022\033.google.protobuf.Featu"
"reSet\030\351\007 \001(\0132\020.pb.JavaFeaturesB(\n\023com.go"
"ogle.protobufB\021JavaFeaturesProto"
}; };
static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_deps[1] = static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_deps[1] =
{ {
@ -111,7 +116,7 @@ static ::absl::once_flag descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2f
PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto = { PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto = {
false, false,
false, false,
829, 912,
descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto, descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto,
"google/protobuf/compiler/java/java_features.proto", "google/protobuf/compiler/java/java_features.proto",
&descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_once, &descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_once,
@ -184,11 +189,11 @@ inline PROTOBUF_NDEBUG_INLINE JavaFeatures::Impl_::Impl_(
inline void JavaFeatures::SharedCtor(::_pb::Arena* arena) { inline void JavaFeatures::SharedCtor(::_pb::Arena* arena) {
new (&_impl_) Impl_(internal_visibility(), arena); new (&_impl_) Impl_(internal_visibility(), arena);
::memset(reinterpret_cast<char *>(&_impl_) + ::memset(reinterpret_cast<char *>(&_impl_) +
offsetof(Impl_, legacy_closed_enum_), offsetof(Impl_, utf8_validation_),
0, 0,
offsetof(Impl_, utf8_validation_) - offsetof(Impl_, use_old_outer_classname_default_) -
offsetof(Impl_, legacy_closed_enum_) + offsetof(Impl_, utf8_validation_) +
sizeof(Impl_::utf8_validation_)); sizeof(Impl_::use_old_outer_classname_default_));
} }
JavaFeatures::~JavaFeatures() { JavaFeatures::~JavaFeatures() {
// @@protoc_insertion_point(destructor:pb.JavaFeatures) // @@protoc_insertion_point(destructor:pb.JavaFeatures)
@ -243,15 +248,15 @@ const ::google::protobuf::internal::ClassData* JavaFeatures::GetClassData() cons
return JavaFeatures_class_data_.base(); return JavaFeatures_class_data_.base();
} }
PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
const ::_pbi::TcParseTable<1, 2, 1, 0, 2> JavaFeatures::_table_ = { const ::_pbi::TcParseTable<2, 3, 1, 0, 2> JavaFeatures::_table_ = {
{ {
PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_._has_bits_), PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_._has_bits_),
0, // no _extensions_ 0, // no _extensions_
2, 8, // max_field_number, fast_idx_mask 4, 24, // max_field_number, fast_idx_mask
offsetof(decltype(_table_), field_lookup_table), offsetof(decltype(_table_), field_lookup_table),
4294967292, // skipmap 4294967284, // skipmap
offsetof(decltype(_table_), field_entries), offsetof(decltype(_table_), field_entries),
2, // num_field_entries 3, // num_field_entries
1, // num_aux_entries 1, // num_aux_entries
offsetof(decltype(_table_), aux_entries), offsetof(decltype(_table_), aux_entries),
JavaFeatures_class_data_.base(), JavaFeatures_class_data_.base(),
@ -261,21 +266,28 @@ const ::_pbi::TcParseTable<1, 2, 1, 0, 2> JavaFeatures::_table_ = {
::_pbi::TcParser::GetTable<::pb::JavaFeatures>(), // to_prefetch ::_pbi::TcParser::GetTable<::pb::JavaFeatures>(), // to_prefetch
#endif // PROTOBUF_PREFETCH_PARSE_TABLE #endif // PROTOBUF_PREFETCH_PARSE_TABLE
}, {{ }, {{
// optional bool use_old_outer_classname_default = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(JavaFeatures, _impl_.use_old_outer_classname_default_), 2>(),
{32, 2, 0, PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.use_old_outer_classname_default_)}},
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(JavaFeatures, _impl_.legacy_closed_enum_), 1>(),
{8, 1, 0, PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.legacy_closed_enum_)}},
// optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::FastEr0S1, {::_pbi::TcParser::FastEr0S1,
{16, 1, 2, PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.utf8_validation_)}}, {16, 0, 2, PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.utf8_validation_)}},
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { {::_pbi::TcParser::MiniParse, {}},
{::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(JavaFeatures, _impl_.legacy_closed_enum_), 0>(),
{8, 0, 0, PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.legacy_closed_enum_)}},
}}, {{ }}, {{
65535, 65535 65535, 65535
}}, {{ }}, {{
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.legacy_closed_enum_), _Internal::kHasBitsOffset + 0, 0, {PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.legacy_closed_enum_), _Internal::kHasBitsOffset + 1, 0,
(0 | ::_fl::kFcOptional | ::_fl::kBool)}, (0 | ::_fl::kFcOptional | ::_fl::kBool)},
// optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.utf8_validation_), _Internal::kHasBitsOffset + 1, 0, {PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.utf8_validation_), _Internal::kHasBitsOffset + 0, 0,
(0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)},
// optional bool use_old_outer_classname_default = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.use_old_outer_classname_default_), _Internal::kHasBitsOffset + 2, 0,
(0 | ::_fl::kFcOptional | ::_fl::kBool)},
}}, {{ }}, {{
{0, 3}, {0, 3},
}}, {{ }}, {{
@ -290,10 +302,10 @@ PROTOBUF_NOINLINE void JavaFeatures::Clear() {
(void) cached_has_bits; (void) cached_has_bits;
cached_has_bits = _impl_._has_bits_[0]; cached_has_bits = _impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000007u) {
::memset(&_impl_.legacy_closed_enum_, 0, static_cast<::size_t>( ::memset(&_impl_.utf8_validation_, 0, static_cast<::size_t>(
reinterpret_cast<char*>(&_impl_.utf8_validation_) - reinterpret_cast<char*>(&_impl_.use_old_outer_classname_default_) -
reinterpret_cast<char*>(&_impl_.legacy_closed_enum_)) + sizeof(_impl_.utf8_validation_)); reinterpret_cast<char*>(&_impl_.utf8_validation_)) + sizeof(_impl_.use_old_outer_classname_default_));
} }
_impl_._has_bits_.Clear(); _impl_._has_bits_.Clear();
_internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>();
@ -316,19 +328,26 @@ PROTOBUF_NOINLINE void JavaFeatures::Clear() {
cached_has_bits = this_._impl_._has_bits_[0]; cached_has_bits = this_._impl_._has_bits_[0];
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000001u) { if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target); target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteBoolToArray( target = ::_pbi::WireFormatLite::WriteBoolToArray(
1, this_._internal_legacy_closed_enum(), target); 1, this_._internal_legacy_closed_enum(), target);
} }
// optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) { if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target); target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray( target = ::_pbi::WireFormatLite::WriteEnumToArray(
2, this_._internal_utf8_validation(), target); 2, this_._internal_utf8_validation(), target);
} }
// optional bool use_old_outer_classname_default = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000004u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteBoolToArray(
4, this_._internal_use_old_outer_classname_default(), target);
}
if (PROTOBUF_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { if (PROTOBUF_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) {
target = target =
::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
@ -354,16 +373,20 @@ PROTOBUF_NOINLINE void JavaFeatures::Clear() {
::_pbi::Prefetch5LinesFrom7Lines(&this_); ::_pbi::Prefetch5LinesFrom7Lines(&this_);
cached_has_bits = this_._impl_._has_bits_[0]; cached_has_bits = this_._impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000007u) {
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000001u) {
total_size += 2;
}
// optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) { if (cached_has_bits & 0x00000001u) {
total_size += 1 + total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this_._internal_utf8_validation()); ::_pbi::WireFormatLite::EnumSize(this_._internal_utf8_validation());
} }
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) {
total_size += 2;
}
// optional bool use_old_outer_classname_default = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000004u) {
total_size += 2;
}
} }
return this_.MaybeComputeUnknownFieldsSize(total_size, return this_.MaybeComputeUnknownFieldsSize(total_size,
&this_._impl_._cached_size_); &this_._impl_._cached_size_);
@ -378,12 +401,15 @@ void JavaFeatures::MergeImpl(::google::protobuf::MessageLite& to_msg, const ::go
(void) cached_has_bits; (void) cached_has_bits;
cached_has_bits = from._impl_._has_bits_[0]; cached_has_bits = from._impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000007u) {
if (cached_has_bits & 0x00000001u) { if (cached_has_bits & 0x00000001u) {
_this->_impl_.legacy_closed_enum_ = from._impl_.legacy_closed_enum_; _this->_impl_.utf8_validation_ = from._impl_.utf8_validation_;
} }
if (cached_has_bits & 0x00000002u) { if (cached_has_bits & 0x00000002u) {
_this->_impl_.utf8_validation_ = from._impl_.utf8_validation_; _this->_impl_.legacy_closed_enum_ = from._impl_.legacy_closed_enum_;
}
if (cached_has_bits & 0x00000004u) {
_this->_impl_.use_old_outer_classname_default_ = from._impl_.use_old_outer_classname_default_;
} }
} }
_this->_impl_._has_bits_[0] |= cached_has_bits; _this->_impl_._has_bits_[0] |= cached_has_bits;
@ -403,11 +429,11 @@ void JavaFeatures::InternalSwap(JavaFeatures* PROTOBUF_RESTRICT other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::google::protobuf::internal::memswap< ::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.utf8_validation_) PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.use_old_outer_classname_default_)
+ sizeof(JavaFeatures::_impl_.utf8_validation_) + sizeof(JavaFeatures::_impl_.use_old_outer_classname_default_)
- PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.legacy_closed_enum_)>( - PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_.utf8_validation_)>(
reinterpret_cast<char*>(&_impl_.legacy_closed_enum_), reinterpret_cast<char*>(&_impl_.utf8_validation_),
reinterpret_cast<char*>(&other->_impl_.legacy_closed_enum_)); reinterpret_cast<char*>(&other->_impl_.utf8_validation_));
} }
::google::protobuf::Metadata JavaFeatures::GetMetadata() const { ::google::protobuf::Metadata JavaFeatures::GetMetadata() const {

@ -269,9 +269,21 @@ class PROTOC_EXPORT JavaFeatures final
// accessors ------------------------------------------------------- // accessors -------------------------------------------------------
enum : int { enum : int {
kLegacyClosedEnumFieldNumber = 1,
kUtf8ValidationFieldNumber = 2, kUtf8ValidationFieldNumber = 2,
kLegacyClosedEnumFieldNumber = 1,
kUseOldOuterClassnameDefaultFieldNumber = 4,
}; };
// optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_utf8_validation() const;
void clear_utf8_validation() ;
::pb::JavaFeatures_Utf8Validation utf8_validation() const;
void set_utf8_validation(::pb::JavaFeatures_Utf8Validation value);
private:
::pb::JavaFeatures_Utf8Validation _internal_utf8_validation() const;
void _internal_set_utf8_validation(::pb::JavaFeatures_Utf8Validation value);
public:
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_legacy_closed_enum() const; bool has_legacy_closed_enum() const;
void clear_legacy_closed_enum() ; void clear_legacy_closed_enum() ;
@ -283,15 +295,15 @@ class PROTOC_EXPORT JavaFeatures final
void _internal_set_legacy_closed_enum(bool value); void _internal_set_legacy_closed_enum(bool value);
public: public:
// optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional bool use_old_outer_classname_default = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_utf8_validation() const; bool has_use_old_outer_classname_default() const;
void clear_utf8_validation() ; void clear_use_old_outer_classname_default() ;
::pb::JavaFeatures_Utf8Validation utf8_validation() const; bool use_old_outer_classname_default() const;
void set_utf8_validation(::pb::JavaFeatures_Utf8Validation value); void set_use_old_outer_classname_default(bool value);
private: private:
::pb::JavaFeatures_Utf8Validation _internal_utf8_validation() const; bool _internal_use_old_outer_classname_default() const;
void _internal_set_utf8_validation(::pb::JavaFeatures_Utf8Validation value); void _internal_set_use_old_outer_classname_default(bool value);
public: public:
// @@protoc_insertion_point(class_scope:pb.JavaFeatures) // @@protoc_insertion_point(class_scope:pb.JavaFeatures)
@ -299,7 +311,7 @@ class PROTOC_EXPORT JavaFeatures final
class _Internal; class _Internal;
friend class ::google::protobuf::internal::TcParser; friend class ::google::protobuf::internal::TcParser;
static const ::google::protobuf::internal::TcParseTable< static const ::google::protobuf::internal::TcParseTable<
1, 2, 1, 2, 3, 1,
0, 2> 0, 2>
_table_; _table_;
@ -319,8 +331,9 @@ class PROTOC_EXPORT JavaFeatures final
const JavaFeatures& from_msg); const JavaFeatures& from_msg);
::google::protobuf::internal::HasBits<1> _has_bits_; ::google::protobuf::internal::HasBits<1> _has_bits_;
::google::protobuf::internal::CachedSize _cached_size_; ::google::protobuf::internal::CachedSize _cached_size_;
bool legacy_closed_enum_;
int utf8_validation_; int utf8_validation_;
bool legacy_closed_enum_;
bool use_old_outer_classname_default_;
PROTOBUF_TSAN_DECLARE_MEMBER PROTOBUF_TSAN_DECLARE_MEMBER
}; };
union { Impl_ _impl_; }; union { Impl_ _impl_; };
@ -352,13 +365,13 @@ PROTOC_EXPORT extern ::google::protobuf::internal::ExtensionIdentifier<
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
inline bool JavaFeatures::has_legacy_closed_enum() const { inline bool JavaFeatures::has_legacy_closed_enum() const {
bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0;
return value; return value;
} }
inline void JavaFeatures::clear_legacy_closed_enum() { inline void JavaFeatures::clear_legacy_closed_enum() {
::google::protobuf::internal::TSanWrite(&_impl_); ::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.legacy_closed_enum_ = false; _impl_.legacy_closed_enum_ = false;
_impl_._has_bits_[0] &= ~0x00000001u; _impl_._has_bits_[0] &= ~0x00000002u;
} }
inline bool JavaFeatures::legacy_closed_enum() const { inline bool JavaFeatures::legacy_closed_enum() const {
// @@protoc_insertion_point(field_get:pb.JavaFeatures.legacy_closed_enum) // @@protoc_insertion_point(field_get:pb.JavaFeatures.legacy_closed_enum)
@ -366,7 +379,7 @@ inline bool JavaFeatures::legacy_closed_enum() const {
} }
inline void JavaFeatures::set_legacy_closed_enum(bool value) { inline void JavaFeatures::set_legacy_closed_enum(bool value) {
_internal_set_legacy_closed_enum(value); _internal_set_legacy_closed_enum(value);
_impl_._has_bits_[0] |= 0x00000001u; _impl_._has_bits_[0] |= 0x00000002u;
// @@protoc_insertion_point(field_set:pb.JavaFeatures.legacy_closed_enum) // @@protoc_insertion_point(field_set:pb.JavaFeatures.legacy_closed_enum)
} }
inline bool JavaFeatures::_internal_legacy_closed_enum() const { inline bool JavaFeatures::_internal_legacy_closed_enum() const {
@ -380,13 +393,13 @@ inline void JavaFeatures::_internal_set_legacy_closed_enum(bool value) {
// optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { // optional .pb.JavaFeatures.Utf8Validation utf8_validation = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
inline bool JavaFeatures::has_utf8_validation() const { inline bool JavaFeatures::has_utf8_validation() const {
bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0; bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0;
return value; return value;
} }
inline void JavaFeatures::clear_utf8_validation() { inline void JavaFeatures::clear_utf8_validation() {
::google::protobuf::internal::TSanWrite(&_impl_); ::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.utf8_validation_ = 0; _impl_.utf8_validation_ = 0;
_impl_._has_bits_[0] &= ~0x00000002u; _impl_._has_bits_[0] &= ~0x00000001u;
} }
inline ::pb::JavaFeatures_Utf8Validation JavaFeatures::utf8_validation() const { inline ::pb::JavaFeatures_Utf8Validation JavaFeatures::utf8_validation() const {
// @@protoc_insertion_point(field_get:pb.JavaFeatures.utf8_validation) // @@protoc_insertion_point(field_get:pb.JavaFeatures.utf8_validation)
@ -394,7 +407,7 @@ inline ::pb::JavaFeatures_Utf8Validation JavaFeatures::utf8_validation() const {
} }
inline void JavaFeatures::set_utf8_validation(::pb::JavaFeatures_Utf8Validation value) { inline void JavaFeatures::set_utf8_validation(::pb::JavaFeatures_Utf8Validation value) {
_internal_set_utf8_validation(value); _internal_set_utf8_validation(value);
_impl_._has_bits_[0] |= 0x00000002u; _impl_._has_bits_[0] |= 0x00000001u;
// @@protoc_insertion_point(field_set:pb.JavaFeatures.utf8_validation) // @@protoc_insertion_point(field_set:pb.JavaFeatures.utf8_validation)
} }
inline ::pb::JavaFeatures_Utf8Validation JavaFeatures::_internal_utf8_validation() const { inline ::pb::JavaFeatures_Utf8Validation JavaFeatures::_internal_utf8_validation() const {
@ -407,6 +420,34 @@ inline void JavaFeatures::_internal_set_utf8_validation(::pb::JavaFeatures_Utf8V
_impl_.utf8_validation_ = value; _impl_.utf8_validation_ = value;
} }
// optional bool use_old_outer_classname_default = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FILE, edition_defaults = {
inline bool JavaFeatures::has_use_old_outer_classname_default() const {
bool value = (_impl_._has_bits_[0] & 0x00000004u) != 0;
return value;
}
inline void JavaFeatures::clear_use_old_outer_classname_default() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.use_old_outer_classname_default_ = false;
_impl_._has_bits_[0] &= ~0x00000004u;
}
inline bool JavaFeatures::use_old_outer_classname_default() const {
// @@protoc_insertion_point(field_get:pb.JavaFeatures.use_old_outer_classname_default)
return _internal_use_old_outer_classname_default();
}
inline void JavaFeatures::set_use_old_outer_classname_default(bool value) {
_internal_set_use_old_outer_classname_default(value);
_impl_._has_bits_[0] |= 0x00000004u;
// @@protoc_insertion_point(field_set:pb.JavaFeatures.use_old_outer_classname_default)
}
inline bool JavaFeatures::_internal_use_old_outer_classname_default() const {
::google::protobuf::internal::TSanRead(&_impl_);
return _impl_.use_old_outer_classname_default_;
}
inline void JavaFeatures::_internal_set_use_old_outer_classname_default(bool value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.use_old_outer_classname_default_ = value;
}
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif // __GNUC__ #endif // __GNUC__

@ -7,13 +7,18 @@
#include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/compiler/java/name_resolver.h"
#include <cstddef>
#include <string> #include <string>
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/substitute.h" #include "absl/strings/string_view.h"
#include "google/protobuf/compiler/java/java_features.pb.h"
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/java/generator.h"
#include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/helpers.h"
#include "google/protobuf/compiler/java/names.h" #include "google/protobuf/compiler/java/names.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
@ -32,6 +37,15 @@ namespace {
// conflicts with some other types defined in the file. // conflicts with some other types defined in the file.
const char* kOuterClassNameSuffix = "OuterClass"; const char* kOuterClassNameSuffix = "OuterClass";
inline bool UseOldFileClassNameDefault(const FileDescriptor* file) {
// TODO b/373884685 - Clean up this check once when we have a way to query
// Java features in the C++ runtime.
if (JavaGenerator::GetEdition(*file) < EDITION_2024) return true;
return JavaGenerator::GetResolvedSourceFeatures(*file)
.GetExtension(pb::java)
.use_old_outer_classname_default();
}
// Strip package name from a descriptor's full name. // Strip package name from a descriptor's full name.
// For example: // For example:
// Full name : foo.Bar.Baz // Full name : foo.Bar.Baz
@ -132,7 +146,9 @@ std::string ClassNameResolver::GetFileDefaultImmutableClassName(
} else { } else {
basename = file->name().substr(last_slash + 1); basename = file->name().substr(last_slash + 1);
} }
return UnderscoresToCamelCase(StripProto(basename), true); // foo_bar_baz.proto -> FooBarBaz
std::string ret = UnderscoresToCamelCase(StripProto(basename), true);
return UseOldFileClassNameDefault(file) ? ret : ret + "Proto";
} }
std::string ClassNameResolver::GetFileImmutableClassName( std::string ClassNameResolver::GetFileImmutableClassName(
@ -143,7 +159,11 @@ std::string ClassNameResolver::GetFileImmutableClassName(
class_name = file->options().java_outer_classname(); class_name = file->options().java_outer_classname();
} else { } else {
class_name = GetFileDefaultImmutableClassName(file); class_name = GetFileDefaultImmutableClassName(file);
if (HasConflictingClassName(file, class_name,
// This disambiguation logic is deprecated and only enabled when using
// the old default scheme.
if (UseOldFileClassNameDefault(file) &&
HasConflictingClassName(file, class_name,
NameEquality::EXACT_EQUAL)) { NameEquality::EXACT_EQUAL)) {
class_name += kOuterClassNameSuffix; class_name += kOuterClassNameSuffix;
} }

Loading…
Cancel
Save