-
Notifications
You must be signed in to change notification settings - Fork 22
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
Utilities for extracting GenCodec field / type names #674
base: master
Are you sure you want to change the base?
Conversation
* | ||
* @see [[com.avsystem.commons.serialization.GenCodecUtils.codecTypeName]] | ||
*/ | ||
final class GencodecTypeName[T](val name: String) |
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.
GenCodecTypeName
import com.avsystem.commons.annotation.explicitGenerics | ||
|
||
/** | ||
* Typeclass holding name of a type that will be used in [[GenCodec]] serialization |
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.
nit: something like Typeclass holding a name used by GenCodec to serialize the T type.
would be easier to understand for first time reader imho
|
||
implicit def materialize[T]: GencodecTypeName[T] = | ||
macro com.avsystem.commons.macros.serialization.GenCodecUtilMacros.codecTypeName[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.
Not gonna die on this hill, but I'm wondering if we even need the typeclass, the use case is pretty esoteric and the util covers it.
test("subtypes count leaf") { | ||
GenCodecUtils.knownSubtypesCount[CaseOther] shouldBe 0 | ||
} | ||
} |
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.
According to scaladoc:
@name
annotation may be defined on any level of inheritance hierarchy. For instance, if a case class field overrides a method of some base trait, the @name
annotation may be used on that method and will affect the case class field.`
We should definitely test that.
|
||
class GenCodecUtilsTest extends AnyFunSuite with Matchers { | ||
import GenCodecUtilsTest.* | ||
|
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.
If we change behaviour of GenCodec, but not the behaviour of this class, we may miss the discrepancy. Maybe we should write a custom output that will make it simple to compare if the name is also equal to what gencodec actually outputs.
import scala.annotation.tailrec | ||
import scala.reflect.macros.blackbox | ||
|
||
class GenCodecUtilMacros(ctx: blackbox.Context) extends CodecMacroCommons(ctx) { |
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.
Do you think this macro could share some code with GenCodec macros for more intended coupling now that they are in the same module?
Utilities for extracting GenCodec field / type names