1616#include < string>
1717
1818#include " absl/strings/string_view.h"
19+ #include " google/protobuf/compiler/java/generator.h"
20+ #include " google/protobuf/compiler/java/java_features.pb.h"
1921#include " google/protobuf/compiler/java/names.h"
2022#include " google/protobuf/compiler/java/options.h"
2123#include " google/protobuf/descriptor.h"
@@ -349,10 +351,12 @@ inline bool ExposePublicParser(const FileDescriptor* descriptor) {
349351// but in the message and can be queried using additional getters that return
350352// ints.
351353inline bool SupportUnknownEnumValue (const FieldDescriptor* field) {
352- // TODO: Check Java legacy_enum_field_treated_as_closed feature.
353- return field->type () != FieldDescriptor::TYPE_ENUM ||
354- FileDescriptorLegacy (field->file ()).syntax () ==
355- FileDescriptorLegacy::SYNTAX_PROTO3;
354+ if (JavaGenerator::GetResolvedSourceFeatures (*field)
355+ .GetExtension (pb::java)
356+ .legacy_closed_enum ()) {
357+ return false ;
358+ }
359+ return field->enum_type () != nullptr && !field->enum_type ()->is_closed ();
356360}
357361
358362// Check whether a message has repeated fields.
@@ -375,7 +379,14 @@ inline bool IsWrappersProtoFile(const FileDescriptor* descriptor) {
375379}
376380
377381inline bool CheckUtf8 (const FieldDescriptor* descriptor) {
378- return descriptor->requires_utf8_validation () ||
382+ if (JavaGenerator::GetResolvedSourceFeatures (*descriptor)
383+ .GetExtension (pb::java)
384+ .utf8_validation () == pb::JavaFeatures::VERIFY) {
385+ return true ;
386+ }
387+ return JavaGenerator::GetResolvedSourceFeatures (*descriptor)
388+ .utf8_validation () == FeatureSet::VERIFY ||
389+ // For legacy syntax. This is not allowed under Editions.
379390 descriptor->file ()->options ().java_string_check_utf8 ();
380391}
381392
0 commit comments