Skip to content

Commit

Permalink
Started moving Kotlin DSL generator to its own directory.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 663760495
  • Loading branch information
haberman authored and copybara-github committed Aug 16, 2024
1 parent 546c8e0 commit 48f2faa
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ cc_dist_library(
"//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp",
"//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/php",
"//src/google/protobuf/compiler/python",
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ cc_library(
"//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp",
"//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/php",
"//src/google/protobuf/compiler/python",
Expand Down
21 changes: 2 additions & 19 deletions src/google/protobuf/compiler/java/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ cc_library(
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler/java:__subpackages__",
"//src/google/protobuf/compiler/kotlin:__subpackages__",
],
deps = [
"//src/google/protobuf",
Expand Down Expand Up @@ -116,6 +117,7 @@ cc_library(
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
"//src/google/protobuf/compiler/kotlin:__subpackages__",
],
deps = [
":generator_common",
Expand Down Expand Up @@ -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(
name = "doc_comment_unittest",
srcs = ["doc_comment_unittest.cc"],
Expand Down
19 changes: 19 additions & 0 deletions src/google/protobuf/compiler/kotlin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
16 changes: 16 additions & 0 deletions src/google/protobuf/compiler/kotlin/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
// license that can be found in the LICENSE file or at
// 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 "google/protobuf/compiler/code_generator.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/options.h"
#include "google/protobuf/io/printer.h"

namespace google {
namespace protobuf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

// Generates Kotlin code for a given .proto file.

#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__
#ifndef GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__

#include <cstdint>
#include <string>
#include <vector>

#include "google/protobuf/compiler/java/java_features.pb.h"
#include "google/protobuf/compiler/code_generator.h"
Expand Down Expand Up @@ -58,4 +60,4 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator {

#include "google/protobuf/port_undef.inc"

#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__
#endif // GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "google/protobuf/compiler/cpp/generator.h"
#include "google/protobuf/compiler/csharp/csharp_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/php/php_generator.h"
#include "google/protobuf/compiler/python/generator.h"
Expand Down

0 comments on commit 48f2faa

Please sign in to comment.