Add template comment and package to previously empty generated kotlin proto files.

We generate a Kotlin file to correspond to each message, which left the per-file generated file blank. We would still like to generate a file to deal with edge cases where there are no messages defined in a proto file. To fix, we print the default comment about the file being generated as well as a package statement.

PiperOrigin-RevId: 486969373
pull/10926/head
Deanna Garcia 2 years ago committed by Copybara-Service
parent 35993fef77
commit 9dfe7e9d8b
  1. 17
      src/google/protobuf/compiler/java/file.cc
  2. 1
      src/google/protobuf/compiler/java/file.h
  3. 2
      src/google/protobuf/compiler/java/kotlin_generator.cc

@ -689,6 +689,23 @@ std::string FileGenerator::GetKotlinClassname() {
return name_resolver_->GetFileClassName(file_, immutable_api_, true);
}
void FileGenerator::GenerateKotlin(io::Printer* printer) {
printer->Print(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n"
"\n",
"filename", file_->name());
printer->Print(
"// Generated files should ignore deprecation warnings\n"
"@file:Suppress(\"DEPRECATION\")");
if (!java_package_.empty()) {
printer->Print(
"package $package$;\n"
"\n",
"package", EscapeKotlinKeywords(java_package_));
}
}
void FileGenerator::GenerateKotlinSiblings(
const std::string& package_dir, GeneratorContext* context,
std::vector<std::string>* file_list,

@ -82,6 +82,7 @@ class FileGenerator {
void Generate(io::Printer* printer);
std::string GetKotlinClassname();
void GenerateKotlin(io::Printer* printer);
void GenerateKotlinSiblings(const std::string& package_dir,
GeneratorContext* generator_context,
std::vector<std::string>* file_list,

@ -119,6 +119,8 @@ bool KotlinGenerator::Generate(const FileDescriptor* file,
output.get(), '$',
file_options.annotate_code ? &annotation_collector : nullptr);
file_generator->GenerateKotlin(&printer);
file_generator->GenerateKotlinSiblings(package_dir, context, &all_files,
&all_annotations);

Loading…
Cancel
Save