Add missing Protobuf Java version checks for enums and missing version info when separate Java files are generated.

PiperOrigin-RevId: 599515908
pull/15446/head
Protobuf Team Bot 10 months ago committed by Copybara-Service
parent 3d79d0374b
commit 2c28d728da
  1. 6
      src/google/protobuf/compiler/java/enum.cc
  2. 20
      src/google/protobuf/compiler/java/file.cc

@ -111,6 +111,12 @@ void EnumGenerator::Generate(io::Printer* printer) {
// -----------------------------------------------------------------
printer->Print("static {\n");
printer->Indent();
PrintGencodeVersionValidator(printer, context_->options().opensource_runtime);
printer->Outdent();
printer->Print("}\n");
for (int i = 0; i < aliases_.size(); i++) {
absl::flat_hash_map<absl::string_view, std::string> vars;
vars["classname"] = descriptor_->name();

@ -500,7 +500,7 @@ static void GenerateSibling(
const DescriptorClass* descriptor, GeneratorContext* context,
std::vector<std::string>* file_list, bool annotate_code,
std::vector<std::string>* annotation_list, const std::string& name_suffix,
GeneratorClass* generator,
GeneratorClass* generator, bool opensource_runtime,
void (GeneratorClass::*pfn)(io::Printer* printer)) {
std::string filename =
absl::StrCat(package_dir, descriptor->name(), name_suffix, ".java");
@ -519,8 +519,10 @@ static void GenerateSibling(
"// source: $filename$\n"
"\n",
"filename", descriptor->file()->name());
printer.Print("// Protobuf Java Version: $protobuf_java_version$\n",
"protobuf_java_version", PROTOBUF_JAVA_VERSION_STRING);
if (opensource_runtime) {
printer.Print("// Protobuf Java Version: $protobuf_java_version$\n",
"protobuf_java_version", PROTOBUF_JAVA_VERSION_STRING);
}
if (!java_package.empty()) {
printer.Print(
"package $package$;\n"
@ -550,14 +552,14 @@ void FileGenerator::GenerateSiblings(
GenerateSibling<EnumGenerator>(
package_dir, java_package_, file_->enum_type(i), context, file_list,
options_.annotate_code, annotation_list, "", &generator,
&EnumGenerator::Generate);
options_.opensource_runtime, &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);
options_.opensource_runtime, &EnumLiteGenerator::Generate);
}
}
for (int i = 0; i < file_->message_type_count(); i++) {
@ -565,12 +567,14 @@ void FileGenerator::GenerateSiblings(
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);
message_generators_[i].get(), options_.opensource_runtime,
&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);
message_generators_[i].get(), options_.opensource_runtime,
&MessageGenerator::Generate);
}
if (HasGenericServices(file_, context_->EnforceLite())) {
for (int i = 0; i < file_->service_count(); i++) {
@ -579,7 +583,7 @@ void FileGenerator::GenerateSiblings(
GenerateSibling<ServiceGenerator>(
package_dir, java_package_, file_->service(i), context, file_list,
options_.annotate_code, annotation_list, "", generator.get(),
&ServiceGenerator::Generate);
options_.opensource_runtime, &ServiceGenerator::Generate);
}
}
}

Loading…
Cancel
Save