Skip to content

Commit

Permalink
Add java conversions option (backported to 0.10.x)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Jan 30, 2021
1 parent fc40883 commit 3368d5e
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 83 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Change Log
## [0.11.0 (Unreleased)]
[0.11.0 (Unreleased)]
- Supports protobuf 3.12.2
- Supports the new experimental optional fields introduced in proto3 at
protobuf 3.12.0 (see https://github.com/protocolbuffers/protobuf/blob/v3.12.0/docs/field_presence.md). To enable, add the following to your `build.sbt`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@ class DescriptorImplicits private[compiler] (
def scalaOptions: ScalaPbOptions =
fileOptionsCache(file)

def javaConversions = params.javaConversions && !scalaOptions.getTestOnlyNoJavaConversions
def javaConversions =
(scalaOptions.getJavaConversions || params.javaConversions) && !scalaOptions.getTestOnlyNoJavaConversions

def javaPackage: String = {
if (file.getOptions.hasJavaPackage)
Expand Down
6 changes: 6 additions & 0 deletions docs/src/main/markdown/customizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ option (scalapb.options) = {
package_name: "com.example.myprotos"
flat_package: true
single_file: true
java_conversions: false
import: "com.thesamet.pb.MyType"
import: "com.thesamet.other._"
preamble: "sealed trait BaseMessage"
Expand Down Expand Up @@ -54,6 +55,11 @@ globally to all files by adding it to your [ScalaPB SBT Settings]({{site.baseurl
- The `single_file` option makes the generator output all messages and
enums to a single Scala file.

- The `java_conversions` options tells ScalaPB to generate converters to the
corresponding Java messages in this file. It does not automatically trigger
Java source code generation for the messages. If you need to generate source code
in Java, include `PB.gens.java` in the list of targets in sbt-protoc.

- The `preamble` is a list of strings that is output at the top of the
generated Scala file. This option requires `single_file` to be set. It is
commonly used to define sealed traits that are extended using
Expand Down
11 changes: 7 additions & 4 deletions protobuf/scalapb/scalapb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ message ScalaPbOptions {
// Strip is applied before enum value naming changes.
optional bool enum_strip_prefix = 17 [default=false];

// Scala type to use for bytes fields.
optional string bytes_type = 21;

// Enable java conversions for this file.
optional bool java_conversions = 23;

// AuxMessageOptions enables you to set message-level options through package-scoped options.
// This is useful when you can't add a dependency on scalapb.proto from the proto file that
// defines the message.
Expand Down Expand Up @@ -141,11 +147,8 @@ message ScalaPbOptions {
// List of message options to apply to some enums.
repeated AuxEnumOptions aux_enum_options = 20;

// Scala type to use for bytes fields.
optional string bytes_type = 21;

// Taken by ScalaPB 0.11.x branch
reserved 22, 23;
reserved 22;

repeated string preprocessors = 24;

Expand Down
Loading

0 comments on commit 3368d5e

Please sign in to comment.