diff options
author | Jon Pretty <jon.pretty@propensive.com> | 2018-01-05 16:16:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 16:16:37 +0100 |
commit | 480564092cdbd5c69f63089a2198299706690e7a (patch) | |
tree | 2243e14792b4e7428177bfea1699db276db6d187 | |
parent | 2e98161a4c18d8f56280437a775cf81df030c0cf (diff) | |
parent | 235f2ddd5adf5c99cf53d6e6321dbe5e2fd842c2 (diff) | |
download | magnolia-480564092cdbd5c69f63089a2198299706690e7a.tar.gz magnolia-480564092cdbd5c69f63089a2198299706690e7a.tar.bz2 magnolia-480564092cdbd5c69f63089a2198299706690e7a.zip |
Merge branch 'master' into md/debug-annotation
-rw-r--r-- | core/shared/src/main/scala/interface.scala | 12 | ||||
-rw-r--r-- | core/shared/src/main/scala/magnolia.scala | 9 | ||||
-rw-r--r-- | examples/shared/src/main/scala/decode.scala | 6 | ||||
-rw-r--r-- | tests/src/main/scala/tests.scala | 4 |
4 files changed, 17 insertions, 14 deletions
diff --git a/core/shared/src/main/scala/interface.scala b/core/shared/src/main/scala/interface.scala index 93aa045..51abc22 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,8 +186,8 @@ 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" } /** @@ -198,4 +198,4 @@ final case class TypeName(ownerName: String, short: String) { * @param typeNamePart If non-empty restricts the output generation to types * whose full name contains the given [[String]] */ -final class debug(typeNamePart: String = "") extends scala.annotation.StaticAnnotation
\ No newline at end of file +final class debug(typeNamePart: String = "") extends scala.annotation.StaticAnnotation diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala index 67e948e..b5c196a 100644 --- a/core/shared/src/main/scala/magnolia.scala +++ b/core/shared/src/main/scala/magnolia.scala @@ -229,11 +229,10 @@ object Magnolia { } val result = if (isCaseObject) { - val obj = GlobalUtil.patchedCompanionRef(c)(genericType) val impl = q""" $typeNameDef ${c.prefix}.combine($magnoliaPkg.Magnolia.caseClass[$typeConstructor, $genericType]( - $typeName, true, false, new $scalaPkg.Array(0), _ => $obj) + $typeName, true, false, new $scalaPkg.Array(0), _ => ${genericType.typeSymbol.asClass.module}) ) """ Some(Typeclass(genericType, impl)) @@ -381,7 +380,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] @@ -468,10 +467,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) } } diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala index 5b47627..6c2ab9a 100644 --- a/tests/src/main/scala/tests.scala +++ b/tests/src/main/scala/tests.scala @@ -318,6 +318,10 @@ object Tests extends TestApp { test("show a Portfolio of Companies") { Show.gen[Portfolio].show(Portfolio(Company("Alice Inc"), Company("Bob & Co"))) }.assert(_ == "Portfolio(companies=[Company(name=Alice Inc),Company(name=Bob & Co)])") + + test("show a List[Int]") { + Show.gen[List[Int]].show(List(1, 2, 3)) + }.assert(_ == "::(head=1,tl$access$1=::(head=2,tl$access$1=::(head=3,tl$access$1=Nil())))") test("sealed trait typeName should be complete and unchanged") { TypeNameInfo.gen[Color].name |