Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ f489f367a5914a646ac6942b9f550cc7e6371166

# Scala Steward: Reformat with scalafmt 3.10.5
0987b604b5059d8d29d3ca53bc1626f6a7a000da

# Scala Steward: Reformat with scalafmt 3.11.1
1152c4e933353d25788092ee6c815c10606bcf55
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.11.0
version = 3.11.1
project.git = true
project.includePaths."+" = ["glob:**/docs/**.md"]
maxColumn = 120
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ private[cats] trait CatsDataImplicitsCompat extends CatsDataImplicitsLowPriority
def partialFactory: Factory[A, partial.Result[NonEmptyLazyList[A]]] =
new FactoryCompat[A, partial.Result[NonEmptyLazyList[A]]] {
def newBuilder: mutable.Builder[A, partial.Result[NonEmptyLazyList[A]]] =
new FactoryCompat.Builder[A, partial.Result[NonEmptyLazyList[A]]] {
private val impl = mutable.ListBuffer.empty[A]
def clear(): Unit = impl.clear()
new FactoryCompatBuilder[A, partial.Result[NonEmptyLazyList[A]], mutable.ListBuffer[A]](
mutable.ListBuffer.empty[A]
) {
def result(): partial.Result[NonEmptyLazyList[A]] =
partial.Result.fromOption(NonEmptyLazyList.fromSeq(impl.result()))
def addOne(elem: A): this.type = { impl += elem; this }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.scalaland.chimney.partial

import scala.collection.compat.Factory
import scala.collection.mutable
import scala.collection.mutable.ListBuffer

/** @since 1.0.0 */
trait CatsDataImplicits extends CatsDataImplicitsCompat {
Expand Down Expand Up @@ -63,12 +64,11 @@ trait CatsDataImplicits extends CatsDataImplicitsCompat {
implicit def catsChainIsTotallyBuildIterable[A]: TotallyBuildIterable[Chain[A], A] =
new TotallyBuildIterable[Chain[A], A] {
def totalFactory: Factory[A, Chain[A]] = new FactoryCompat[A, Chain[A]] {
def newBuilder: mutable.Builder[A, Chain[A]] = new FactoryCompat.Builder[A, Chain[A]] {
private var impl = Chain.empty[A]
def clear(): Unit = impl = Chain.empty[A]
def result(): Chain[A] = impl
def addOne(elem: A): this.type = { impl = impl.append(elem); this }
}
def newBuilder: mutable.Builder[A, Chain[A]] =
new FactoryCompatVarBuilder[A, Chain[A], Chain[A]](() => Chain.empty[A]) {
def result(): Chain[A] = impl
def addOne(elem: A): this.type = { impl = impl.append(elem); this }
}
}
def iterator(collection: Chain[A]): Iterator[A] = collection.iterator
}
Expand All @@ -79,9 +79,7 @@ trait CatsDataImplicits extends CatsDataImplicitsCompat {
def partialFactory: Factory[A, partial.Result[NonEmptyChain[A]]] =
new FactoryCompat[A, partial.Result[NonEmptyChain[A]]] {
def newBuilder: mutable.Builder[A, partial.Result[NonEmptyChain[A]]] =
new FactoryCompat.Builder[A, partial.Result[NonEmptyChain[A]]] {
private var impl = Chain.empty[A]
def clear(): Unit = impl = Chain.empty[A]
new FactoryCompatVarBuilder[A, partial.Result[NonEmptyChain[A]], Chain[A]](() => Chain.empty[A]) {
def result(): partial.Result[NonEmptyChain[A]] = partial.Result.fromOption(NonEmptyChain.fromChain(impl))
def addOne(elem: A): this.type = { impl = impl.append(elem); this }
}
Expand All @@ -95,9 +93,9 @@ trait CatsDataImplicits extends CatsDataImplicitsCompat {
def partialFactory: Factory[A, partial.Result[NonEmptyList[A]]] =
new FactoryCompat[A, partial.Result[NonEmptyList[A]]] {
def newBuilder: mutable.Builder[A, partial.Result[NonEmptyList[A]]] =
new FactoryCompat.Builder[A, partial.Result[NonEmptyList[A]]] {
private val impl = List.newBuilder[A]
def clear(): Unit = impl.clear()
new FactoryCompatBuilder[A, partial.Result[NonEmptyList[A]], mutable.Builder[A, List[A]]](
List.newBuilder[A]
) {
def result(): partial.Result[NonEmptyList[A]] =
partial.Result.fromOption(NonEmptyList.fromList(impl.result()))
def addOne(elem: A): this.type = { impl += elem; this }
Expand All @@ -112,9 +110,11 @@ trait CatsDataImplicits extends CatsDataImplicitsCompat {
def partialFactory: Factory[(K, V), partial.Result[NonEmptyMap[K, V]]] =
new FactoryCompat[(K, V), partial.Result[NonEmptyMap[K, V]]] {
def newBuilder: mutable.Builder[(K, V), partial.Result[NonEmptyMap[K, V]]] =
new FactoryCompat.Builder[(K, V), partial.Result[NonEmptyMap[K, V]]] {
private val impl = scala.collection.immutable.SortedMap.newBuilder[K, V]
def clear(): Unit = impl.clear()
new FactoryCompatBuilder[
(K, V),
partial.Result[NonEmptyMap[K, V]],
mutable.Builder[(K, V), scala.collection.immutable.SortedMap[K, V]]
](scala.collection.immutable.SortedMap.newBuilder[K, V]) {
def result(): partial.Result[NonEmptyMap[K, V]] =
partial.Result.fromOption(NonEmptyMap.fromMap(impl.result()))
def addOne(elem: (K, V)): this.type = { impl += elem; this }
Expand All @@ -129,9 +129,9 @@ trait CatsDataImplicits extends CatsDataImplicitsCompat {
def partialFactory: Factory[A, partial.Result[NonEmptySeq[A]]] =
new FactoryCompat[A, partial.Result[NonEmptySeq[A]]] {
def newBuilder: mutable.Builder[A, partial.Result[NonEmptySeq[A]]] =
new FactoryCompat.Builder[A, partial.Result[NonEmptySeq[A]]] {
private val impl = mutable.ListBuffer.empty[A]
def clear(): Unit = impl.clear()
new FactoryCompatBuilder[A, partial.Result[NonEmptySeq[A]], ListBuffer[A]](
mutable.ListBuffer.empty[A]
) {
def result(): partial.Result[NonEmptySeq[A]] =
partial.Result.fromOption(NonEmptySeq.fromSeq(impl.result()))
def addOne(elem: A): this.type = { impl += elem; this }
Expand All @@ -146,9 +146,11 @@ trait CatsDataImplicits extends CatsDataImplicitsCompat {
def partialFactory: Factory[A, partial.Result[NonEmptySet[A]]] =
new FactoryCompat[A, partial.Result[NonEmptySet[A]]] {
def newBuilder: mutable.Builder[A, partial.Result[NonEmptySet[A]]] =
new FactoryCompat.Builder[A, partial.Result[NonEmptySet[A]]] {
private val impl = scala.collection.immutable.SortedSet.newBuilder[A]
def clear(): Unit = impl.clear()
new FactoryCompatBuilder[
A,
partial.Result[NonEmptySet[A]],
mutable.Builder[A, scala.collection.immutable.SortedSet[A]]
](scala.collection.immutable.SortedSet.newBuilder[A]) {
def result(): partial.Result[NonEmptySet[A]] =
partial.Result.fromOption(NonEmptySet.fromSet(impl.result()))
def addOne(elem: A): this.type = { impl += elem; this }
Expand All @@ -163,9 +165,9 @@ trait CatsDataImplicits extends CatsDataImplicitsCompat {
def partialFactory: Factory[A, partial.Result[NonEmptyVector[A]]] =
new FactoryCompat[A, partial.Result[NonEmptyVector[A]]] {
def newBuilder: mutable.Builder[A, partial.Result[NonEmptyVector[A]]] =
new FactoryCompat.Builder[A, partial.Result[NonEmptyVector[A]]] {
private val impl = Vector.newBuilder[A]
def clear(): Unit = impl.clear()
new FactoryCompatBuilder[A, partial.Result[NonEmptyVector[A]], mutable.Builder[A, Vector[A]]](
Vector.newBuilder[A]
) {
def result(): partial.Result[NonEmptyVector[A]] =
partial.Result.fromOption(NonEmptyVector.fromVector(impl.result()))
def addOne(elem: A): this.type = { impl += elem; this }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ trait JavaCollectionsImplicits {
implicit def javaIteratorIsTotallyBuildIterable[Item]: TotallyBuildIterable[ju.Iterator[Item], Item] =
new TotallyBuildIterable[ju.Iterator[Item], Item] {
def totalFactory: Factory[Item, ju.Iterator[Item]] = new FactoryCompat[Item, ju.Iterator[Item]] {
def newBuilder: mutable.Builder[Item, ju.Iterator[Item]] = new FactoryCompat.Builder[Item, ju.Iterator[Item]] {
private val impl = new ju.ArrayList[Item]()
def clear(): Unit = impl.clear()
def result(): ju.Iterator[Item] = impl.iterator()
def addOne(elem: Item): this.type = { impl.add(elem); this }
}
def newBuilder: mutable.Builder[Item, ju.Iterator[Item]] =
new FactoryCompatJavaCollectionBuilder[Item, ju.Iterator[Item], Item, ju.Collection[Item]](
new ju.ArrayList[Item]()
) {
def result(): ju.Iterator[Item] = impl.iterator()
def addOne(elem: Item): this.type = { impl.add(elem); this }
}
}
def iterator(collection: ju.Iterator[Item]): Iterator[Item] = collection.asScala
}
Expand All @@ -46,12 +47,12 @@ trait JavaCollectionsImplicits {
new TotallyBuildIterable[ju.Enumeration[Item], Item] {
def totalFactory: Factory[Item, ju.Enumeration[Item]] = new FactoryCompat[Item, ju.Enumeration[Item]] {
def newBuilder: mutable.Builder[Item, ju.Enumeration[Item]] =
new FactoryCompat.Builder[Item, ju.Enumeration[Item]] {
private val impl = new ju.ArrayList[Item]()
def clear(): Unit = impl.clear()
new FactoryCompatJavaCollectionBuilder[Item, ju.Enumeration[Item], Item, ju.Collection[Item]](
new ju.ArrayList[Item]()
) {
def result(): ju.Enumeration[Item] = new ju.Enumeration[Item] {
private val it = impl.iterator()
def hasMoreElements: Boolean = it.hasNext()
def hasMoreElements: Boolean = it.hasNext
def nextElement(): Item = it.next()
}
override def addOne(elem: Item): this.type = { impl.add(elem); this }
Expand Down Expand Up @@ -253,9 +254,9 @@ trait JavaCollectionsImplicits {
new TotallyBuildIterable[ju.stream.Stream[Item], Item] {
def totalFactory: Factory[Item, ju.stream.Stream[Item]] = new FactoryCompat[Item, ju.stream.Stream[Item]] {
def newBuilder: mutable.Builder[Item, ju.stream.Stream[Item]] =
new FactoryCompat.Builder[Item, ju.stream.Stream[Item]] {
private var impl = ju.stream.Stream.builder[Item]()
def clear(): Unit = impl = ju.stream.Stream.builder[Item]()
new FactoryCompatVarBuilder[Item, ju.stream.Stream[Item], ju.stream.Stream.Builder[Item]](
ju.stream.Stream.builder[Item]
) {
def result(): ju.stream.Stream[Item] = impl.build()
def addOne(elem: Item): this.type = { impl.add(elem); this }
}
Expand All @@ -268,9 +269,9 @@ trait JavaCollectionsImplicits {
new TotallyBuildIterable[ju.stream.IntStream, Int] {
def totalFactory: Factory[Int, ju.stream.IntStream] = new FactoryCompat[Int, ju.stream.IntStream] {
def newBuilder: mutable.Builder[Int, ju.stream.IntStream] =
new FactoryCompat.Builder[Int, ju.stream.IntStream] {
private var impl = ju.stream.IntStream.builder()
def clear(): Unit = impl = ju.stream.IntStream.builder()
new FactoryCompatVarBuilder[Int, ju.stream.IntStream, ju.stream.IntStream.Builder](
ju.stream.IntStream.builder
) {
def result(): ju.stream.IntStream = impl.build()
def addOne(elem: Int): this.type = { impl.add(elem); this }
}
Expand All @@ -284,9 +285,9 @@ trait JavaCollectionsImplicits {
new TotallyBuildIterable[ju.stream.LongStream, Long] {
def totalFactory: Factory[Long, ju.stream.LongStream] = new FactoryCompat[Long, ju.stream.LongStream] {
def newBuilder: mutable.Builder[Long, ju.stream.LongStream] =
new FactoryCompat.Builder[Long, ju.stream.LongStream] {
private var impl = ju.stream.LongStream.builder()
def clear(): Unit = impl = ju.stream.LongStream.builder()
new FactoryCompatVarBuilder[Long, ju.stream.LongStream, ju.stream.LongStream.Builder](
ju.stream.LongStream.builder
) {
def result(): ju.stream.LongStream = impl.build()
def addOne(elem: Long): this.type = { impl.add(elem); this }
}
Expand All @@ -300,9 +301,10 @@ trait JavaCollectionsImplicits {
new TotallyBuildIterable[ju.stream.DoubleStream, Double] {
def totalFactory: Factory[Double, ju.stream.DoubleStream] = new FactoryCompat[Double, ju.stream.DoubleStream] {
def newBuilder: mutable.Builder[Double, ju.stream.DoubleStream] =
new FactoryCompat.Builder[Double, ju.stream.DoubleStream] {
private var impl = ju.stream.DoubleStream.builder()
def clear(): Unit = impl = ju.stream.DoubleStream.builder()
new FactoryCompatVarBuilder[Double, ju.stream.DoubleStream, ju.stream.DoubleStream.Builder](
ju.stream.DoubleStream.builder
) {

def result(): ju.stream.DoubleStream = impl.build()
def addOne(elem: Double): this.type = { impl.add(elem); this }
}
Expand All @@ -319,9 +321,7 @@ trait JavaCollectionsImplicits {
new TotallyBuildIterable[CC, Item] {
def totalFactory: Factory[Item, CC] = new FactoryCompat[Item, CC] {
def newBuilder: mutable.Builder[Item, CC] =
new FactoryCompat.Builder[Item, CC] {
private val impl = empty
def clear(): Unit = impl.clear()
new FactoryCompatJavaCollectionBuilder[Item, CC, Item, CC](empty) {
def result(): CC = impl
def addOne(elem: Item): this.type = { impl.add(elem); this }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class PartialTransformerJavaCollectionsConversionsSpec extends ChimneySpec {

input.transformIntoPartial[ju.Map[Int, Int]].asOption.get.asScala ==> outputUnstable
input.transformIntoPartial[ju.AbstractMap[Int, Int]].asOption.get.asScala ==> outputUnstable
input.transformIntoPartial[ju.WeakHashMap[Int, Int]].asOption.get.asScala ==> outputUnstable
input.transformIntoPartial[ju.IdentityHashMap[Int, Int]].asOption.get.asScala ==> outputUnstable
input.transformIntoPartial[ju.SortedMap[Int, Int]].asOption.get.asScala.toList ==> outputSorted
input.transformIntoPartial[ju.NavigableMap[Int, Int]].asOption.get.asScala.toList ==> outputSorted
input.transformIntoPartial[ju.HashMap[Int, Int]].asOption.get.asScala ==> outputUnstable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@ final class PartialTransformerDefinition[From, To, Overrides <: TransformerOverr

/** Scope overrides to apply to all derivations matching `[FromMatch, ToMatch]`.
*
* When chimney recursively derives transformations for nested types, any `forAll`-scoped overrides whose
* `FromMatch` and `ToMatch` are supertypes of the current derivation pair will be injected.
* When chimney recursively derives transformations for nested types, any `forAll`-scoped overrides whose `FromMatch`
* and `ToMatch` are supertypes of the current derivation pair will be injected.
*
* @tparam FromMatch
* source type to match (subtypes of this will also match)
Expand All @@ -838,8 +838,7 @@ final class PartialTransformerDefinition[From, To, Overrides <: TransformerOverr
*
* @since 1.10.0
*/
def forAll[FromMatch, ToMatch]
: PartialTransformerDefinitionForAll[From, To, Overrides, Flags, FromMatch, ToMatch] =
def forAll[FromMatch, ToMatch]: PartialTransformerDefinitionForAll[From, To, Overrides, Flags, FromMatch, ToMatch] =
new PartialTransformerDefinitionForAll[From, To, Overrides, Flags, FromMatch, ToMatch](runtimeData)

/** Build Partial Transformer using current configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ final class TransformerDefinition[From, To, Overrides <: TransformerOverrides, F

/** Scope overrides to apply to all derivations matching `[FromMatch, ToMatch]`.
*
* When chimney recursively derives transformations for nested types, any `forAll`-scoped overrides whose
* `FromMatch` and `ToMatch` are supertypes of the current derivation pair will be injected.
* When chimney recursively derives transformations for nested types, any `forAll`-scoped overrides whose `FromMatch`
* and `ToMatch` are supertypes of the current derivation pair will be injected.
*
* @tparam FromMatch
* source type to match (subtypes of this will also match)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ private[compiletime] trait ChimneyTypesPlatform extends ChimneyTypes { this: Chi
}
}
object ForAll extends ForAllModule {
def unapply[A](A: Type[A]): Option[(??, ??, ?<[runtime.TransformerOverrides], ?<[runtime.TransformerOverrides])] =
def unapply[A](
A: Type[A]
): Option[(??, ??, ?<[runtime.TransformerOverrides], ?<[runtime.TransformerOverrides])] =
A.asCtor[runtime.TransformerOverrides.ForAll[?, ?, ?, ?]].map { A0 =>
(
A0.param(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,7 @@ class TransformerIntoForAllMacros(val c: whitebox.Context) extends utils.DslMacr
def apply[ToPath <: Path: WeakTypeTag]: c.WeakTypeTag[?] =
weakTypeTag[ForAll[FromMatch, ToMatch, Const[ToPath, Empty], Overrides]]
}.applyFromSelector(selector)
q"""
{
val updatedTd = _root_.io.scalaland.chimney.internal.runtime.WithRuntimeDataStore
.update(${c.prefix}.td, $value)
.asInstanceOf[_root_.io.scalaland.chimney.dsl.TransformerDefinition[
${weakTypeOf[From]},
${weakTypeOf[To]},
$overridesType,
${weakTypeOf[Flags]}
]]
new _root_.io.scalaland.chimney.dsl.TransformerInto[
${weakTypeOf[From]},
${weakTypeOf[To]},
$overridesType,
${weakTypeOf[Flags]}
](
${c.prefix}.source,
updatedTd
)
}
"""
withFieldImpl(value, overridesType)
}

def withFieldComputedImpl[
Expand All @@ -87,10 +67,21 @@ class TransformerIntoForAllMacros(val c: whitebox.Context) extends utils.DslMacr
def apply[ToPath <: Path: WeakTypeTag]: c.WeakTypeTag[?] =
weakTypeTag[ForAll[FromMatch, ToMatch, Computed[ToPath, Empty], Overrides]]
}.applyFromSelector(selector)
withFieldImpl(f, overridesType)
}

private def withFieldImpl[
ToMatch: WeakTypeTag,
FromMatch: WeakTypeTag,
Flags <: TransformerFlags: WeakTypeTag,
Overrides <: TransformerOverrides: WeakTypeTag,
To: WeakTypeTag,
From: WeakTypeTag
](value: Tree, overridesType: WeakTypeTag[?]) =
q"""
{
val updatedTd = _root_.io.scalaland.chimney.internal.runtime.WithRuntimeDataStore
.update(${c.prefix}.td, $f)
.update(${c.prefix}.td, $value)
.asInstanceOf[_root_.io.scalaland.chimney.dsl.TransformerDefinition[
${weakTypeOf[From]},
${weakTypeOf[To]},
Expand All @@ -108,5 +99,4 @@ class TransformerIntoForAllMacros(val c: whitebox.Context) extends utils.DslMacr
)
}
"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@ final class PartialTransformerDefinition[From, To, Overrides <: TransformerOverr

/** Scope overrides to apply to all derivations matching `[FromMatch, ToMatch]`.
*
* When chimney recursively derives transformations for nested types, any `forAll`-scoped overrides whose
* `FromMatch` and `ToMatch` are supertypes of the current derivation pair will be injected.
* When chimney recursively derives transformations for nested types, any `forAll`-scoped overrides whose `FromMatch`
* and `ToMatch` are supertypes of the current derivation pair will be injected.
*
* @tparam FromMatch
* source type to match (subtypes of this will also match)
Expand Down
Loading