-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EnumMode enum option #2993
EnumMode enum option #2993
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id 'application' | ||
id 'org.jetbrains.kotlin.jvm' | ||
id 'com.squareup.wire' | ||
} | ||
|
||
wire { | ||
kotlin { | ||
includes = ["enum.geology.*"] | ||
enumMode = "enum_class" | ||
} | ||
kotlin { | ||
includes = ["sealed.geology.*"] | ||
enumMode = "sealed_class" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
syntax = "proto2"; | ||
|
||
package enum.geology; | ||
|
||
import "wire/extensions.proto"; | ||
|
||
option java_package = "com.squareup.enum.geology"; | ||
|
||
// Target is set to "enum_class" so the option should not have any effect. | ||
enum Period { | ||
option (wire.enum_mode) = "enum_class"; | ||
CRETACEOUS = 1; | ||
JURASSIC = 2; | ||
TRIASSIC = 3; | ||
} | ||
|
||
// Target is set to "enum_class" so the option should takes precedence. | ||
enum Continent { | ||
option (wire.enum_mode) = "sealed_class"; | ||
AFRICA = 0; | ||
AMERICA = 1; | ||
ANTARCTICA = 2; | ||
ASIA = 3; | ||
AUSTRALIA = 4; | ||
EUROPE = 5; | ||
} | ||
|
||
enum Drink { | ||
UNKNOWN = 0; | ||
PEPSI = 1; | ||
MOUNTAIN_DEW = 2; | ||
ROOT_BEER = 9; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
syntax = "proto2"; | ||
|
||
package sealed.geology; | ||
|
||
import "wire/extensions.proto"; | ||
|
||
option java_package = "com.squareup.sealed.geology"; | ||
|
||
// Target is set to "sealed_class" so the option should not have any effect. | ||
enum Period { | ||
option (wire.enum_mode) = "sealed_class"; | ||
CRETACEOUS = 1; | ||
JURASSIC = 2; | ||
TRIASSIC = 3; | ||
} | ||
|
||
// Target is set to "sealed_class" so the option should takes precedence. | ||
enum Continent { | ||
option (wire.enum_mode) = "enum_class"; | ||
AFRICA = 0; | ||
AMERICA = 1; | ||
ANTARCTICA = 2; | ||
ASIA = 3; | ||
AUSTRALIA = 4; | ||
EUROPE = 5; | ||
} | ||
|
||
enum Drink { | ||
UNKNOWN = 0; | ||
PEPSI = 1; | ||
MOUNTAIN_DEW = 2; | ||
ROOT_BEER = 9; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,18 @@ extend google.protobuf.FieldOptions { | |
optional bool use_array = 1185; | ||
} | ||
|
||
extend google.protobuf.EnumOptions { | ||
/** | ||
* Defines how an enum type is to be generated. This is only supported by Kotlin generation. | ||
* - 'enum_class': the enum type will be generated as a Kotlin enum class. | ||
* - 'sealed_class': the enum type will be generated as a Kotlin sealed class. | ||
* | ||
* When set, the value of this option takes precedence over the global enum mode that may be set | ||
* at the Kotlin target level in the Wire Gradle plugin. | ||
*/ | ||
optional string enum_mode = 1190; | ||
Comment on lines
+47
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it |
||
} | ||
|
||
extend google.protobuf.EnumValueOptions { | ||
/** | ||
* Annotates an enum constant that starts to be available with a specified version. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this