Skip to content
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

Use dedicated macro for scala 3 enum type #983

Open
wants to merge 4 commits into
base: v0.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ val commonSettings = Seq(
"-Yretain-trees",
// tolerate some nested macro expansion
"-Xmax-inlines",
"64"
"128"
)
case Some((2, 13)) =>
Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import magnolify.shims.FactoryCompat
import scala.annotation.implicitNotFound
import scala.collection.concurrent
import scala.reflect.ClassTag
import scala.util.Try
import scala.jdk.CollectionConverters.*
import scala.collection.compat.*

Expand Down Expand Up @@ -241,7 +242,8 @@ object ProtobufField {
.asInstanceOf[Array[E]]
.map(e => e.name() -> e)
.toMap
val default = et.from(map.values.find(_.getNumber == 0).get.name())

val default = et.from(map.values.find(e => Try(e.getNumber).getOrElse(-1) == 0).get.name())
aux2[T, EnumValueDescriptor](default)(e => et.from(e.getName))(e =>
map(et.to(e)).getValueDescriptor
)
Expand Down
95 changes: 50 additions & 45 deletions protobuf/src/test/protobuf/Proto2.proto
Original file line number Diff line number Diff line change
@@ -1,82 +1,87 @@
syntax = "proto2";

package magnolify.protobuf;
package magnolify.protobuf.v2;

option java_package = "magnolify.protobuf";

message IntegersP2 {
message Integers {
required int32 i = 1;
required int64 l = 2;
}

message FloatsP2 {
message Floats {
required float f = 1;
required double d = 2;
}

message RequiredP2 {
message Required {
required bool b = 1;
required string s = 2;
required int32 i = 3;
}

message NullableP2 {
message Nullable {
optional bool b = 1;
optional string s = 2;
optional int32 i = 3;
}

message RepeatedP2 {
message Repeated {
repeated bool b = 1;
repeated string s = 2;
repeated int32 i = 3;
}

message NestedP2 {
message Nested {
required bool b = 1;
required string s = 2;
required int32 i = 3;
required RequiredP2 r = 4;
optional RequiredP2 o = 5;
repeated RequiredP2 l = 6;
required Required r = 4;
optional Required o = 5;
repeated Required l = 6;
}

message CollectionP2 {
message Collection {
repeated int32 a = 1;
repeated int32 l = 2;
repeated int32 v = 3;
repeated int32 s = 4;
}

message MoreCollectionP2 {
message MoreCollection {
repeated int32 i = 1;
repeated int32 s = 2;
repeated int32 is = 3;
}

message EnumsP2 {
enum JavaEnums {
RED = 0;
GREEN = 1;
BLUE = 2;
}
enum ScalaEnums {
Red = 0;
Green = 1;
Blue = 2;
}
required JavaEnums j = 1;
required ScalaEnums s = 2; // Enumeration
required ScalaEnums a = 3; // ADT
optional JavaEnums jo = 4;
optional ScalaEnums so = 5; // Enumeration
optional ScalaEnums ao = 6; // ADT
repeated JavaEnums jr = 7;
repeated ScalaEnums sr = 8; // Enumeration
repeated ScalaEnums ar = 9; // ADT
}

message UnsafeEnumsP2 {
enum UpperCaseColor {
RED = 0;
GREEN = 1;
BLUE = 2;
}

enum CamelCaseColor {
Red = 0;
Green = 1;
Blue = 2;
Yellow = 3;
Cyan = 4;
Magenta = 5;
}

message Enums {
required UpperCaseColor j = 1;
required CamelCaseColor s = 2; // Enumeration
required CamelCaseColor a = 3; // ADT
optional UpperCaseColor jo = 4;
optional CamelCaseColor so = 5; // Enumeration
optional CamelCaseColor ao = 6; // ADT
repeated UpperCaseColor jr = 7;
repeated CamelCaseColor sr = 8; // Enumeration
repeated CamelCaseColor ar = 9; // ADT
}

message UnsafeEnums {
required string j = 1;
required string s = 2;
required string a = 3;
Expand All @@ -88,37 +93,37 @@ message UnsafeEnumsP2 {
repeated string ar = 9;
}

message CustomP2 {
message Custom {
required string u = 1;
required int64 d = 2;
}

message BytesP2 {
message Bytes {
required bytes b = 1;
}

message DefaultRequiredP2 {
message DefaultRequired {
required int32 i = 1 [default = 123];
required int64 l = 2 [default = 456];
required float f = 3 [default = 1.23];
required double d = 4 [default = 4.56];
required bool b = 5 [default = true];
required string s = 6 [default = "abc"];
required bytes bs = 7 [default = "def"];
required EnumsP2.JavaEnums je = 8 [default = GREEN];
required EnumsP2.ScalaEnums se = 9 [default = Green]; // Enumeration
required EnumsP2.ScalaEnums ae = 10 [default = Green]; // ADT
required UpperCaseColor je = 8 [default = GREEN];
required CamelCaseColor se = 9 [default = Green]; // Enumeration
required CamelCaseColor ae = 10 [default = Cyan]; // ADT
}

message DefaultNullableP2 {
message DefaultNullable {
optional int32 i = 1 [default = 123];
optional int64 l = 2 [default = 456];
optional float f = 3 [default = 1.23];
optional double d = 4 [default = 4.56];
optional bool b = 5 [default = true];
optional string s = 6 [default = "abc"];
optional bytes bs = 7 [default = "def"];
optional EnumsP2.JavaEnums je = 8 [default = GREEN];
optional EnumsP2.ScalaEnums se = 9 [default = Green]; // Enumeration
optional EnumsP2.ScalaEnums ae = 10 [default = Green]; // ADT
optional UpperCaseColor je = 8 [default = GREEN];
optional CamelCaseColor se = 9 [default = Green]; // Enumeration
optional CamelCaseColor ae = 10 [default = Cyan]; // ADT
}
85 changes: 45 additions & 40 deletions protobuf/src/test/protobuf/Proto3.proto
Original file line number Diff line number Diff line change
@@ -1,82 +1,87 @@
syntax = "proto3";

package magnolify.protobuf;
package magnolify.protobuf.v3;

option java_package = "magnolify.protobuf";

message IntegersP3 {
message Integers {
int32 i = 1;
int64 l = 2;
}

message FloatsP3 {
message Floats {
float f = 1;
double d = 2;
}

message RequiredP3 {
message Required {
bool b = 1;
string s = 2;
int32 i = 3;
}

message NullableP3 {
message Nullable {
optional bool b = 1;
optional string s = 2;
optional int32 i = 3;
}

message RepeatedP3 {
message Repeated {
repeated bool b = 1;
repeated string s = 2;
repeated int32 i = 3;
}

message NestedP3 {
message Nested {
bool b = 1;
string s = 2;
int32 i = 3;
RequiredP3 r = 4;
optional RequiredP3 o = 5;
repeated RequiredP3 l = 6;
Required r = 4;
optional Required o = 5;
repeated Required l = 6;
}

message CollectionP3 {
message Collection {
repeated int32 a = 1;
repeated int32 l = 2;
repeated int32 v = 3;
repeated int32 s = 4;
}

message MoreCollectionP3 {
message MoreCollection {
repeated int32 i = 1;
repeated int32 s = 2;
repeated int32 is = 3;
}

message EnumsP3 {
enum JavaEnums {
RED = 0;
GREEN = 1;
BLUE = 2;
}
enum ScalaEnums {
Red = 0;
Green = 1;
Blue = 2;
}
JavaEnums j = 1;
ScalaEnums s = 2; // Enumeration
ScalaEnums a = 3; // ADT
optional JavaEnums jo = 4;
optional ScalaEnums so = 5; // Enumeration
optional ScalaEnums ao = 6; // ADT
repeated JavaEnums jr = 7;
repeated ScalaEnums sr = 8; // Enumeration
repeated ScalaEnums ar = 9; // ADT
}

message UnsafeEnumsP3 {
enum UpperCaseColor {
RED = 0;
GREEN = 1;
BLUE = 2;
}

enum CamelCaseColor {
Red = 0;
Green = 1;
Blue = 2;
Yellow = 3;
Cyan = 4;
Magenta = 5;
}

message Enums {
UpperCaseColor j = 1;
CamelCaseColor s = 2; // Enumeration
CamelCaseColor a = 3; // ADT
optional UpperCaseColor jo = 4;
optional CamelCaseColor so = 5; // Enumeration
optional CamelCaseColor ao = 6; // ADT
repeated UpperCaseColor jr = 7;
repeated CamelCaseColor sr = 8; // Enumeration
repeated CamelCaseColor ar = 9; // ADT
}

message UnsafeEnums {
string j = 1;
string s = 2;
string a = 3;
Expand All @@ -88,21 +93,21 @@ message UnsafeEnumsP3 {
repeated string ar = 9;
}

message CustomP3 {
message Custom {
string u = 1;
int64 d = 2;
}

message BytesP3 {
message Bytes {
bytes b = 1;
}

message UpperCaseP3 {
message UpperCase {
string FIRSTFIELD = 1;
string SECONDFIELD = 2;
UpperCaseInnerP3 INNERFIELD = 3;
UpperCaseInner INNERFIELD = 3;
}

message UpperCaseInnerP3 {
message UpperCaseInner {
string INNERFIRST = 1;
}
Loading
Loading