Skip to content

Commit

Permalink
Use Path instead of String in TransformerCfg
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Sep 15, 2023
1 parent 5701ab6 commit 98cd5e0
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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
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,
Expand All @@ -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)
)

Expand All @@ -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[
Expand All @@ -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)
)

Expand All @@ -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)
)

Expand All @@ -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[

Check warning on line 79 in chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala#L79

Added line #L79 was not covered by tests
From,
To,
FieldRelabelled[Select[FromField, Root], Select[ToField, Root], Cfg],

Check warning on line 82 in chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala#L81-L82

Added lines #L81 - L82 were not covered by tests
Flags
]]
}.applyFromSelectors(selectorFrom, selectorTo)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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
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,
Expand All @@ -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)
)

Expand All @@ -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)
)

Expand All @@ -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)
)

Expand All @@ -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)
)

Expand All @@ -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)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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
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,
Expand All @@ -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)
)

Expand All @@ -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)
)

Expand All @@ -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)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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
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,
Expand All @@ -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)
)

Expand All @@ -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)
)

Expand All @@ -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)
)

Expand Down
Loading

0 comments on commit 98cd5e0

Please sign in to comment.