Skip to content

Commit

Permalink
Merge pull request #17 from jatcwang/update_magnolia
Browse files Browse the repository at this point in the history
update magnolia to new namespace
  • Loading branch information
jatcwang authored Dec 2, 2021
2 parents 54c762d + 2777e9f commit 285f1da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ lazy val core = Project("difflicious-core", file("modules/core"))
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
if (isScala3.value) "com.softwaremill.magnolia1_3" %% "magnolia" % "1.0.0-M4"
if (isScala3.value) "com.softwaremill.magnolia1_3" %% "magnolia" % "1.0.0-M7"
// if (isScala3.value) "com.softwaremill.magnolia" %% "magnolia-core" % "2.0.0-M7-SNAPSHOT"
else "com.softwaremill.magnolia" %% "magnolia-core" % "1.0.0-M4",
else "com.softwaremill.magnolia1_2" %% "magnolia" % "1.0.0-M7",
"dev.zio" %% "izumi-reflect" % "1.1.2",
"com.lihaoyi" %% "fansi" % "0.2.14",
) ++ (
Expand Down Expand Up @@ -114,7 +114,7 @@ lazy val docs: Project = project
val orig = (ThisProject / makeMicrosite).taskValue
if (isScala3.value) Def.task({})
else Def.task(orig.value)
}.value
}.value,
)
.settings(
mdocIn := file("docs/docs"),
Expand Down
18 changes: 9 additions & 9 deletions modules/core/src/main/scala-2.13/difflicious/DifferGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import difflicious.DiffResult.MismatchTypeResult
import difflicious.differ.RecordDiffer
import difflicious.internal.EitherGetSyntax._
import difflicious.utils.TypeName.SomeTypeName
import magnolia._
import magnolia1._

import scala.collection.mutable
import scala.collection.immutable.ListMap

trait DifferGen {
type Typeclass[T] = Differ[T]

def combine[T](ctx: ReadOnlyCaseClass[Differ, T]): Differ[T] = {
def join[T](ctx: ReadOnlyCaseClass[Differ, T]): Differ[T] = {
new RecordDiffer[T](
ctx.parameters
.map { p =>
Expand Down Expand Up @@ -40,17 +40,17 @@ trait DifferGen {

override def diff(inputs: DiffInput[T]): DiffResult = inputs match {
case DiffInput.ObtainedOnly(obtained) =>
ctx.dispatch(obtained)(sub => sub.typeclass.diff(DiffInput.ObtainedOnly(sub.cast(obtained))))
ctx.split(obtained)(sub => sub.typeclass.diff(DiffInput.ObtainedOnly(sub.cast(obtained))))
case DiffInput.ExpectedOnly(expected) =>
ctx.dispatch(expected)(sub => sub.typeclass.diff(DiffInput.ExpectedOnly(sub.cast(expected))))
ctx.split(expected)(sub => sub.typeclass.diff(DiffInput.ExpectedOnly(sub.cast(expected))))
case DiffInput.Both(obtained, expected) => {
ctx.dispatch(obtained) { obtainedSubtype =>
ctx.dispatch(expected) { expectedSubtype =>
ctx.split(obtained) { obtainedSubtype =>
ctx.split(expected) { expectedSubtype =>
if (obtainedSubtype.typeName.short == expectedSubtype.typeName.short) {
obtainedSubtype.typeclass
.diff(
obtainedSubtype.cast(obtained),
expectedSubtype.cast(expected).asInstanceOf[obtainedSubtype.SType]
expectedSubtype.cast(expected).asInstanceOf[obtainedSubtype.SType],
)
} else {
MismatchTypeResult(
Expand Down Expand Up @@ -129,12 +129,12 @@ trait DifferGen {

}

def dispatch[T](ctx: SealedTrait[Differ, T]): Differ[T] =
def split[T](ctx: SealedTrait[Differ, T]): Differ[T] =
new SealedTraitDiffer[T](ctx, isIgnored = false)

def derived[T]: Differ[T] = macro Magnolia.gen[T]

private def toDiffliciousTypeName(typeName: magnolia.TypeName): SomeTypeName = {
private def toDiffliciousTypeName(typeName: magnolia1.TypeName): SomeTypeName = {
difflicious.utils.TypeName(
long = typeName.full,
short = typeName.short,
Expand Down
4 changes: 3 additions & 1 deletion modules/core/src/main/scala-3/difflicious/DifferGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait DifferGen extends Derivation[Differ]:
isIgnored = false,
typeName = toDiffliciousTypeName(ctx.typeInfo)
)

override def split[T](ctx: SealedTrait[Differ, T]): Differ[T] =
new SealedTraitDiffer(ctx, isIgnored = false)

Expand Down Expand Up @@ -70,6 +70,7 @@ trait DifferGen extends Derivation[Differ]:
subtypes = IArray(newSubtypes.toArray: _*),
annotations = ctx.annotations,
typeAnnotations = ctx.typeAnnotations,
isEnum = ctx.isEnum,
)
new SealedTraitDiffer[T](newSealedTrait, isIgnored = newIgnored)

Expand Down Expand Up @@ -99,6 +100,7 @@ trait DifferGen extends Derivation[Differ]:
subtypes = newSubtypes,
annotations = ctx.annotations,
typeAnnotations = ctx.typeAnnotations,
isEnum = ctx.isEnum,
)
new SealedTraitDiffer[T](newSealedTrait, isIgnored)
}
Expand Down

0 comments on commit 285f1da

Please sign in to comment.