-
Notifications
You must be signed in to change notification settings - Fork 65
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
airframe-surface, codec: #1092 Support Enum-like classes in Scala.js #1099
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1099 +/- ##
==========================================
+ Coverage 82.46% 82.60% +0.13%
==========================================
Files 270 271 +1
Lines 10297 10345 +48
Branches 708 666 -42
==========================================
+ Hits 8491 8545 +54
+ Misses 1806 1800 -6
Continue to review full report at Codecov.
|
airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ReflectSurfaceFactory.scala
Outdated
Show resolved
Hide resolved
airframe-surface/shared/src/main/scala/wvlet/airframe/surface/SurfaceMacros.scala
Show resolved
Hide resolved
)""" | ||
expr | ||
case _ => | ||
newGenericSurfaceOf(t) |
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.
This means we cannot define Enum-like classes in the default package? But in reality, we almost always define a package.
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.
OK. I'll add support for unapply methods in package objects.
To use this support, the requirements are
Is this correct? |
@shimamoto Yes. These are correct. I'll try adding (package).unapply(s: String) too |
// companion object package -> Select(Select( .... ))) tree | ||
val ex = tl.foldLeft[Tree](Ident(TermName(p1))) { (z, n) => | ||
Select(z, TermName(n)) | ||
} |
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.
This generates a tree like Select(Select(Ident(TermName(java)), TermName(obj)), TermName(Object))
for java.lang.Object
and it selects a companion object. I see...
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.
There might be a better way to produce this expression, but I could not find it...
@shimamoto I've tried to find package object in Scala Macros, but it was difficult for me to do that. I'm not sure how frequent it is to define |
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.
Sounds good. Thank you for taking the time to give it a try.
Support enum like classes with Surface and codec. This PR closes #1092
This support will be useful for defining RPC/Endpoint model classes with Enum-like case objects that can be shared between Scala JVM and Scala.js.
cc: @takezoe @shimamoto