Utilities for extracting GenCodec field / type names#674
Utilities for extracting GenCodec field / type names#674
Conversation
| * | ||
| * @see [[com.avsystem.commons.serialization.GenCodecUtils.codecTypeName]] | ||
| */ | ||
| final class GencodecTypeName[T](val name: String) |
| 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.
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.
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.
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.
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.
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