aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias <mathias@decodified.com>2018-01-05 11:40:27 +0100
committerMathias <mathias@decodified.com>2018-01-05 11:43:51 +0100
commit6ce9fd4ce13ca5fae1c4bc8d2ba3af72bbd4dbf5 (patch)
treed99564efe71c4df1016df4e4f7919f0970a0c101
parentc2acc0fd2f4772ea1b6d3a59271fbe2d9063f69f (diff)
downloadmagnolia-6ce9fd4ce13ca5fae1c4bc8d2ba3af72bbd4dbf5.tar.gz
magnolia-6ce9fd4ce13ca5fae1c4bc8d2ba3af72bbd4dbf5.tar.bz2
magnolia-6ce9fd4ce13ca5fae1c4bc8d2ba3af72bbd4dbf5.zip
Switch `Subtype#label` member to new `TypeName`
-rw-r--r--core/shared/src/main/scala/interface.scala10
-rw-r--r--core/shared/src/main/scala/magnolia.scala6
-rw-r--r--examples/shared/src/main/scala/decode.scala6
3 files changed, 11 insertions, 11 deletions
diff --git a/core/shared/src/main/scala/interface.scala b/core/shared/src/main/scala/interface.scala
index f0f104c..05803f0 100644
--- a/core/shared/src/main/scala/interface.scala
+++ b/core/shared/src/main/scala/interface.scala
@@ -12,10 +12,10 @@ trait Subtype[Typeclass[_], Type] {
/** the type of subtype */
type SType <: Type
- /** the name of the subtype
+ /** the [[TypeName]] of the subtype
*
- * This is the fully-qualified name of the type of subclass. */
- def label: String
+ * This is the full name information for the type of subclass. */
+ def typeName: TypeName
/** the typeclass instance associated with this subtype
*
@@ -186,6 +186,6 @@ final class SealedTrait[Typeclass[_], Type](val typeName: TypeName,
/**
* Provides the different parts of a type's class name.
*/
-final case class TypeName(ownerName: String, short: String) {
- def full: String = s"$ownerName.$short"
+final case class TypeName(owner: String, short: String) {
+ def full: String = s"$owner.$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 b4179f9..c586539 100644
--- a/core/shared/src/main/scala/magnolia.scala
+++ b/core/shared/src/main/scala/magnolia.scala
@@ -377,7 +377,7 @@ object Magnolia {
val assignments = typeclasses.zipWithIndex.map {
case ((typ, typeclass), idx) =>
q"""$subtypesVal($idx) = $magnoliaPkg.Magnolia.subtype[$typeConstructor, $genericType, $typ](
- ${s"${typ.typeSymbol.owner.fullName}.${typ.typeSymbol.name.decodedName}"},
+ $magnoliaPkg.TypeName(${typ.typeSymbol.owner.fullName}, ${typ.typeSymbol.name.decodedName.toString}),
$typeclass,
(t: $genericType) => t.isInstanceOf[$typ],
(t: $genericType) => t.asInstanceOf[$typ]
@@ -460,10 +460,10 @@ 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 subtype[Tc[_], T, S <: T](name: String, tc: => Tc[S], isType: T => Boolean, asType: T => S): Subtype[Tc, T] =
+ def subtype[Tc[_], T, S <: T](name: TypeName, tc: => Tc[S], isType: T => Boolean, asType: T => S): Subtype[Tc, T] =
new Subtype[Tc, T] with PartialFunction[T, S] {
type SType = S
- def label: String = name
+ def typeName: TypeName = name
def typeclass: Tc[SType] = tc
def cast: PartialFunction[T, SType] = this
def isDefinedAt(t: T) = isType(t)
diff --git a/examples/shared/src/main/scala/decode.scala b/examples/shared/src/main/scala/decode.scala
index 5b083bd..595ee6f 100644
--- a/examples/shared/src/main/scala/decode.scala
+++ b/examples/shared/src/main/scala/decode.scala
@@ -26,7 +26,7 @@ object Decoder {
/** defines how new [[Decoder]]s for case classes should be constructed */
def combine[T](ctx: CaseClass[Decoder, T]): Decoder[T] = new Decoder[T] {
def decode(value: String) = {
- val (name, values) = parse(value)
+ val (_, values) = parse(value)
ctx.construct { param =>
param.typeclass.decode(values(param.label))
}
@@ -36,8 +36,8 @@ object Decoder {
/** defines how to choose which subtype of the sealed trait to use for decoding */
def dispatch[T](ctx: SealedTrait[Decoder, T]): Decoder[T] = new Decoder[T] {
def decode(param: String) = {
- val (name, values) = parse(param)
- val subtype = ctx.subtypes.find(_.label == name).get
+ val (name, _) = parse(param)
+ val subtype = ctx.subtypes.find(_.typeName.full == name).get
subtype.typeclass.decode(param)
}
}