Started moving Kotlin DSL generator to its own directory.

PiperOrigin-RevId: 663760495
pull/17832/head
Joshua Haberman 3 months ago committed by Copybara-Service
parent 546c8e0a25
commit 48f2faa70e
  1. 2
      pkg/BUILD.bazel
  2. 2
      src/google/protobuf/compiler/BUILD.bazel
  3. 21
      src/google/protobuf/compiler/java/BUILD.bazel
  4. 19
      src/google/protobuf/compiler/kotlin/BUILD.bazel
  5. 16
      src/google/protobuf/compiler/kotlin/README.md
  6. 10
      src/google/protobuf/compiler/kotlin/generator.cc
  7. 8
      src/google/protobuf/compiler/kotlin/generator.h
  8. 2
      src/google/protobuf/compiler/main.cc

@ -198,7 +198,7 @@ cc_dist_library(
"//src/google/protobuf/compiler/cpp", "//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp", "//src/google/protobuf/compiler/csharp",
"//src/google/protobuf/compiler/java", "//src/google/protobuf/compiler/java",
"//src/google/protobuf/compiler/java:kotlin", "//src/google/protobuf/compiler/kotlin",
"//src/google/protobuf/compiler/objectivec", "//src/google/protobuf/compiler/objectivec",
"//src/google/protobuf/compiler/php", "//src/google/protobuf/compiler/php",
"//src/google/protobuf/compiler/python", "//src/google/protobuf/compiler/python",

@ -195,7 +195,7 @@ cc_library(
"//src/google/protobuf/compiler/cpp", "//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp", "//src/google/protobuf/compiler/csharp",
"//src/google/protobuf/compiler/java", "//src/google/protobuf/compiler/java",
"//src/google/protobuf/compiler/java:kotlin", "//src/google/protobuf/compiler/kotlin",
"//src/google/protobuf/compiler/objectivec", "//src/google/protobuf/compiler/objectivec",
"//src/google/protobuf/compiler/php", "//src/google/protobuf/compiler/php",
"//src/google/protobuf/compiler/python", "//src/google/protobuf/compiler/python",

@ -45,6 +45,7 @@ cc_library(
visibility = [ visibility = [
"//pkg:__pkg__", "//pkg:__pkg__",
"//src/google/protobuf/compiler/java:__subpackages__", "//src/google/protobuf/compiler/java:__subpackages__",
"//src/google/protobuf/compiler/kotlin:__subpackages__",
], ],
deps = [ deps = [
"//src/google/protobuf", "//src/google/protobuf",
@ -116,6 +117,7 @@ cc_library(
visibility = [ visibility = [
"//pkg:__pkg__", "//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__", "//src/google/protobuf/compiler:__pkg__",
"//src/google/protobuf/compiler/kotlin:__subpackages__",
], ],
deps = [ deps = [
":generator_common", ":generator_common",
@ -182,25 +184,6 @@ cc_library(
], ],
) )
cc_library(
name = "kotlin",
srcs = ["kotlin_generator.cc"],
hdrs = ["kotlin_generator.h"],
strip_include_prefix = "/src",
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
],
deps = [
":helpers",
":java",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/strings",
],
)
cc_test( cc_test(
name = "doc_comment_unittest", name = "doc_comment_unittest",
srcs = ["doc_comment_unittest.cc"], srcs = ["doc_comment_unittest.cc"],

@ -0,0 +1,19 @@
cc_library(
name = "kotlin",
srcs = ["generator.cc"],
hdrs = ["generator.h"],
strip_include_prefix = "/src",
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
],
deps = [
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf/compiler/java",
"//src/google/protobuf/compiler/java:helpers",
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/strings",
],
)

@ -0,0 +1,16 @@
# Kotlin DSL Generator
This code generator implements the Kotlin DSL. The Kotlin DSL sits on top of
another proto implementation (written in Java or Kotlin) and adds convenient
support for building proto messages using DSL syntax, as documented in
[Kotlin Generated Code Guide](https://protobuf.dev/reference/kotlin/kotlin-generated/).
This code generator is invoked by passing `--kotlin_out` to `protoc`.
When using Kotlin on the JVM, you will also need to pass `--java_out` to
generate the Java code that implements the generated classes themselves.
When using Kotlin on other platforms (eg. Kotlin Native), there is currently no
support for generating message classes, so it is not possible to use the Kotlin
DSL at this time.

@ -5,14 +5,20 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd // https://developers.google.com/open-source/licenses/bsd
#include "google/protobuf/compiler/java/kotlin_generator.h" #include "google/protobuf/compiler/kotlin/generator.h"
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/java/file.h" #include "google/protobuf/compiler/java/file.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/options.h" #include "google/protobuf/compiler/java/options.h"
#include "google/protobuf/io/printer.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {

@ -7,10 +7,12 @@
// Generates Kotlin code for a given .proto file. // Generates Kotlin code for a given .proto file.
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ #ifndef GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__
#include <cstdint>
#include <string> #include <string>
#include <vector>
#include "google/protobuf/compiler/java/java_features.pb.h" #include "google/protobuf/compiler/java/java_features.pb.h"
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
@ -58,4 +60,4 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator {
#include "google/protobuf/port_undef.inc" #include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ #endif // GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__

@ -10,7 +10,7 @@
#include "google/protobuf/compiler/cpp/generator.h" #include "google/protobuf/compiler/cpp/generator.h"
#include "google/protobuf/compiler/csharp/csharp_generator.h" #include "google/protobuf/compiler/csharp/csharp_generator.h"
#include "google/protobuf/compiler/java/generator.h" #include "google/protobuf/compiler/java/generator.h"
#include "google/protobuf/compiler/java/kotlin_generator.h" #include "google/protobuf/compiler/kotlin/generator.h"
#include "google/protobuf/compiler/objectivec/generator.h" #include "google/protobuf/compiler/objectivec/generator.h"
#include "google/protobuf/compiler/php/php_generator.h" #include "google/protobuf/compiler/php/php_generator.h"
#include "google/protobuf/compiler/python/generator.h" #include "google/protobuf/compiler/python/generator.h"

Loading…
Cancel
Save