From 98cd5e0eda39c0458a7f41702bd776f8eb7eb23b Mon Sep 17 00:00:00 2001 From: Mateusz Kubuszok Date: Fri, 15 Sep 2023 12:56:47 +0200 Subject: [PATCH] Use Path instead of String in TransformerCfg --- .../compiletime/ChimneyTypesPlatform.scala | 30 +++++++------- .../PartialTransformerDefinitionMacros.scala | 18 +++++--- .../dsl/PartialTransformerIntoMacros.scala | 18 +++++--- .../dsl/TransformerDefinitionMacros.scala | 11 +++-- .../dsl/TransformerIntoMacros.scala | 11 +++-- .../compiletime/ChimneyTypesPlatform.scala | 41 +++++++++++-------- .../PartialTransformerDefinitionMacros.scala | 26 +++++++++--- .../dsl/PartialTransformerIntoMacros.scala | 16 +++++--- .../dsl/TransformerDefinitionMacros.scala | 12 ++++-- .../dsl/TransformerIntoMacros.scala | 12 ++++-- .../internal/compiletime/ChimneyTypes.scala | 12 +++--- .../transformer/Configurations.scala | 26 +++++++++--- .../internal/runtime/TransformerCfg.scala | 10 ++--- 13 files changed, 158 insertions(+), 85 deletions(-) diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala index c3a0e3a1e..2d8eca779 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala @@ -50,48 +50,48 @@ private[compiletime] trait ChimneyTypesPlatform extends ChimneyTypes { this: Chi object TransformerCfg extends TransformerCfgModule { val Empty: Type[runtime.TransformerCfg.Empty] = weakTypeTag[runtime.TransformerCfg.Empty] object FieldConst extends FieldConstModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldConst[Name, Cfg]] = weakTypeTag[runtime.TransformerCfg.FieldConst[Name, Cfg]] - def unapply[A](A: Type[A]): Option[(?<[String], ?<[runtime.TransformerCfg])] = + def unapply[A](A: Type[A]): Option[(?<[runtime.Path], ?<[runtime.TransformerCfg])] = if (A.isCtor[runtime.TransformerCfg.FieldConst[?, ?]]) - Some(A.param_<[String](0) -> A.param_<[runtime.TransformerCfg](1)) + Some(A.param_<[runtime.Path](0) -> A.param_<[runtime.TransformerCfg](1)) else scala.None } object FieldConstPartial extends FieldConstPartialModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldConstPartial[Name, Cfg]] = weakTypeTag[runtime.TransformerCfg.FieldConstPartial[Name, Cfg]] - def unapply[A](A: Type[A]): Option[(?<[String], ?<[runtime.TransformerCfg])] = + def unapply[A](A: Type[A]): Option[(?<[runtime.Path], ?<[runtime.TransformerCfg])] = if (A.isCtor[runtime.TransformerCfg.FieldConstPartial[?, ?]]) - Some(A.param_<[String](0) -> A.param_<[runtime.TransformerCfg](1)) + Some(A.param_<[runtime.Path](0) -> A.param_<[runtime.TransformerCfg](1)) else scala.None } object FieldComputed extends FieldComputedModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldComputed[Name, Cfg]] = weakTypeTag[runtime.TransformerCfg.FieldComputed[Name, Cfg]] - def unapply[A](A: Type[A]): Option[(?<[String], ?<[runtime.TransformerCfg])] = + def unapply[A](A: Type[A]): Option[(?<[runtime.Path], ?<[runtime.TransformerCfg])] = if (A.isCtor[runtime.TransformerCfg.FieldComputed[?, ?]]) - Some(A.param_<[String](0) -> A.param_<[runtime.TransformerCfg](1)) + Some(A.param_<[runtime.Path](0) -> A.param_<[runtime.TransformerCfg](1)) else scala.None } object FieldComputedPartial extends FieldComputedPartialModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldComputedPartial[Name, Cfg]] = weakTypeTag[runtime.TransformerCfg.FieldComputedPartial[Name, Cfg]] - def unapply[A](A: Type[A]): Option[(?<[String], ?<[runtime.TransformerCfg])] = + def unapply[A](A: Type[A]): Option[(?<[runtime.Path], ?<[runtime.TransformerCfg])] = if (A.isCtor[runtime.TransformerCfg.FieldComputedPartial[?, ?]]) - Some(A.param_<[String](0) -> A.param_<[runtime.TransformerCfg](1)) + Some(A.param_<[runtime.Path](0) -> A.param_<[runtime.TransformerCfg](1)) else scala.None } object FieldRelabelled extends FieldRelabelledModule { - def apply[FromName <: String: Type, ToName <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[FromName <: runtime.Path: Type, ToName <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldRelabelled[FromName, ToName, Cfg]] = weakTypeTag[runtime.TransformerCfg.FieldRelabelled[FromName, ToName, Cfg]] - def unapply[A](A: Type[A]): Option[(?<[String], ?<[String], ?<[runtime.TransformerCfg])] = + def unapply[A](A: Type[A]): Option[(?<[runtime.Path], ?<[runtime.Path], ?<[runtime.TransformerCfg])] = if (A.isCtor[runtime.TransformerCfg.FieldRelabelled[?, ?, ?]]) - Some((A.param_<[String](0), A.param_<[String](1), A.param_<[runtime.TransformerCfg](2))) + Some((A.param_<[runtime.Path](0), A.param_<[runtime.Path](1), A.param_<[runtime.TransformerCfg](2))) else scala.None } object CoproductInstance extends CoproductInstanceModule { diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala index db5162032..ebc7efa1d 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala @@ -2,6 +2,7 @@ package io.scalaland.chimney.internal.compiletime.dsl import io.scalaland.chimney.dsl.PartialTransformerDefinition import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import scala.annotation.unused @@ -9,7 +10,7 @@ import scala.reflect.macros.whitebox class PartialTransformerDefinitionMacros(val c: whitebox.Context) extends utils.DslMacroUtils { - import c.universe.* + import c.universe.{Select as _, *} def withFieldConstImpl[ From: WeakTypeTag, @@ -21,7 +22,7 @@ class PartialTransformerDefinitionMacros(val c: whitebox.Context) extends utils. .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerDefinition[From, To, FieldConst[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerDefinition[From, To, FieldConst[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -35,7 +36,7 @@ class PartialTransformerDefinitionMacros(val c: whitebox.Context) extends utils. .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerDefinition[From, To, FieldConstPartial[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerDefinition[From, To, FieldConstPartial[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) def withFieldComputedImpl[ @@ -48,7 +49,7 @@ class PartialTransformerDefinitionMacros(val c: whitebox.Context) extends utils. .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerDefinition[From, To, FieldComputed[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerDefinition[From, To, FieldComputed[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -62,7 +63,7 @@ class PartialTransformerDefinitionMacros(val c: whitebox.Context) extends utils. .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerDefinition[From, To, FieldComputedPartial[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerDefinition[From, To, FieldComputedPartial[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -75,7 +76,12 @@ class PartialTransformerDefinitionMacros(val c: whitebox.Context) extends utils. .asInstanceOfExpr( new ApplyFieldNameTypes { def apply[FromField <: String: WeakTypeTag, ToField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerDefinition[From, To, FieldRelabelled[FromField, ToField, Cfg], Flags]] + weakTypeTag[PartialTransformerDefinition[ + From, + To, + FieldRelabelled[Select[FromField, Root], Select[ToField, Root], Cfg], + Flags + ]] }.applyFromSelectors(selectorFrom, selectorTo) ) diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala index c395a378f..ade1e27d8 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala @@ -2,6 +2,7 @@ package io.scalaland.chimney.internal.compiletime.dsl import io.scalaland.chimney.dsl.PartialTransformerInto import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import scala.annotation.unused @@ -9,7 +10,7 @@ import scala.reflect.macros.whitebox class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMacroUtils { - import c.universe.* + import c.universe.{Select as _, *} def withFieldConstImpl[ From: WeakTypeTag, @@ -21,7 +22,7 @@ class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMac .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerInto[From, To, FieldConst[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerInto[From, To, FieldConst[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -35,7 +36,7 @@ class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMac .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerInto[From, To, FieldConstPartial[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerInto[From, To, FieldConstPartial[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -49,7 +50,7 @@ class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMac .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerInto[From, To, FieldComputed[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerInto[From, To, FieldComputed[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -63,7 +64,7 @@ class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMac .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerInto[From, To, FieldComputedPartial[FromField, Cfg], Flags]] + weakTypeTag[PartialTransformerInto[From, To, FieldComputedPartial[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -76,7 +77,12 @@ class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMac .asInstanceOfExpr( new ApplyFieldNameTypes { def apply[FromField <: String: WeakTypeTag, ToField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[PartialTransformerInto[From, To, FieldRelabelled[FromField, ToField, Cfg], Flags]] + weakTypeTag[PartialTransformerInto[ + From, + To, + FieldRelabelled[Select[FromField, Root], Select[ToField, Root], Cfg], + Flags + ]] }.applyFromSelectors(selectorFrom, selectorTo) ) diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala index 11b36f30c..fc12b032b 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala @@ -2,6 +2,7 @@ package io.scalaland.chimney.internal.compiletime.dsl import io.scalaland.chimney.dsl.TransformerDefinition import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import scala.annotation.unused @@ -9,7 +10,7 @@ import scala.reflect.macros.whitebox class TransformerDefinitionMacros(val c: whitebox.Context) extends utils.DslMacroUtils { - import c.universe.* + import c.universe.{Select as _, *} def withFieldConstImpl[ From: WeakTypeTag, @@ -21,7 +22,7 @@ class TransformerDefinitionMacros(val c: whitebox.Context) extends utils.DslMacr .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[TransformerDefinition[From, To, FieldConst[FromField, Cfg], Flags]] + weakTypeTag[TransformerDefinition[From, To, FieldConst[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -35,7 +36,7 @@ class TransformerDefinitionMacros(val c: whitebox.Context) extends utils.DslMacr .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[TransformerDefinition[From, To, FieldComputed[FromField, Cfg], Flags]] + weakTypeTag[TransformerDefinition[From, To, FieldComputed[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -48,7 +49,9 @@ class TransformerDefinitionMacros(val c: whitebox.Context) extends utils.DslMacr .asInstanceOfExpr( new ApplyFieldNameTypes { def apply[FromField <: String: WeakTypeTag, ToField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[TransformerDefinition[From, To, FieldRelabelled[FromField, ToField, Cfg], Flags]] + weakTypeTag[ + TransformerDefinition[From, To, FieldRelabelled[Select[FromField, Root], Select[ToField, Root], Cfg], Flags] + ] }.applyFromSelectors(selectorFrom, selectorTo) ) diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala index a1e7c78b8..7d430c72c 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala @@ -2,6 +2,7 @@ package io.scalaland.chimney.internal.compiletime.dsl import io.scalaland.chimney.dsl.TransformerInto import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import scala.annotation.unused @@ -9,7 +10,7 @@ import scala.reflect.macros.whitebox class TransformerIntoMacros(val c: whitebox.Context) extends utils.DslMacroUtils { - import c.universe.* + import c.universe.{Select as _, *} def withFieldConstImpl[ From: WeakTypeTag, @@ -21,7 +22,7 @@ class TransformerIntoMacros(val c: whitebox.Context) extends utils.DslMacroUtils .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[TransformerInto[From, To, FieldConst[FromField, Cfg], Flags]] + weakTypeTag[TransformerInto[From, To, FieldConst[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -35,7 +36,7 @@ class TransformerIntoMacros(val c: whitebox.Context) extends utils.DslMacroUtils .asInstanceOfExpr( new ApplyFieldNameType { def apply[FromField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[TransformerInto[From, To, FieldComputed[FromField, Cfg], Flags]] + weakTypeTag[TransformerInto[From, To, FieldComputed[Select[FromField, Root], Cfg], Flags]] }.applyFromSelector(selector) ) @@ -48,7 +49,9 @@ class TransformerIntoMacros(val c: whitebox.Context) extends utils.DslMacroUtils .asInstanceOfExpr( new ApplyFieldNameTypes { def apply[FromField <: String: WeakTypeTag, ToField <: String: WeakTypeTag]: c.WeakTypeTag[?] = - weakTypeTag[TransformerInto[From, To, FieldRelabelled[FromField, ToField, Cfg], Flags]] + weakTypeTag[ + TransformerInto[From, To, FieldRelabelled[Select[FromField, Root], Select[ToField, Root], Cfg], Flags] + ] }.applyFromSelectors(selectorFrom, selectorTo) ) diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala index 2267c859b..4c467f7da 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyTypesPlatform.scala @@ -47,49 +47,56 @@ private[compiletime] trait ChimneyTypesPlatform extends ChimneyTypes { this: Chi object TransformerCfg extends TransformerCfgModule { val Empty: Type[runtime.TransformerCfg.Empty] = quoted.Type.of[runtime.TransformerCfg.Empty] object FieldConst extends FieldConstModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldConst[Name, Cfg]] = quoted.Type.of[runtime.TransformerCfg.FieldConst[Name, Cfg]] - def unapply[A](tpe: Type[A]): Option[(?<[String], ?<[runtime.TransformerCfg])] = tpe match + def unapply[A](tpe: Type[A]): Option[(?<[runtime.Path], ?<[runtime.TransformerCfg])] = tpe match case '[runtime.TransformerCfg.FieldConst[name, c]] => - Some((Type[name].as_?<[String], Type[c].as_?<[runtime.TransformerCfg])) + Some((Type[name].as_?<[runtime.Path], Type[c].as_?<[runtime.TransformerCfg])) case _ => scala.None } object FieldConstPartial extends FieldConstPartialModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldConstPartial[Name, Cfg]] = quoted.Type.of[runtime.TransformerCfg.FieldConstPartial[Name, Cfg]] - def unapply[A](tpe: Type[A]): Option[(?<[String], ?<[runtime.TransformerCfg])] = tpe match + def unapply[A](tpe: Type[A]): Option[(?<[runtime.Path], ?<[runtime.TransformerCfg])] = tpe match case '[runtime.TransformerCfg.FieldConstPartial[name, c]] => - Some((Type[name].as_>?<[Nothing, String], Type[c].as_>?<[Nothing, runtime.TransformerCfg])) + Some((Type[name].as_>?<[Nothing, runtime.Path], Type[c].as_>?<[Nothing, runtime.TransformerCfg])) case _ => scala.None } object FieldComputed extends FieldComputedModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldComputed[Name, Cfg]] = quoted.Type.of[runtime.TransformerCfg.FieldComputed[Name, Cfg]] - def unapply[A](tpe: Type[A]): Option[(?<[String], ?<[runtime.TransformerCfg])] = tpe match + def unapply[A](tpe: Type[A]): Option[(?<[runtime.Path], ?<[runtime.TransformerCfg])] = tpe match case '[runtime.TransformerCfg.FieldComputed[name, c]] => - Some((Type[name].as_?<[String], Type[c].as_?<[runtime.TransformerCfg])) + Some((Type[name].as_?<[runtime.Path], Type[c].as_?<[runtime.TransformerCfg])) case _ => scala.None } object FieldComputedPartial extends FieldComputedPartialModule { - def apply[Name <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[Name <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldComputedPartial[Name, Cfg]] = quoted.Type.of[runtime.TransformerCfg.FieldComputedPartial[Name, Cfg]] - def unapply[A](tpe: Type[A]): Option[(Nothing >?< String, Nothing >?< runtime.TransformerCfg)] = tpe match + def unapply[A](tpe: Type[A]): Option[(Nothing >?< runtime.Path, Nothing >?< runtime.TransformerCfg)] = tpe match case '[runtime.TransformerCfg.FieldComputedPartial[name, c]] => - Some((Type[name].as_?<[String], Type[c].as_?<[runtime.TransformerCfg])) + Some((Type[name].as_?<[runtime.Path], Type[c].as_?<[runtime.TransformerCfg])) case _ => scala.None } object FieldRelabelled extends FieldRelabelledModule { - def apply[FromName <: String: Type, ToName <: String: Type, Cfg <: runtime.TransformerCfg: Type] + def apply[FromName <: runtime.Path: Type, ToName <: runtime.Path: Type, Cfg <: runtime.TransformerCfg: Type] : Type[runtime.TransformerCfg.FieldRelabelled[FromName, ToName, Cfg]] = quoted.Type.of[runtime.TransformerCfg.FieldRelabelled[FromName, ToName, Cfg]] - def unapply[A](tpe: Type[A]): Option[(?<[String], ?<[String], ?<[runtime.TransformerCfg])] = tpe match - case '[runtime.TransformerCfg.FieldRelabelled[fromName, toName, c]] => - Some((Type[fromName].as_?<[String], Type[toName].as_?<[String], Type[c].as_?<[runtime.TransformerCfg])) - case _ => scala.None + def unapply[A](tpe: Type[A]): Option[(?<[runtime.Path], ?<[runtime.Path], ?<[runtime.TransformerCfg])] = + tpe match + case '[runtime.TransformerCfg.FieldRelabelled[fromName, toName, c]] => + Some( + ( + Type[fromName].as_?<[runtime.Path], + Type[toName].as_?<[runtime.Path], + Type[c].as_?<[runtime.TransformerCfg] + ) + ) + case _ => scala.None } object CoproductInstance extends CoproductInstanceModule { def apply[InstType: Type, TargetType: Type, Cfg <: runtime.TransformerCfg: Type] diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala index a69cd0da9..e60af7b86 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala @@ -4,6 +4,7 @@ import io.scalaland.chimney.PartialTransformer import io.scalaland.chimney.dsl.* import io.scalaland.chimney.internal.compiletime.derivation.transformer.TransformerMacros import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags, WithRuntimeDataStore} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import io.scalaland.chimney.partial @@ -29,7 +30,7 @@ object PartialTransformerDefinitionMacros { '{ WithRuntimeDataStore .update($td, $value) - .asInstanceOf[PartialTransformerDefinition[From, To, FieldConst[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerDefinition[From, To, FieldConst[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -52,7 +53,12 @@ object PartialTransformerDefinitionMacros { '{ WithRuntimeDataStore .update($td, $value) - .asInstanceOf[PartialTransformerDefinition[From, To, FieldConstPartial[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerDefinition[ + From, + To, + FieldConstPartial[Select[fieldNameT, Root], Cfg], + Flags + ]] } } } @@ -75,7 +81,7 @@ object PartialTransformerDefinitionMacros { '{ WithRuntimeDataStore .update($td, $f) - .asInstanceOf[PartialTransformerDefinition[From, To, FieldComputed[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerDefinition[From, To, FieldComputed[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -98,7 +104,12 @@ object PartialTransformerDefinitionMacros { '{ WithRuntimeDataStore .update($td, $f) - .asInstanceOf[PartialTransformerDefinition[From, To, FieldComputedPartial[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerDefinition[ + From, + To, + FieldComputedPartial[Select[fieldNameT, Root], Cfg], + Flags + ]] } } } @@ -120,7 +131,12 @@ object PartialTransformerDefinitionMacros { case ('[FieldNameUtils.StringBounded[fieldNameFromT]], '[FieldNameUtils.StringBounded[fieldNameToT]]) => '{ $td.asInstanceOf[ - PartialTransformerDefinition[From, To, FieldRelabelled[fieldNameFromT, fieldNameToT, Cfg], Flags] + PartialTransformerDefinition[ + From, + To, + FieldRelabelled[Select[fieldNameFromT, Root], Select[fieldNameToT, Root], Cfg], + Flags + ] ] } } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala index b377813ef..c249e032b 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerIntoMacros.scala @@ -4,6 +4,7 @@ import io.scalaland.chimney.PartialTransformer import io.scalaland.chimney.dsl.* import io.scalaland.chimney.internal.compiletime.derivation.transformer.TransformerMacros import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags, WithRuntimeDataStore} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import io.scalaland.chimney.partial @@ -29,7 +30,7 @@ object PartialTransformerIntoMacros { '{ WithRuntimeDataStore .update($ti, $value) - .asInstanceOf[PartialTransformerInto[From, To, FieldConst[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerInto[From, To, FieldConst[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -52,7 +53,7 @@ object PartialTransformerIntoMacros { '{ WithRuntimeDataStore .update($ti, $value) - .asInstanceOf[PartialTransformerInto[From, To, FieldConstPartial[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerInto[From, To, FieldConstPartial[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -75,7 +76,7 @@ object PartialTransformerIntoMacros { '{ WithRuntimeDataStore .update($ti, $f) - .asInstanceOf[PartialTransformerInto[From, To, FieldComputed[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerInto[From, To, FieldComputed[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -98,7 +99,7 @@ object PartialTransformerIntoMacros { '{ WithRuntimeDataStore .update($ti, $f) - .asInstanceOf[PartialTransformerInto[From, To, FieldComputedPartial[fieldNameT, Cfg], Flags]] + .asInstanceOf[PartialTransformerInto[From, To, FieldComputedPartial[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -119,7 +120,12 @@ object PartialTransformerIntoMacros { (FieldNameUtils.strLiteralType(fieldNameFrom).asType, FieldNameUtils.strLiteralType(fieldNameTo).asType) match { case ('[FieldNameUtils.StringBounded[fieldNameFromT]], '[FieldNameUtils.StringBounded[fieldNameToT]]) => '{ - $ti.asInstanceOf[PartialTransformerInto[From, To, FieldRelabelled[fieldNameFromT, fieldNameToT, Cfg], Flags]] + $ti.asInstanceOf[PartialTransformerInto[ + From, + To, + FieldRelabelled[Select[fieldNameFromT, Root], Select[fieldNameToT, Root], Cfg], + Flags + ]] } } } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala index 4d4ec94a6..23f4e420c 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerDefinitionMacros.scala @@ -4,6 +4,7 @@ import io.scalaland.chimney.Transformer import io.scalaland.chimney.dsl.* import io.scalaland.chimney.internal.compiletime.derivation.transformer.TransformerMacros import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags, WithRuntimeDataStore} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import scala.quoted.* @@ -28,7 +29,7 @@ object TransformerDefinitionMacros { '{ WithRuntimeDataStore .update($td, $value) - .asInstanceOf[TransformerDefinition[From, To, FieldConst[fieldNameT, Cfg], Flags]] + .asInstanceOf[TransformerDefinition[From, To, FieldConst[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -51,7 +52,7 @@ object TransformerDefinitionMacros { '{ WithRuntimeDataStore .update($td, $f) - .asInstanceOf[TransformerDefinition[From, To, FieldComputed[fieldNameT, Cfg], Flags]] + .asInstanceOf[TransformerDefinition[From, To, FieldComputed[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -72,7 +73,12 @@ object TransformerDefinitionMacros { (FieldNameUtils.strLiteralType(fieldNameFrom).asType, FieldNameUtils.strLiteralType(fieldNameTo).asType) match { case ('[FieldNameUtils.StringBounded[fieldNameFromT]], '[FieldNameUtils.StringBounded[fieldNameToT]]) => '{ - $td.asInstanceOf[TransformerDefinition[From, To, FieldRelabelled[fieldNameFromT, fieldNameToT, Cfg], Flags]] + $td.asInstanceOf[TransformerDefinition[ + From, + To, + FieldRelabelled[Select[fieldNameFromT, Root], Select[fieldNameToT, Root], Cfg], + Flags + ]] } } } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala index eeb61da13..f28ded218 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/TransformerIntoMacros.scala @@ -5,6 +5,7 @@ import io.scalaland.chimney.internal.* import io.scalaland.chimney.dsl.* import io.scalaland.chimney.internal.compiletime.derivation.transformer.TransformerMacros import io.scalaland.chimney.internal.runtime.{TransformerCfg, TransformerFlags, WithRuntimeDataStore} +import io.scalaland.chimney.internal.runtime.Path.* import io.scalaland.chimney.internal.runtime.TransformerCfg.* import scala.quoted.* @@ -29,7 +30,7 @@ object TransformerIntoMacros { '{ WithRuntimeDataStore .update($ti, $value) - .asInstanceOf[TransformerInto[From, To, FieldConst[fieldNameT, Cfg], Flags]] + .asInstanceOf[TransformerInto[From, To, FieldConst[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -52,7 +53,7 @@ object TransformerIntoMacros { '{ WithRuntimeDataStore .update($ti, $f) - .asInstanceOf[TransformerInto[From, To, FieldComputed[fieldNameT, Cfg], Flags]] + .asInstanceOf[TransformerInto[From, To, FieldComputed[Select[fieldNameT, Root], Cfg], Flags]] } } } @@ -73,7 +74,12 @@ object TransformerIntoMacros { (FieldNameUtils.strLiteralType(fieldNameFrom).asType, FieldNameUtils.strLiteralType(fieldNameTo).asType) match { case ('[FieldNameUtils.StringBounded[fieldNameFromT]], '[FieldNameUtils.StringBounded[fieldNameToT]]) => '{ - $ti.asInstanceOf[TransformerInto[From, To, FieldRelabelled[fieldNameFromT, fieldNameToT, Cfg], Flags]] + $ti.asInstanceOf[TransformerInto[ + From, + To, + FieldRelabelled[Select[fieldNameFromT, Root], Select[fieldNameToT, Root], Cfg], + Flags + ]] } } } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/ChimneyTypes.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/ChimneyTypes.scala index be59a5ebb..26249780d 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/ChimneyTypes.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/ChimneyTypes.scala @@ -43,7 +43,7 @@ private[compiletime] trait ChimneyTypes { this: ChimneyDefinitions => val FieldConst: FieldConstModule trait FieldConstModule extends Type.Ctor2UpperBounded[ - String, + runtime.Path, runtime.TransformerCfg, runtime.TransformerCfg.FieldConst ] { this: FieldConst.type => } @@ -51,7 +51,7 @@ private[compiletime] trait ChimneyTypes { this: ChimneyDefinitions => val FieldConstPartial: FieldConstPartialModule trait FieldConstPartialModule extends Type.Ctor2UpperBounded[ - String, + runtime.Path, runtime.TransformerCfg, runtime.TransformerCfg.FieldConstPartial ] { this: FieldConstPartial.type => } @@ -59,7 +59,7 @@ private[compiletime] trait ChimneyTypes { this: ChimneyDefinitions => val FieldComputed: FieldComputedModule trait FieldComputedModule extends Type.Ctor2UpperBounded[ - String, + runtime.Path, runtime.TransformerCfg, runtime.TransformerCfg.FieldComputed ] { this: FieldComputed.type => } @@ -67,7 +67,7 @@ private[compiletime] trait ChimneyTypes { this: ChimneyDefinitions => val FieldComputedPartial: FieldComputedPartialModule trait FieldComputedPartialModule extends Type.Ctor2UpperBounded[ - String, + runtime.Path, runtime.TransformerCfg, runtime.TransformerCfg.FieldComputedPartial ] { this: FieldComputedPartial.type => } @@ -75,8 +75,8 @@ private[compiletime] trait ChimneyTypes { this: ChimneyDefinitions => val FieldRelabelled: FieldRelabelledModule trait FieldRelabelledModule extends Type.Ctor3UpperBounded[ - String, - String, + runtime.Path, + runtime.Path, runtime.TransformerCfg, runtime.TransformerCfg.FieldRelabelled ] { this: FieldRelabelled.type => } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala index 00f00a111..ce70e4960 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala @@ -190,36 +190,36 @@ private[compiletime] trait Configurations { this: Derivation => import fieldName.Underlying as FieldName, cfg.Underlying as Cfg2 extractTransformerConfig[Cfg2](1 + runtimeDataIdx) .addFieldOverride( - Type[FieldName].extractStringSingleton, + extractPath[FieldName], RuntimeFieldOverride.Const(runtimeDataIdx) ) case ChimneyType.TransformerCfg.FieldConstPartial(fieldName, cfg) => import fieldName.Underlying as FieldName, cfg.Underlying as Cfg2 extractTransformerConfig[Cfg2](1 + runtimeDataIdx) .addFieldOverride( - Type[FieldName].extractStringSingleton, + extractPath[FieldName], RuntimeFieldOverride.ConstPartial(runtimeDataIdx) ) case ChimneyType.TransformerCfg.FieldComputed(fieldName, cfg) => import fieldName.Underlying as FieldName, cfg.Underlying as Cfg2 extractTransformerConfig[Cfg2](1 + runtimeDataIdx) .addFieldOverride( - Type[FieldName].extractStringSingleton, + extractPath[FieldName], RuntimeFieldOverride.Computed(runtimeDataIdx) ) case ChimneyType.TransformerCfg.FieldComputedPartial(fieldName, cfg) => import fieldName.Underlying as FieldName, cfg.Underlying as Cfg2 extractTransformerConfig[Cfg2](1 + runtimeDataIdx) .addFieldOverride( - Type[FieldName].extractStringSingleton, + extractPath[FieldName], RuntimeFieldOverride.ComputedPartial(runtimeDataIdx) ) case ChimneyType.TransformerCfg.FieldRelabelled(fromName, toName, cfg) => import fromName.Underlying as FromName, toName.Underlying as ToName, cfg.Underlying as Cfg2 extractTransformerConfig[Cfg2](runtimeDataIdx) .addFieldOverride( - Type[ToName].extractStringSingleton, - RuntimeFieldOverride.RenamedFrom(Type[FromName].extractStringSingleton) + extractPath[ToName], + RuntimeFieldOverride.RenamedFrom(extractPath[FromName]) ) case ChimneyType.TransformerCfg.CoproductInstance(instance, target, cfg) => import instance.Underlying as Instance, target.Underlying as Target, cfg.Underlying as Cfg2 @@ -238,7 +238,21 @@ private[compiletime] trait Configurations { this: Derivation => RuntimeCoproductOverride.CoproductInstancePartial(runtimeDataIdx) ) case _ => + // $COVERAGE-OFF$ reportError(s"Bad internal transformer config type shape ${Type.prettyPrint[Cfg]}!!") + // $COVERAGE-ON$ + } + + // currently we aren't supporting nested paths + // This (suppressed) error is a case when compiler is simply wrong :) + @scala.annotation.nowarn("msg=Unreachable case") + private def extractPath[Field <: runtime.Path: Type]: String = Type[Field] match { + case ChimneyType.Path.Select(fieldName, path) if path.value =:= ChimneyType.Path.Root => + fieldName.value.extractStringSingleton + case _ => + // $COVERAGE-OFF$ + reportError(s"Nested paths ${Type.prettyPrint[Field]} are not supported!!") + // $COVERAGE-ON$ } } } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/TransformerCfg.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/TransformerCfg.scala index 07985891d..089db3d94 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/TransformerCfg.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/TransformerCfg.scala @@ -3,11 +3,11 @@ package io.scalaland.chimney.internal.runtime sealed abstract class TransformerCfg object TransformerCfg { final class Empty extends TransformerCfg - final class FieldConst[Name <: String, Cfg <: TransformerCfg] extends TransformerCfg - final class FieldConstPartial[Name <: String, Cfg <: TransformerCfg] extends TransformerCfg - final class FieldComputed[Name <: String, Cfg <: TransformerCfg] extends TransformerCfg - final class FieldComputedPartial[Name <: String, Cfg <: TransformerCfg] extends TransformerCfg - final class FieldRelabelled[FromName <: String, ToName <: String, Cfg <: TransformerCfg] extends TransformerCfg + final class FieldConst[Field <: Path, Cfg <: TransformerCfg] extends TransformerCfg + final class FieldConstPartial[Field <: Path, Cfg <: TransformerCfg] extends TransformerCfg + final class FieldComputed[Field <: Path, Cfg <: TransformerCfg] extends TransformerCfg + final class FieldComputedPartial[Field <: Path, Cfg <: TransformerCfg] extends TransformerCfg + final class FieldRelabelled[FromField <: Path, ToField <: Path, Cfg <: TransformerCfg] extends TransformerCfg final class CoproductInstance[InstType, TargetType, Cfg <: TransformerCfg] extends TransformerCfg final class CoproductInstancePartial[InstType, TargetType, Cfg <: TransformerCfg] extends TransformerCfg }