aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMathias <mathias@decodified.com>2018-01-04 17:45:02 +0100
committerMathias <mathias@decodified.com>2018-01-04 17:45:02 +0100
commit5312aa433cb0d5767c61f94c16d84b4c0f60f17b (patch)
tree59539174a7683432ee437e2463ff5d7bfa427109 /core
parent93e3ff410b93c4d2d886371937ad55c7d269ba99 (diff)
downloadmagnolia-5312aa433cb0d5767c61f94c16d84b4c0f60f17b.tar.gz
magnolia-5312aa433cb0d5767c61f94c16d84b4c0f60f17b.tar.bz2
magnolia-5312aa433cb0d5767c61f94c16d84b4c0f60f17b.zip
Change `typeName: String` to `typeName: magnolia.TypeName` [BREAKING!]
Diffstat (limited to 'core')
-rw-r--r--core/shared/src/main/scala/interface.scala11
-rw-r--r--core/shared/src/main/scala/magnolia.scala21
2 files changed, 24 insertions, 8 deletions
diff --git a/core/shared/src/main/scala/interface.scala b/core/shared/src/main/scala/interface.scala
index b06f350..f0f104c 100644
--- a/core/shared/src/main/scala/interface.scala
+++ b/core/shared/src/main/scala/interface.scala
@@ -104,7 +104,7 @@ trait Param[Typeclass[_], Type] {
* @tparam Typeclass type constructor for the typeclass being derived
* @tparam Type generic type of this parameter */
abstract class CaseClass[Typeclass[_], Type] private[magnolia] (
- val typeName: String,
+ val typeName: TypeName,
val isObject: Boolean,
val isValueClass: Boolean,
parametersArray: Array[Param[Typeclass, Type]]
@@ -157,7 +157,7 @@ abstract class CaseClass[Typeclass[_], Type] private[magnolia] (
* @param subtypesArray an array of [[Subtype]] instances for each subtype in the sealed trait
* @tparam Typeclass type constructor for the typeclass being derived
* @tparam Type generic type of this parameter */
-final class SealedTrait[Typeclass[_], Type](val typeName: String,
+final class SealedTrait[Typeclass[_], Type](val typeName: TypeName,
subtypesArray: Array[Subtype[Typeclass, Type]]) {
/** a sequence of all the subtypes of this sealed trait */
@@ -182,3 +182,10 @@ final class SealedTrait[Typeclass[_], Type](val typeName: String,
rec(0)
}
}
+
+/**
+ * Provides the different parts of a type's class name.
+ */
+final case class TypeName(ownerName: String, short: String) {
+ def full: String = s"$ownerName.$short"
+} \ No newline at end of file
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]],