aboutsummaryrefslogtreecommitdiff
path: root/core/shared/src/main/scala/magnolia.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/shared/src/main/scala/magnolia.scala')
-rw-r--r--core/shared/src/main/scala/magnolia.scala21
1 files changed, 15 insertions, 6 deletions
diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala
index 200d38e..b4179f9 100644
--- a/core/shared/src/main/scala/magnolia.scala
+++ b/core/shared/src/main/scala/magnolia.scala
@@ -218,13 +218,18 @@ object Magnolia {
val resultType = appliedType(typeConstructor, genericType)
- val className = s"${genericType.typeSymbol.owner.fullName}.${genericType.typeSymbol.name.decodedName}"
+ val typeName = TermName(c.freshName("typeName"))
+ val typeNameDef = {
+ val ts = genericType.typeSymbol
+ q"val $typeName = $magnoliaPkg.TypeName(${ts.owner.fullName}, ${ts.name.decodedName.toString})"
+ }
val result = if (isCaseObject) {
val obj = GlobalUtil.patchedCompanionRef(c)(genericType)
val impl = q"""
+ $typeNameDef
${c.prefix}.combine($magnoliaPkg.Magnolia.caseClass[$typeConstructor, $genericType](
- $className, true, false, new $scalaPkg.Array(0), _ => $obj)
+ $typeName, true, false, new $scalaPkg.Array(0), _ => $obj)
)
"""
Some(Typeclass(genericType, impl))
@@ -318,15 +323,17 @@ object Magnolia {
val $paramsVal: $scalaPkg.Array[$magnoliaPkg.Param[$typeConstructor, $genericType]] =
new $scalaPkg.Array(${assignments.length})
..$assignments
+
+ $typeNameDef
${c.prefix}.combine($magnoliaPkg.Magnolia.caseClass[$typeConstructor, $genericType](
- $className,
+ $typeName,
false,
$isValueClass,
$paramsVal,
($fieldValues: $scalaPkg.Seq[Any]) => {
if ($fieldValues.lengthCompare($paramsVal.length) != 0) {
- val msg = "`" + $className + "` has " + $paramsVal.length + " fields, not " + $fieldValues.size
+ val msg = "`" + $typeName.full + "` has " + $paramsVal.length + " fields, not " + $fieldValues.size
throw new java.lang.IllegalArgumentException(msg)
}
new $genericType(..${
@@ -385,9 +392,11 @@ object Magnolia {
new $scalaPkg.Array(${assignments.size})
..$assignments
+
+ $typeNameDef
${c.prefix}.dispatch(new $magnoliaPkg.SealedTrait(
- $className,
+ $typeName,
$subtypesVal: $scalaPkg.Array[$magnoliaPkg.Subtype[$typeConstructor, $genericType]])
): $resultType
}"""
@@ -482,7 +491,7 @@ object Magnolia {
*
* This method is intended to be called only from code generated by the Magnolia macro, and
* should not be called directly from users' code. */
- def caseClass[Tc[_], T](name: String,
+ def caseClass[Tc[_], T](name: TypeName,
obj: Boolean,
valClass: Boolean,
params: Array[Param[Tc, T]],