aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wright <kevin.wright@bradyplc.com>2018-02-08 21:20:53 +0000
committerKevin Wright <kevin.wright@bradyplc.com>2018-02-08 21:20:53 +0000
commitc1b9c1f53a6bb3f62abc7141e6b6153d8208e1f0 (patch)
treee867d326898b1e7d0019753728b921c3a160167c
parent6660480a75b240b7ac613ed308e5b7f7ddfc6459 (diff)
downloadmagnolia-c1b9c1f53a6bb3f62abc7141e6b6153d8208e1f0.tar.gz
magnolia-c1b9c1f53a6bb3f62abc7141e6b6153d8208e1f0.tar.bz2
magnolia-c1b9c1f53a6bb3f62abc7141e6b6153d8208e1f0.zip
post-review changes
-rw-r--r--CONTRIBUTORS1
-rw-r--r--build.sbt6
-rw-r--r--core/shared/src/main/scala/interface.scala2
-rw-r--r--core/shared/src/main/scala/magnolia.scala6
-rw-r--r--examples/shared/src/main/scala/decode.scala8
-rw-r--r--examples/shared/src/main/scala/show.scala2
6 files changed, 12 insertions, 13 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index d0d60e5..4e84fbb 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -3,3 +3,4 @@ Loïc Descotte [@loic_d](https://twitter.com/loic_d)
Georgi Krastev [@joro_kr](https://twitter.com/joro_kr/)
Shadaj Laddad [@shadaj](https://twitter.com/shadajl)
Mathias Doenitz [@sirthias](https://twitter.com/sirthias)
+Kevin Wright [@thecoda](https://twitter.com/thecoda)
diff --git a/build.sbt b/build.sbt
index 487c103..50ec53d 100644
--- a/build.sbt
+++ b/build.sbt
@@ -30,7 +30,6 @@ lazy val tests = project
initialCommands in console := """import magnolia.tests._; import magnolia.examples._;""",
libraryDependencies ++= Seq(
"com.fommil" %% "deriving-macro" % "0.9.0",
- "com.fommil" %% "scalaz-deriving" % "0.9.0",
// These two to allow compilation under Java 9...
// Specifically to import XML stuff that got modularised
"javax.xml.bind" % "jaxb-api" % "2.3.0" % "compile",
@@ -92,11 +91,6 @@ lazy val publishSettings = Seq(
<name>Jon Pretty</name>
<url>https://github.com/propensive/magnolia/</url>
</developer>
- <developer>
- <id>thecoda</id>
- <name>Kevin Wright</name>
- <url>https://github.com/kevinwright/</url>
- </developer>
</developers>
)
)
diff --git a/core/shared/src/main/scala/interface.scala b/core/shared/src/main/scala/interface.scala
index 97ea5b7..1dac65e 100644
--- a/core/shared/src/main/scala/interface.scala
+++ b/core/shared/src/main/scala/interface.scala
@@ -113,6 +113,7 @@ trait Param[Typeclass[_], Type] {
* @param typeName the name of the case class
* @param isObject true only if this represents a case object rather than a case class
* @param parametersArray an array of [[Param]] values for this case class
+ * @param annotationsArray an array of instantiated annotations applied to this case class
* @tparam Typeclass type constructor for the typeclass being derived
* @tparam Type generic type of this parameter */
abstract class CaseClass[Typeclass[_], Type] private[magnolia] (
@@ -174,6 +175,7 @@ abstract class CaseClass[Typeclass[_], Type] private[magnolia] (
* which form a coproduct, and to the fully-qualified name of the sealed trait.
* @param typeName the name of the sealed trait
* @param subtypesArray an array of [[Subtype]] instances for each subtype in the sealed trait
+ * @param annotationsArray an array of instantiated annotations applied to this case class
* @tparam Typeclass type constructor for the typeclass being derived
* @tparam Type generic type of this parameter */
final class SealedTrait[Typeclass[_], Type](
diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala
index 00cf5ec..3cfda3d 100644
--- a/core/shared/src/main/scala/magnolia.scala
+++ b/core/shared/src/main/scala/magnolia.scala
@@ -202,7 +202,8 @@ object Magnolia {
val headParamList = {
val primaryConstructor = classType map (_.primaryConstructor)
- val optList: Option[List[c.universe.Symbol]] = primaryConstructor flatMap (_.typeSignature.paramLists.headOption)
+ val optList: Option[List[c.universe.Symbol]] =
+ primaryConstructor flatMap (_.asMethod.typeSignature.paramLists.headOption)
optList.map(_.map(_.asTerm))
}
@@ -256,10 +257,11 @@ object Magnolia {
val preAssignments = caseParams.map(_.typeclass)
- val defaults = headParamList.filterNot(_ => isValueClass) map { plist =>
+ val defaults = headParamList map { plist =>
// note: This causes the namer/typer to generate the synthetic default methods by forcing
// the typeSignature of the "default" factory method to be visited.
// It feels like it shouldn't be needed, but we'll get errors otherwise (as discovered after 6 hours debugging)
+
val companionSym = companionRef.symbol.asModule.info
val primaryFactoryMethod = companionSym.decl(TermName("apply")).alternatives.lastOption
primaryFactoryMethod.foreach(_.asMethod.typeSignature)
diff --git a/examples/shared/src/main/scala/decode.scala b/examples/shared/src/main/scala/decode.scala
index 9e91d17..539e478 100644
--- a/examples/shared/src/main/scala/decode.scala
+++ b/examples/shared/src/main/scala/decode.scala
@@ -10,10 +10,10 @@ trait Decoder[T] { def decode(str: String): T }
object Decoder {
/** decodes strings */
- implicit val string: Decoder[String] = (str: String) => str
+ implicit val string: Decoder[String] = (s: String) => s
/** decodes ints */
- implicit val int: Decoder[Int] = (str: String) => str.toInt
+ implicit val int: Decoder[Int] = _.toInt
/** binds the Magnolia macro to this derivation object */
implicit def gen[T]: Decoder[T] = macro Magnolia.gen[T]
@@ -22,7 +22,7 @@ object Decoder {
type Typeclass[T] = Decoder[T]
/** defines how new [[Decoder]]s for case classes should be constructed */
- def combine[T](ctx: CaseClass[Decoder, T]): Decoder[T] = (value: String) => {
+ def combine[T](ctx: CaseClass[Decoder, T]): Decoder[T] = value => {
val (_, values) = parse(value)
ctx.construct { param =>
param.typeclass.decode(values(param.label))
@@ -30,7 +30,7 @@ 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] = (param: String) => {
+ def dispatch[T](ctx: SealedTrait[Decoder, T]): Decoder[T] = param => {
val (name, _) = parse(param)
val subtype = ctx.subtypes.find(_.typeName.full == name).get
subtype.typeclass.decode(param)
diff --git a/examples/shared/src/main/scala/show.scala b/examples/shared/src/main/scala/show.scala
index 9afc4c9..ecf1dec 100644
--- a/examples/shared/src/main/scala/show.scala
+++ b/examples/shared/src/main/scala/show.scala
@@ -20,7 +20,7 @@ trait GenericShow[Out] {
/** creates a new [[Show]] instance by labelling and joining (with `mkString`) the result of
* showing each parameter, and prefixing it with the class name */
- def combine[T](ctx: CaseClass[Typeclass, T]): Show[Out, T] = (value: T) => {
+ def combine[T](ctx: CaseClass[Typeclass, T]): Show[Out, T] = { value =>
if (ctx.isValueClass) {
val param = ctx.parameters.head
param.typeclass.show(param.dereference(value))