diff --git a/.scalafmt.conf b/.scalafmt.conf index 677e6293b..fb9d17bea 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -9,13 +9,15 @@ fileOverride { align.preset = some -rewrite.rules = [Imports, SortModifiers] +rewrite.rules = [Imports, RedundantBraces, SortModifiers] rewrite.imports.sort = scalastyle +rewrite.redundantBraces.stringInterpolation = true rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = false -docstrings.style = keep +docstrings.blankFirstLine = no +docstrings.style = SpaceAsterisk docstrings.wrap = no newlines.sometimesBeforeColonInMethodReturnType = true diff --git a/chimney-cats/src/main/scala/io/scalaland/chimney/cats/CatsPartialTransformerImplicits.scala b/chimney-cats/src/main/scala/io/scalaland/chimney/cats/CatsPartialTransformerImplicits.scala index ffbf3b799..37d02d1e2 100644 --- a/chimney-cats/src/main/scala/io/scalaland/chimney/cats/CatsPartialTransformerImplicits.scala +++ b/chimney-cats/src/main/scala/io/scalaland/chimney/cats/CatsPartialTransformerImplicits.scala @@ -11,9 +11,8 @@ import language.implicitConversions trait CatsPartialTransformerImplicits extends CatsPartialTransformerLowPriorityImplicits1 { /** @since 0.7.0 */ - implicit final val semigroupPartialResultErrors: Semigroup[partial.Result.Errors] = { + implicit final val semigroupPartialResultErrors: Semigroup[partial.Result.Errors] = Semigroup.instance(partial.Result.Errors.merge) - } /** @since 0.7.0 */ implicit final val applicativePartialResult: Applicative[partial.Result] = diff --git a/chimney-cats/src/test/scala/io/scalaland/chimney/cats/utils/ValidatedUtils.scala b/chimney-cats/src/test/scala/io/scalaland/chimney/cats/utils/ValidatedUtils.scala index b9750a51a..d498768ca 100644 --- a/chimney-cats/src/test/scala/io/scalaland/chimney/cats/utils/ValidatedUtils.scala +++ b/chimney-cats/src/test/scala/io/scalaland/chimney/cats/utils/ValidatedUtils.scala @@ -18,12 +18,11 @@ object ValidatedUtils { implicit class OptionOps[T](private val opt: Option[T]) extends AnyVal { - def toValidated[EE[_]: InvariantMonoidal](err: => String): Validated[EE[String], T] = { + def toValidated[EE[_]: InvariantMonoidal](err: => String): Validated[EE[String], T] = opt match { case Some(value) => Validated.Valid(value) case None => Validated.Invalid(InvariantMonoidal[EE].point(err)) } - } def toValidatedNec(err: => String): ValidatedNec[String, T] = toValidated[NonEmptyChain](err)(implicitly) @@ -31,12 +30,11 @@ object ValidatedUtils { def toValidatedNel(err: => String): ValidatedNel[String, T] = toValidated[NonEmptyList](err)(implicitly) - def toIor[EE[_]: InvariantMonoidal](err: => String): Ior[EE[String], T] = { + def toIor[EE[_]: InvariantMonoidal](err: => String): Ior[EE[String], T] = opt match { case Some(value) => Ior.Right(value) case None => Ior.Left(InvariantMonoidal[EE].point(err)) } - } def toIorNec(err: => String): IorNec[String, T] = toIor[NonEmptyChain](err)(implicitly) @@ -53,8 +51,7 @@ object ValidatedUtils { implicit class ValidatedOps[+E, +A](private val validated: Validated[E, A]) extends AnyVal { - def getValid: A = { + def getValid: A = validated.valueOr(_ => throw new NoSuchElementException) - } } } diff --git a/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ExprsPlatform.scala b/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ExprsPlatform.scala index 946d64a2a..52f4239b4 100644 --- a/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ExprsPlatform.scala +++ b/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/ExprsPlatform.scala @@ -25,7 +25,7 @@ private[compiletime] trait ExprsPlatform extends Exprs { this: DefinitionsPlatfo object Array extends ArrayModule { def apply[A: Type](args: Expr[A]*): Expr[Array[A]] = - c.Expr[Array[A]](q"_root_.scala.Array[${Type[A]}](..${args})") + c.Expr[Array[A]](q"_root_.scala.Array[${Type[A]}](..$args)") def map[A: Type, B: Type](array: Expr[Array[A]])(fExpr: Expr[A => B]): Expr[Array[B]] = if (isScala212) @@ -128,7 +128,7 @@ private[compiletime] trait ExprsPlatform extends Exprs { this: DefinitionsPlatfo def eq[A: Type, B: Type](a: Expr[A], b: Expr[B]): Expr[Boolean] = c.Expr[Boolean](q"$a == $b") - def asInstanceOf[A: Type, B: Type](expr: Expr[A]): Expr[B] = c.Expr[B](q"${expr}.asInstanceOf[${Type[B]}]") + def asInstanceOf[A: Type, B: Type](expr: Expr[A]): Expr[B] = c.Expr[B](q"$expr.asInstanceOf[${Type[B]}]") def upcast[A: Type, B: Type](expr: Expr[A]): Expr[B] = { val wideningChecked = expr.widenExpr[B] diff --git a/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala b/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala index 121e2627b..393a21009 100644 --- a/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala +++ b/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala @@ -51,12 +51,12 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo // unknown case out => assertionFailed( - s"Constructor of ${Type.prettyPrint(fromUntyped[Any](tpe))} has unrecognized/unsupported format of type: ${out}" + s"Constructor of ${Type.prettyPrint(fromUntyped[Any](tpe))} has unrecognized/unsupported format of type: $out" ) } /** Applies type arguments from supertype to subtype if there are any */ - def subtypeTypeOf[A: Type](subtype: Symbol): ?<[A] = { + def subtypeTypeOf[A: Type](subtype: Symbol): ?<[A] = subtype.primaryConstructor.paramSymss match { // subtype takes type parameters case typeParamSymbols :: _ if typeParamSymbols.exists(_.isType) => @@ -75,7 +75,6 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo case _ => fromUntyped[A](subtype.typeRef).as_?<[A] } - } } val Nothing: Type[Nothing] = quoted.Type.of[Nothing] diff --git a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Existentials.scala b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Existentials.scala index ed8b0fba7..5627a9c35 100644 --- a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Existentials.scala +++ b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Existentials.scala @@ -3,11 +3,11 @@ package io.scalaland.chimney.internal.compiletime private[compiletime] trait Existentials { this: Types with Exprs => /** Represents value with some existential type and Type using the same existential. - * - * Since Scala 3 removed a lot of cases for existential types we cannot just use Type[?] in shared code. - * Additionally, we might need to have something to prove that our Type[?] is has the same ? as some Value[?]. - * For that, this utility would be useful. - */ + * + * Since Scala 3 removed a lot of cases for existential types we cannot just use Type[?] in shared code. + * Additionally, we might need to have something to prove that our Type[?] is has the same ? as some Value[?]. + * For that, this utility would be useful. + */ final protected type Existential[F[_]] = Existential.Bounded[Nothing, Any, F] protected object Existential { diff --git a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/ExprPromises.scala b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/ExprPromises.scala index d99642e81..57647576e 100644 --- a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/ExprPromises.scala +++ b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/ExprPromises.scala @@ -6,16 +6,16 @@ private[compiletime] trait ExprPromises { this: Definitions => protected type ExprPromiseName /** Allow us to use `Expr[A]` before we would either: know how we would initiate it, or: what the final shape of - * a whole expression would be. - * - * In situations like `'{ val a = sth; ${ useA('{ a }) } } ` you know both how `a` would be created as well as - * the shape of the final tree. In cases when you would e.g. use expression in some context-dependent derivation - * which could return `Either[Expr[B], Expr[F[B]]`, ExprPromise allows you to calculate that result and THEN decide - * how to turn it into final Expr value. - * - * @tparam From type of the promised expression - * @tparam A type of the current result we created using Expr[From] - */ + * a whole expression would be. + * + * In situations like `'{ val a = sth; ${ useA('{ a }) } } ` you know both how `a` would be created as well as + * the shape of the final tree. In cases when you would e.g. use expression in some context-dependent derivation + * which could return `Either[Expr[B], Expr[F[B]]`, ExprPromise allows you to calculate that result and THEN decide + * how to turn it into final Expr value. + * + * @tparam From type of the promised expression + * @tparam A type of the current result we created using Expr[From] + */ final protected class ExprPromise[From: Type, A](private val usage: A, private val fromName: ExprPromiseName) { def map[B](f: A => B): ExprPromise[From, B] = new ExprPromise(f(usage), fromName) @@ -80,12 +80,12 @@ private[compiletime] trait ExprPromises { this: Definitions => protected trait ExprPromiseModule { this: ExprPromise.type => /** Creates the expression promise. - * - * @param nameGenerationStrategy to avoid accidental name clashing, we are using fresh name generator which - * assures us that the name would be unique, we are only choosing the prefix - * @param usageHint if we'll fulfil promise as val/lazy val/var it let us decide as which - * @tparam From type of promised expression - */ + * + * @param nameGenerationStrategy to avoid accidental name clashing, we are using fresh name generator which + * assures us that the name would be unique, we are only choosing the prefix + * @param usageHint if we'll fulfil promise as val/lazy val/var it let us decide as which + * @tparam From type of promised expression + */ final def promise[From: Type]( nameGenerationStrategy: NameGenerationStrategy, usageHint: UsageHint = UsageHint.None @@ -135,9 +135,9 @@ private[compiletime] trait ExprPromises { this: Definitions => } /** When we decide that promised expression would be used as val/lazy val/var/def, we receive this wrapper around - * the results, which would ensure that: initialization of a definition would happen before its use, you can only use - * the definition inside its scope. - */ + * the results, which would ensure that: initialization of a definition would happen before its use, you can only use + * the definition inside its scope. + */ final protected class PrependDefinitionsTo[A]( private val usage: A, private val defns: Vector[(ExprPromiseName, ExistentialExpr, PrependDefinitionsTo.DefnType)] @@ -212,9 +212,9 @@ private[compiletime] trait ExprPromises { this: Definitions => } /** When we decide that expression would be crated in patter-match binding, we would receive this wrapper around - * the results, which would ensure that definition is only used inside the scope and allow combining several cases - * into a single pattern matching. - */ + * the results, which would ensure that definition is only used inside the scope and allow combining several cases + * into a single pattern matching. + */ final protected class PatternMatchCase[To]( val someFrom: ??, val usage: Expr[To], diff --git a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala index dc3af836a..3218316cb 100644 --- a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala +++ b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala @@ -53,7 +53,8 @@ trait ProductTypes { this: Definitions => final type Arguments = Map[String, ExistentialExpr] /** Let us obtain a list of primary constructor's parameters as well as setter parameters, as well as a method - * of taking all computed arguments and turning it into constructed value. */ + * of taking all computed arguments and turning it into constructed value. + */ final case class Constructor[To](parameters: Parameters, constructor: Arguments => Expr[To]) object Constructor { def unapply[To](To: Type[To]): Option[(Parameters, Arguments => Expr[To])] = diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala b/chimney/src/main/scala-2/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala index faeb47b50..8da2f8788 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala @@ -7,14 +7,14 @@ import scala.language.experimental.macros private[chimney] trait PartialTransformerCompanionPlatform { this: PartialTransformer.type => /** Provides [[io.scalaland.chimney.PartialTransformer]] derived with the default settings. - * - * When transformation can't be derived, it results with compilation error. - * - * @tparam From type of input value - * @tparam To type of output value - * @return [[io.scalaland.chimney.PartialTransformer]] type class definition - * @since 0.7.0 - */ + * + * When transformation can't be derived, it results with compilation error. + * + * @tparam From type of input value + * @tparam To type of output value + * @return [[io.scalaland.chimney.PartialTransformer]] type class definition + * @since 0.7.0 + */ def derive[From, To]: PartialTransformer[From, To] = macro TransformerMacros.derivePartialTransformerWithDefaults[From, To] } diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/PatcherCompanionPlatform.scala b/chimney/src/main/scala-2/io/scalaland/chimney/PatcherCompanionPlatform.scala index 6de6dbef2..4c7e27f32 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/PatcherCompanionPlatform.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/PatcherCompanionPlatform.scala @@ -7,13 +7,13 @@ import scala.language.experimental.macros private[chimney] trait PatcherCompanionPlatform { this: Patcher.type => /** Provides implicit [[io.scalaland.chimney.Patcher]] instance - * for arbitrary types. - * - * @tparam A type of object to apply patch to - * @tparam Patch type of patch object - * @return [[io.scalaland.chimney.Patcher]] type class instance - * @since 0.2.0 - */ + * for arbitrary types. + * + * @tparam A type of object to apply patch to + * @tparam Patch type of patch object + * @return [[io.scalaland.chimney.Patcher]] type class instance + * @since 0.2.0 + */ implicit def derive[A, Patch]: Patcher[A, Patch] = macro PatcherMacros.derivePatcherImpl[A, Patch] } diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/TransformerCompanionPlatform.scala b/chimney/src/main/scala-2/io/scalaland/chimney/TransformerCompanionPlatform.scala index 5e1a8dab1..8cacce3ce 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/TransformerCompanionPlatform.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/TransformerCompanionPlatform.scala @@ -7,14 +7,14 @@ import scala.language.experimental.macros private[chimney] trait TransformerCompanionPlatform { this: Transformer.type => /** Provides [[io.scalaland.chimney.Transformer]] derived with the default settings. - * - * When transformation can't be derived, it results with compilation error. - * - * @tparam From type of input value - * @tparam To type of output value - * @return [[io.scalaland.chimney.Transformer]] type class instance - * @since 0.2.0 - */ + * + * When transformation can't be derived, it results with compilation error. + * + * @tparam From type of input value + * @tparam To type of output value + * @return [[io.scalaland.chimney.Transformer]] type class instance + * @since 0.2.0 + */ def derive[From, To]: Transformer[From, To] = macro TransformerMacros.deriveTotalTransformerWithDefaults[From, To] diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala b/chimney/src/main/scala-2/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala index ea6ec981f..ede68dfd6 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala @@ -35,7 +35,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ def withFieldConst[T, U](selector: To => T, value: U)(implicit @@ -54,7 +54,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ def withFieldConstPartial[T, U](selector: To => T, value: partial.Result[U])(implicit @@ -73,7 +73,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ def withFieldComputed[T, U](selector: To => T, f: From => U)(implicit @@ -92,7 +92,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ def withFieldComputedPartial[T, U]( @@ -112,7 +112,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selectorFrom source field in `From`, defined like `_.originalName` * @param selectorTo target field in `To`, defined like `_.newName` * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ def withFieldRenamed[T, U]( diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/dsl/TransformerDefinition.scala b/chimney/src/main/scala-2/io/scalaland/chimney/dsl/TransformerDefinition.scala index d46093a49..96c681385 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/dsl/TransformerDefinition.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/dsl/TransformerDefinition.scala @@ -43,7 +43,7 @@ final class TransformerDefinition[From, To, Cfg <: TransformerCfg, Flags <: Tran * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.TransformerDefinition]] - * + * * @since 0.4.0 */ def withFieldConst[T, U](selector: To => T, value: U)(implicit diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala b/chimney/src/main/scala-3/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala index 4efbdb162..182364976 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/PartialTransformerCompanionPlatform.scala @@ -5,14 +5,14 @@ import io.scalaland.chimney.internal.compiletime.derivation.transformer.Transfor private[chimney] trait PartialTransformerCompanionPlatform { this: PartialTransformer.type => /** Provides [[io.scalaland.chimney.PartialTransformer]] derived with the default settings. - * - * When transformation can't be derived, it results with compilation error. - * - * @tparam From type of input value - * @tparam To type of output value - * @return [[io.scalaland.chimney.PartialTransformer]] type class definition - * @since 0.8.0 - */ + * + * When transformation can't be derived, it results with compilation error. + * + * @tparam From type of input value + * @tparam To type of output value + * @return [[io.scalaland.chimney.PartialTransformer]] type class definition + * @since 0.8.0 + */ inline def derive[From, To]: PartialTransformer[From, To] = ${ TransformerMacros.derivePartialTransformerWithDefaults[From, To] } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/PatcherCompanionPlatform.scala b/chimney/src/main/scala-3/io/scalaland/chimney/PatcherCompanionPlatform.scala index 6582cf16e..d159a6fc9 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/PatcherCompanionPlatform.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/PatcherCompanionPlatform.scala @@ -5,12 +5,12 @@ import io.scalaland.chimney.internal.compiletime.derivation.patcher.PatcherMacro private[chimney] trait PatcherCompanionPlatform { this: Patcher.type => /** Provides implicit [[io.scalaland.chimney.Patcher]] instance - * for arbitrary types. - * - * @tparam A type of object to apply patch to - * @tparam Patch type of patch object - * @return [[io.scalaland.chimney.Patcher]] type class instance - * @since 0.8.0 - */ + * for arbitrary types. + * + * @tparam A type of object to apply patch to + * @tparam Patch type of patch object + * @return [[io.scalaland.chimney.Patcher]] type class instance + * @since 0.8.0 + */ implicit inline def derive[A, Patch]: Patcher[A, Patch] = ${ PatcherMacros.derivePatcher[A, Patch] } } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/TransformerCompanionPlatform.scala b/chimney/src/main/scala-3/io/scalaland/chimney/TransformerCompanionPlatform.scala index ee671a265..45b0a0dd9 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/TransformerCompanionPlatform.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/TransformerCompanionPlatform.scala @@ -5,14 +5,14 @@ import io.scalaland.chimney.internal.compiletime.derivation.transformer.Transfor private[chimney] trait TransformerCompanionPlatform { this: Transformer.type => /** Provides [[io.scalaland.chimney.Transformer]] derived with the default settings. - * - * When transformation can't be derived, it results with compilation error. - * - * @tparam From type of input value - * @tparam To type of output value - * @return [[io.scalaland.chimney.Transformer]] type class instance - * @since 0.8.0 - */ + * + * When transformation can't be derived, it results with compilation error. + * + * @tparam From type of input value + * @tparam To type of output value + * @return [[io.scalaland.chimney.Transformer]] type class instance + * @since 0.8.0 + */ inline def derive[From, To]: Transformer[From, To] = ${ TransformerMacros.deriveTotalTransformerWithDefaults[From, To] } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala index c476677ed..0a725b55d 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerDefinition.scala @@ -29,7 +29,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ transparent inline def withFieldConst[T, U]( @@ -48,7 +48,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ transparent inline def withFieldConstPartial[T, U]( @@ -67,7 +67,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ transparent inline def withFieldComputed[T, U]( @@ -86,7 +86,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ transparent inline def withFieldComputedPartial[T, U]( @@ -105,7 +105,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @param selectorFrom source field in `From`, defined like `_.originalName` * @param selectorTo target field in `To`, defined like `_.newName` * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ transparent inline def withFieldRenamed[T, U]( @@ -125,7 +125,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * @tparam Inst type of coproduct instance * @param f function to calculate values of components that cannot be mapped automatically * @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]] - * + * * @since 0.7.0 */ transparent inline def withCoproductInstance[Inst]( @@ -159,7 +159,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags * When transformation can't be derived, it results with compilation error. * * @return [[io.scalaland.chimney.PartialTransformer]] type class instance - * + * * @since 0.7.0 */ inline def buildTransformer[ImplicitScopeFlags <: TransformerFlags](using diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerInto.scala b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerInto.scala index d655c9e65..5156411fc 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerInto.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PartialTransformerInto.scala @@ -33,7 +33,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerInto]] - * + * * @since 0.7.0 */ transparent inline def withFieldConst[T, U]( @@ -52,7 +52,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerInto]] - * + * * @since 0.7.0 */ transparent inline def withFieldConstPartial[T, U]( @@ -71,7 +71,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerInto]] - * + * * @since 0.7.0 */ transparent inline def withFieldComputed[T, U]( @@ -90,7 +90,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.PartialTransformerInto]] - * + * * @since 0.7.0 */ transparent inline def withFieldComputedPartial[T, U]( @@ -109,7 +109,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * @param selectorFrom source field in `From`, defined like `_.originalName` * @param selectorTo target field in `To`, defined like `_.newName` * @return [[io.scalaland.chimney.dsl.PartialTransformerInto]] - * + * * @since 0.7.0 */ transparent inline def withFieldRenamed[T, U]( @@ -129,7 +129,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * @tparam Inst type of coproduct instance * @param f function to calculate values of components that cannot be mapped automatically * @return [[io.scalaland.chimney.dsl.PartialTransformerInto]] - * + * * @since 0.7.0 */ transparent inline def withCoproductInstance[Inst]( @@ -148,7 +148,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * @tparam Inst type of coproduct instance * @param f function to calculate values of components that cannot be mapped automatically * @return [[io.scalaland.chimney.dsl.PartialTransformerInto]] - * + * * @since 0.7.0 */ transparent inline def withCoproductInstancePartial[Inst]( @@ -163,7 +163,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * When transformation can't be derived, it results with compilation error. * * @return partial transformation result of type `partial.Result[To]` - * + * * @since 0.7.0 */ inline def transform[ImplicitScopeFlags <: TransformerFlags](using @@ -180,7 +180,7 @@ final class PartialTransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Tra * When transformation can't be derived, it results with compilation error. * * @return partial transformation result of type `partial.Result[To]` - * + * * @since 0.7.0 */ inline def transformFailFast[ImplicitScopeFlags <: TransformerFlags](using diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PatcherUsing.scala b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PatcherUsing.scala index 812c2c062..2f2abf698 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PatcherUsing.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/PatcherUsing.scala @@ -26,7 +26,7 @@ final class PatcherUsing[A, Patch, Cfg <: PatcherCfg](val obj: A, val objPatch: * * @see [[https://scalalandio.github.io/chimney/patchers/options-handling.html]] for more details * @return [[io.scalaland.chimney.dsl.PatcherUsing]] - * + * * @since 0.4.0 */ def ignoreNoneInPatch: PatcherUsing[A, Patch, IgnoreNoneInPatch[Cfg]] = @@ -42,7 +42,7 @@ final class PatcherUsing[A, Patch, Cfg <: PatcherCfg](val obj: A, val objPatch: * * @see [[https://scalalandio.github.io/chimney/patchers/redundant-fields.html]] for more details * @return [[io.scalaland.chimney.dsl.PatcherUsing]] - * + * * @since 0.4.0 */ def ignoreRedundantPatcherFields: PatcherUsing[A, Patch, IgnoreRedundantPatcherFields[Cfg]] = @@ -60,7 +60,7 @@ final class PatcherUsing[A, Patch, Cfg <: PatcherCfg](val obj: A, val objPatch: /** Applies configured patching in-place * * @return patched value - * + * * @since 0.4.0 */ inline def patch: A = ${ PatcherMacros.derivePatcherResult[A, Patch, Cfg]('obj, 'objPatch) } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerDefinition.scala b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerDefinition.scala index 1afbefdfb..467be70bc 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerDefinition.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerDefinition.scala @@ -42,7 +42,7 @@ final class TransformerDefinition[From, To, Cfg <: TransformerCfg, Flags <: Tran * @param selector target field in `To`, defined like `_.name` * @param value constant value to use for the target field * @return [[io.scalaland.chimney.dsl.TransformerDefinition]] - * + * * @since 0.4.0 */ transparent inline def withFieldConst[T, U]( @@ -61,7 +61,7 @@ final class TransformerDefinition[From, To, Cfg <: TransformerCfg, Flags <: Tran * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.TransformerDefinition]] - * + * * @since 0.4.0 */ transparent inline def withFieldComputed[T, U]( @@ -80,7 +80,7 @@ final class TransformerDefinition[From, To, Cfg <: TransformerCfg, Flags <: Tran * @param selectorFrom source field in `From`, defined like `_.originalName` * @param selectorTo target field in `To`, defined like `_.newName` * @return [[io.scalaland.chimney.dsl.TransformerDefinition]] - * + * * @since 0.4.0 */ transparent inline def withFieldRenamed[T, U]( @@ -100,7 +100,7 @@ final class TransformerDefinition[From, To, Cfg <: TransformerCfg, Flags <: Tran * @tparam Inst type of coproduct instance * @param f function to calculate values of components that cannot be mapped automatically * @return [[io.scalaland.chimney.dsl.TransformerDefinition]] - * + * * @since 0.4.0 */ transparent inline def withCoproductInstance[Inst]( @@ -114,7 +114,7 @@ final class TransformerDefinition[From, To, Cfg <: TransformerCfg, Flags <: Tran * When transformation can't be derived, it results with compilation error. * * @return [[io.scalaland.chimney.Transformer]] type class instance - * + * * @since 0.4.0 */ inline def buildTransformer[ImplicitScopeFlags <: TransformerFlags](using diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerInto.scala b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerInto.scala index 218b3f6c6..f2e02b4d2 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerInto.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/TransformerInto.scala @@ -39,7 +39,7 @@ final class TransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Transforme * * @see [[https://scalalandio.github.io/chimney/transformers/customizing-transformers.html#providing-missing-values]] for more details * @return [[io.scalaland.chimney.dsl.TransformerInto]] - * + * * @since 0.1.5 */ transparent inline def withFieldConst[T, U]( @@ -58,7 +58,7 @@ final class TransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Transforme * @param selector target field in `To`, defined like `_.name` * @param f function used to compute value of the target field * @return [[io.scalaland.chimney.dsl.TransformerInto]] - * + * * @since 0.1.5 */ transparent inline def withFieldComputed[T, U]( @@ -77,7 +77,7 @@ final class TransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Transforme * @param selectorFrom source field in `From`, defined like `_.originalName` * @param selectorTo target field in `To`, defined like `_.newName` * @return [[io.scalaland.chimney.dsl.TransformerInto]] - * + * * @since 0.1.5 */ transparent inline def withFieldRenamed[T, U]( @@ -96,7 +96,7 @@ final class TransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Transforme * @see [[https://scalalandio.github.io/chimney/transformers/customizing-transformers.html#transforming-coproducts]] for more details * @tparam Inst type of coproduct instance@param f function to calculate values of components that cannot be mapped automatically * @return [[io.scalaland.chimney.dsl.TransformerInto]] - * + * * @since 0.1.2 */ transparent inline def withCoproductInstance[Inst]( @@ -111,7 +111,7 @@ final class TransformerInto[From, To, Cfg <: TransformerCfg, Flags <: Transforme * When transformation can't be derived, it results with compilation error. * * @return transformed value of type `To` - * + * * @since 0.1.0 */ inline def transform[ImplicitScopeFlags <: TransformerFlags](using diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/extensions.scala b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/extensions.scala index c99e52740..7f91884c6 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/dsl/extensions.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/dsl/extensions.scala @@ -11,7 +11,7 @@ import scala.util.Try * * @tparam From type of source value * @param source wrapped source value - * + * * @since 0.4.0 */ extension [From](source: From) { @@ -20,7 +20,7 @@ extension [From](source: From) { * * @tparam To target type * @return [[io.scalaland.chimney.dsl.TransformerInto]] - * + * * @since 0.1.0 */ def into[To]: TransformerInto[From, To, TransformerCfg.Empty, TransformerFlags.Default] = @@ -147,11 +147,11 @@ extension [T](obj: T) { extension [T](option: Option[T]) { /** Converts Option to Result, using EmptyValue error if None. - * - * @return successful result if [[scala.Some]], failed result with EmptyValue error if [[None]] - * - * @since 0.7.0 - */ + * + * @return successful result if [[scala.Some]], failed result with EmptyValue error if [[None]] + * + * @since 0.7.0 + */ def toPartialResult: partial.Result[T] = partial.Result.fromOption(option) diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyExprsPlatform.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyExprsPlatform.scala index b2551ed8b..01eb49ac0 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyExprsPlatform.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/ChimneyExprsPlatform.scala @@ -140,9 +140,8 @@ private[compiletime] trait ChimneyExprsPlatform extends ChimneyExprs { this: Chi def extractAt( runtimeDataStore: Expr[TransformerDefinitionCommons.RuntimeDataStore], index: Int - ): Expr[Any] = { + ): Expr[Any] = '{ ${ runtimeDataStore }.apply(${ quoted.Expr(index) }) } - } } object Patcher extends PatcherModule { diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/FieldNameUtils.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/FieldNameUtils.scala index 5ecb7e634..81c7b9b27 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/FieldNameUtils.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/FieldNameUtils.scala @@ -72,7 +72,6 @@ object FieldNameUtils { case _ => None } - private def invalidSelectorErrorMessage[T](selectorExpr: Expr[T])(using Quotes): String = { + private def invalidSelectorErrorMessage[T](selectorExpr: Expr[T])(using Quotes): String = s"Invalid selector expression: ${selectorExpr.show}" - } } 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 6970982fd..b377813ef 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 @@ -166,11 +166,10 @@ object PartialTransformerIntoMacros { source: Expr[From], td: Expr[PartialTransformerDefinition[From, To, Cfg, Flags]], failFast: Boolean - )(using Quotes): Expr[partial.Result[To]] = { + )(using Quotes): Expr[partial.Result[To]] = TransformerMacros.derivePartialTransformerResultWithConfig[From, To, Cfg, Flags, ImplicitScopeFlags]( source, td, failFast ) - } } 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 132006425..eeb61da13 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 @@ -103,7 +103,6 @@ object TransformerIntoMacros { ]( source: Expr[From], td: Expr[TransformerDefinition[From, To, Cfg, Flags]] - )(using Quotes): Expr[To] = { + )(using Quotes): Expr[To] = TransformerMacros.deriveTotalTransformerResultWithConfig[From, To, Cfg, Flags, ImplicitScopeFlags](source, td) - } } diff --git a/chimney/src/main/scala/io/scalaland/chimney/PartialTransformer.scala b/chimney/src/main/scala/io/scalaland/chimney/PartialTransformer.scala index 260da675e..201caa631 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/PartialTransformer.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/PartialTransformer.scala @@ -57,13 +57,12 @@ object PartialTransformer extends PartialTransformerCompanionPlatform { * @since 0.7.0 */ def apply[From, To](f: From => partial.Result[To]): PartialTransformer[From, To] = - (src: From, _: Boolean) => { - try { + (src: From, _: Boolean) => + try f(src) - } catch { + catch { case why: Throwable => partial.Result.fromErrorThrowable(why) } - } /** Construct ad-hoc instance of partial transformer from transforming function returning target value. * @@ -75,13 +74,12 @@ object PartialTransformer extends PartialTransformerCompanionPlatform { * @since 0.7.0 */ def fromFunction[From, To](f: From => To): PartialTransformer[From, To] = - (src: From, _: Boolean) => { - try { + (src: From, _: Boolean) => + try partial.Result.fromValue(f(src)) - } catch { + catch { case why: Throwable => partial.Result.fromErrorThrowable(why) } - } /** Lifts total transformer to partial transformer * diff --git a/chimney/src/main/scala/io/scalaland/chimney/dsl/FlagsDsl.scala b/chimney/src/main/scala/io/scalaland/chimney/dsl/FlagsDsl.scala index ee5e71c07..149afaed2 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/dsl/FlagsDsl.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/dsl/FlagsDsl.scala @@ -134,18 +134,20 @@ private[dsl] trait FlagsDsl[UpdateFlag[_ <: TransformerFlags], Flags <: Transfor disableFlag[ImplicitConflictResolution[?]] /** Enable printing the logs from the derivation process. - * - * @see [[https://scalalandio.github.io/chimney/TODO]] for more details - * @since 0.8.0 - */ + * + * @see [[https://scalalandio.github.io/chimney/TODO]] for more details + * + * @since 0.8.0 + */ def enableMacrosLogging: UpdateFlag[Enable[MacrosLogging, Flags]] = enableFlag[MacrosLogging] /** Disable printing the logs from the derivation process. - * - * @see [[https://scalalandio.github.io/chimney/TODO]] for more details - * @since 0.8.0 - */ + * + * @see [[https://scalalandio.github.io/chimney/TODO]] for more details + * + * @since 0.8.0 + */ def disableMacrosLogging: UpdateFlag[Disable[MacrosLogging, Flags]] = disableFlag[MacrosLogging] diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/DerivationResult.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/DerivationResult.scala index 589a232dd..854cd7f57 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/DerivationResult.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/DerivationResult.scala @@ -4,14 +4,14 @@ import scala.collection.compat.* import scala.util.control.NonFatal /** Representations of a ongoing computation. - * - * Features: - * - handles errors - * - catches exceptions - * - provides sequential and parallel combinators - * - * Intended to simplify how we express our logic during the derivation without long types and boilerplate. - */ + * + * Features: + * - handles errors + * - catches exceptions + * - provides sequential and parallel combinators + * + * Intended to simplify how we express our logic during the derivation without long types and boilerplate. + */ sealed private[compiletime] trait DerivationResult[+A] { import DerivationResult.* @@ -33,7 +33,7 @@ sealed private[compiletime] trait DerivationResult[+A] { var state: State = null.asInstanceOf[State] val result = - try { + try this match { case Success(value, s) => state = s @@ -42,7 +42,7 @@ sealed private[compiletime] trait DerivationResult[+A] { state = s onFailure(derivationErrors) } - } catch { + catch { case NonFatal(err) => DerivationResult.fromException(err) } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/Log.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/Log.scala index 98a591415..26d4a3cdc 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/Log.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/Log.scala @@ -24,7 +24,7 @@ private[compiletime] object Log { private val singleIndent = " " private def print(log: Log, indent: String): String = log match { - case Entry(msg) => s"$indent+ ${msg().replaceAll("\n", s"\n${indent}| ")}\n" + case Entry(msg) => s"$indent+ ${msg().replaceAll("\n", s"\n$indent| ")}\n" case Scope(scopeName, journal) => s"$indent+ $scopeName\n${print(journal, indent + singleIndent)}" } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/PatcherDerivationError.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/PatcherDerivationError.scala index b4bd33e48..2f35bb6e1 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/PatcherDerivationError.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/PatcherDerivationError.scala @@ -15,7 +15,6 @@ object PatcherDerivationError { s"Field named '$patchFieldName' not found in target patching type $objTypeName!" } - def printErrors(errors: Seq[PatcherDerivationError]): String = { + def printErrors(errors: Seq[PatcherDerivationError]): String = errors.map(printError).mkString("\n") - } } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/TransformerDerivationError.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/TransformerDerivationError.scala index 2391d05c9..ee848abd5 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/TransformerDerivationError.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/TransformerDerivationError.scala @@ -52,7 +52,7 @@ final case class NotSupportedTransformerDerivation( ) extends TransformerDerivationError object TransformerDerivationError { - def printErrors(errors: Seq[TransformerDerivationError]): String = { + def printErrors(errors: Seq[TransformerDerivationError]): String = errors .groupBy(e => (e.targetTypeName, e.sourceTypeName)) .map { case ((targetTypeName, sourceTypeName), errs) => @@ -94,5 +94,4 @@ object TransformerDerivationError { |""".stripMargin } .mkString("\n") - } } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala index 3896276ca..5fba8532f 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala @@ -49,7 +49,7 @@ private[compiletime] trait Derivation val patchedArgs = targetParams.map { case (targetParamName, _) => targetParamName -> patchMapping.getOrElse( targetParamName, - targetGetters(targetParamName).mapK[Expr] { _ => getter => getter.get(ctx.obj) } + targetGetters(targetParamName).mapK[Expr](_ => getter => getter.get(ctx.obj)) ) } @@ -71,7 +71,7 @@ private[compiletime] trait Derivation ): DerivationResult[Option[ExistentialExpr]] = { def patchGetterExpr: ExistentialExpr = - patchGetter.mapK[Expr] { _ => getter => getter.get(ctx.patch) } + patchGetter.mapK[Expr](_ => getter => getter.get(ctx.patch)) targetParams.get(patchFieldName) match { case Some(targetParam) 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 bf82ecc63..1e300f760 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 @@ -75,7 +75,7 @@ private[compiletime] trait Configurations { this: Derivation => def allowFromToImplicitSearch: TransformerConfig = copy(preventResolutionForTypes = None) - def prepareForRecursiveCall: TransformerConfig = { + def prepareForRecursiveCall: TransformerConfig = // When going recursively we have to: // - clear the field overrides since `with*(_.field, *)` might make sense for src, but not for src.field // - clear implicit call prevention: @@ -93,7 +93,6 @@ private[compiletime] trait Configurations { this: Derivation => preventResolutionForTypes = None, fieldOverrides = Map.empty ) - } // def usesRuntimeDataStore: Boolean = // fieldOverrides.values.exists(_.usesRuntimeDataStore) || coproductOverrides.nonEmpty diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Contexts.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Contexts.scala index 61c4ee838..7b939716a 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Contexts.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Contexts.scala @@ -57,14 +57,14 @@ private[compiletime] trait Contexts { this: Derivation => }.asInstanceOf[this.type] /** Avoid clumsy - * {{{ - * - * ctx match { - * case total: TransformationContext.ForTotal[?, ?] => ... - * case partial: TransformationContext.ForPartial[?, ?] => ... - * } - * }}} - */ + * {{{ + * + * ctx match { + * case total: TransformationContext.ForTotal[?, ?] => ... + * case partial: TransformationContext.ForPartial[?, ?] => ... + * } + * }}} + */ def fold[B]( forTotal: TransformationContext.ForTotal[From, To] => B )( diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala index a9f7e5854..e2224bcd6 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala @@ -165,7 +165,7 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio import getter.Underlying as Getter, getter.value.get DerivationResult.namedScope( s"Recursive derivation for field `$sourceName`: ${Type - .prettyPrint[getter.Underlying]} renamed into `${toName}`: ${Type + .prettyPrint[getter.Underlying]} renamed into `$toName`: ${Type .prettyPrint[ctorParam.Underlying]}" ) { // We're constructing: @@ -213,7 +213,7 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio import getter.Underlying, getter.value.get DerivationResult.namedScope( s"Recursive derivation for field `$fromName`: ${Type - .prettyPrint[getter.Underlying]} into matched `${toName}`: ${Type.prettyPrint[ctorParam.Underlying]}" + .prettyPrint[getter.Underlying]} into matched `$toName`: ${Type.prettyPrint[ctorParam.Underlying]}" ) { // We're constructing: // '{ ${ derivedToElement } } // using ${ src.$name } @@ -436,7 +436,7 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio nestFlatMaps(partialsAsLazy.toList, totalConstructorArguments) } - val fullErrorBranch: Expr[partial.Result[To]] = { + val fullErrorBranch: Expr[partial.Result[To]] = // Here, we're building: // '{ // var allerrors: Errors = null @@ -488,7 +488,6 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio } ) } - } ctx match { case TransformationContext.ForTotal(_) => diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/NonEmptyErrorsChain.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/NonEmptyErrorsChain.scala index 27f6c6e20..f18080f40 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/NonEmptyErrorsChain.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/runtime/NonEmptyErrorsChain.scala @@ -19,9 +19,8 @@ sealed abstract class NonEmptyErrorsChain extends Iterable[partial.Error] { * * @since 0.7.0 */ - final def prependPath(pathElement: partial.PathElement): NonEmptyErrorsChain = { + final def prependPath(pathElement: partial.PathElement): NonEmptyErrorsChain = NonEmptyErrorsChain.WrapPath(this, pathElement) - } /** Tests whether collections is empty. * @@ -35,14 +34,13 @@ sealed abstract class NonEmptyErrorsChain extends Iterable[partial.Error] { * * @since 0.7.0 */ - final override def iterator: Iterator[partial.Error] = { + final override def iterator: Iterator[partial.Error] = this match { case NonEmptyErrorsChain.Single(error) => Iterator.single(error) case NonEmptyErrorsChain.Wrap(errors) => errors.iterator case NonEmptyErrorsChain.Merge(left, right) => left.iterator ++ right.iterator case NonEmptyErrorsChain.WrapPath(errors, pathElement) => errors.iterator.map(_.prependErrorPath(pathElement)) } - } /** Returns a new errors collection containing elements from this, followed by elements of other collection. * @@ -51,20 +49,17 @@ sealed abstract class NonEmptyErrorsChain extends Iterable[partial.Error] { * * @since 0.7.0 */ - final def ++(other: NonEmptyErrorsChain): NonEmptyErrorsChain = { + final def ++(other: NonEmptyErrorsChain): NonEmptyErrorsChain = NonEmptyErrorsChain.Merge(this, other) - } - final override def equals(obj: Any): Boolean = { + final override def equals(obj: Any): Boolean = obj match { case xs: NonEmptyErrorsChain => xs.iterator.sameElements(this.iterator) case _ => false } - } - final override def hashCode(): Int = { + final override def hashCode(): Int = MurmurHash3.orderedHash(iterator) - } } object NonEmptyErrorsChain { @@ -75,9 +70,8 @@ object NonEmptyErrorsChain { * @return instance of [[NonEmptyErrorsChain]] * @since 0.7.0 */ - final def single(error: partial.Error): NonEmptyErrorsChain = { + final def single(error: partial.Error): NonEmptyErrorsChain = Single(error) - } /** Creates errors collection from head and tail. * @@ -86,11 +80,10 @@ object NonEmptyErrorsChain { * @return instance of [[NonEmptyErrorsChain]] * @since 0.7.0 */ - final def from(head: partial.Error, tail: partial.Error*): NonEmptyErrorsChain = { + final def from(head: partial.Error, tail: partial.Error*): NonEmptyErrorsChain = if (tail.isEmpty) Single(head) else if (tail.sizeIs == 1) Merge(Single(head), Single(tail.head)) else Merge(Single(head), Wrap(tail)) - } final private case class Single(error: partial.Error) extends NonEmptyErrorsChain final private case class Wrap(errors: Iterable[partial.Error]) extends NonEmptyErrorsChain diff --git a/chimney/src/main/scala/io/scalaland/chimney/partial/Path.scala b/chimney/src/main/scala/io/scalaland/chimney/partial/Path.scala index 3065267bf..5429135ec 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/partial/Path.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/partial/Path.scala @@ -14,14 +14,14 @@ final case class Path(private val elems: List[PathElement]) extends AnyVal { * @return path with prepended path element * * @since 0.7.0 - * */ + */ def prepend(pathElement: PathElement): Path = Path(pathElement :: elems) /** Returns conventional string based representation of a path * * @since 0.7.0 */ - def asString: String = { + def asString: String = if (elems.isEmpty) "" else { val sb = new StringBuilder @@ -35,7 +35,6 @@ final case class Path(private val elems: List[PathElement]) extends AnyVal { } sb.result() } - } } object Path { diff --git a/chimney/src/main/scala/io/scalaland/chimney/partial/Result.scala b/chimney/src/main/scala/io/scalaland/chimney/partial/Result.scala index 7fe303272..19749e27e 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/partial/Result.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/partial/Result.scala @@ -115,7 +115,7 @@ object Result { * @param errors non-empty collection of path-annotated errors * * @since 0.7.0 - * */ + */ final case class Errors(errors: NonEmptyErrorsChain) extends Result[Nothing] { def prependPath(pathElement: PathElement): Errors = Errors(errors.prependPath(pathElement)) @@ -180,12 +180,11 @@ object Result { /** Used internally by macro. Please don't use in your code. */ - final def __mergeResultNullable[T](errorsNullable: Errors, result: Result[T]): Errors = { + final def __mergeResultNullable[T](errorsNullable: Errors, result: Result[T]): Errors = result match { case _: Value[?] => errorsNullable case errors: Errors => if (errorsNullable == null) errors else merge(errorsNullable, errors) } - } } /** Converts a function that throws Exceptions into function that returns Result. @@ -400,9 +399,9 @@ object Result { * @since 0.7.0 */ final def fromCatching[A](value: => A): Result[A] = - try { + try fromValue(value) - } catch { + catch { case t: Throwable => fromErrorThrowable(t) } @@ -431,23 +430,21 @@ object Result { if (failFast) { var errors: Errors = null - while (errors == null && it.hasNext) { + while (errors == null && it.hasNext) f(it.next()) match { case Value(value) => bs += value case e: Errors => errors = e } - } if (errors == null) Result.Value(bs.result()) else errors } else { var allErrors: NonEmptyErrorsChain = null - while (it.hasNext) { + while (it.hasNext) f(it.next()) match { case Value(value) => bs += value case Errors(ee) => if (allErrors == null) allErrors = ee else allErrors ++= ee } - } if (allErrors == null) Result.Value(bs.result()) else Result.Errors(allErrors) } } diff --git a/chimney/src/test/scala-3/io/scalaland/chimney/VersionCompat.scala b/chimney/src/test/scala-3/io/scalaland/chimney/VersionCompat.scala index b3b7e2ec2..7f98e6d03 100644 --- a/chimney/src/test/scala-3/io/scalaland/chimney/VersionCompat.scala +++ b/chimney/src/test/scala-3/io/scalaland/chimney/VersionCompat.scala @@ -19,7 +19,7 @@ trait VersionCompat { } .mkString("\n") val separator = if error.message.contains('\n') then "\n" else " " - s"error:${separator}${trimMessage}\n${error.lineContent}\n${indent}^" + s"error:$separator$trimMessage\n${error.lineContent}\n$indent^" } .mkString("\n") } diff --git a/chimney/src/test/scala/io/scalaland/chimney/ChimneySpec.scala b/chimney/src/test/scala/io/scalaland/chimney/ChimneySpec.scala index 5cf904530..999d03d66 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/ChimneySpec.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/ChimneySpec.scala @@ -25,7 +25,7 @@ trait ChimneySpec extends munit.BaseFunSuite with VersionCompat { self => else super.test(options.withName(appendName(prefix, options.name)))(body) implicit class ArrowAssert(lhs: Any) { - def ==>[V](rhs: V): Unit = { + def ==>[V](rhs: V): Unit = (lhs, rhs) match { // Hack to make Arrays compare sanely; at some point we may want some // custom, extensible, typesafe equality check but for now this will do @@ -34,13 +34,11 @@ trait ChimneySpec extends munit.BaseFunSuite with VersionCompat { self => case (lhs, rhs) => Predef.assert(lhs == rhs, s"==> assertion failed: $lhs != $rhs") } - } } implicit class CompileErrorsCheck(msg: String) { - def check(msgs: String*): Unit = for (msg <- msgs) { - + def check(msgs: String*): Unit = for (msg <- msgs) Predef.assert( ChimneySpec.AnsiControlCode.replaceAllIn(this.msg, "").contains(msg), "Error message did not contain expected snippet\n" + @@ -49,7 +47,6 @@ trait ChimneySpec extends munit.BaseFunSuite with VersionCompat { self => "Expected Snippet\n" + msg ) - } def arePresent(): Unit = Predef.assert(msg.nonEmpty, "Expected compilation errors") } diff --git a/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerProductSpec.scala b/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerProductSpec.scala index fc7b57262..26e791571 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerProductSpec.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerProductSpec.scala @@ -598,9 +598,8 @@ class TotalTransformerProductSpec extends ChimneySpec { case class Bar(x: Option[Bar]) test("defined by hand") { - implicit def fooToBarTransformer: Transformer[Foo, Bar] = (foo: Foo) => { - Bar(foo.x.map(fooToBarTransformer.transform)) - } + implicit def fooToBarTransformer: Transformer[Foo, Bar] = + (foo: Foo) => Bar(foo.x.map(fooToBarTransformer.transform)) Foo(Some(Foo(None))).transformInto[Bar] ==> Bar(Some(Bar(None))) } diff --git a/chimney/src/test/scala/io/scalaland/chimney/fixtures/Numbers.scala b/chimney/src/test/scala/io/scalaland/chimney/fixtures/Numbers.scala index e9f3128b3..b49fdc194 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/fixtures/Numbers.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/fixtures/Numbers.scala @@ -30,7 +30,7 @@ package numbers { implicit def shortToLongTotalInner[A, B](implicit ft: Transformer[A, B] - ): PartialTransformer[short.NumScale[A, Nothing], long.NumScale[B]] = { + ): PartialTransformer[short.NumScale[A, Nothing], long.NumScale[B]] = Transformer .definePartial[short.NumScale[A, Nothing], long.NumScale[B]] .withCoproductInstancePartial { (billion: short.Billion[A]) => @@ -40,11 +40,10 @@ package numbers { trillion.transformIntoPartial[long.Billion[B]] } .buildTransformer - } implicit def shortToLongPartialInner[A, B](implicit ft: PartialTransformer[A, B] - ): PartialTransformer[short.NumScale[A, Nothing], long.NumScale[B]] = { + ): PartialTransformer[short.NumScale[A, Nothing], long.NumScale[B]] = Transformer .definePartial[short.NumScale[A, Nothing], long.NumScale[B]] .withCoproductInstancePartial { (billion: short.Billion[A]) => @@ -54,6 +53,5 @@ package numbers { trillion.transformIntoPartial[long.Billion[B]] } .buildTransformer - } } } diff --git a/chimney/src/test/scala/io/scalaland/chimney/fixtures/javabeans/javabeans.scala b/chimney/src/test/scala/io/scalaland/chimney/fixtures/javabeans/javabeans.scala index 052e7fe61..3ba5c8ffd 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/fixtures/javabeans/javabeans.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/fixtures/javabeans/javabeans.scala @@ -7,9 +7,8 @@ case class CaseClassWithFlagMethod(id: String, name: String) { } case class CaseClassWithFlag(id: String, name: String, flag: Boolean) { - def equalsToBean(jbswf: JavaBeanSourceWithFlag): Boolean = { + def equalsToBean(jbswf: JavaBeanSourceWithFlag): Boolean = id == jbswf.getId && name == jbswf.getName && flag == jbswf.isFlag - } } case class CaseClassWithFlagRenamed(id: String, name: String, renamedFlag: Boolean) @@ -33,17 +32,14 @@ class JavaBeanTarget { private var name: String = _ private var flag: Boolean = _ - def setId(id: String): Unit = { + def setId(id: String): Unit = this.id = id - } - def setName(name: String): Unit = { + def setName(name: String): Unit = this.name = name - } - def setFlag(flag: Boolean): Unit = { + def setFlag(flag: Boolean): Unit = this.flag = flag - } // make sure that only public setters are taken into account protected def setFoo(foo: Unit): Unit = () @@ -56,21 +52,19 @@ class JavaBeanTarget { def isFlag: Boolean = flag - override def equals(obj: Any): Boolean = { + override def equals(obj: Any): Boolean = obj match { case jbt: JavaBeanTarget => this.id == jbt.getId && this.name == jbt.getName && this.flag == jbt.isFlag case _ => false } - } } class JavaBeanTargetNoIdSetter { private var id: String = _ - def withId(id: String): Unit = { + def withId(id: String): Unit = this.id = id - } // make sure that only public setters are taken into account protected def setFoo(foo: Unit): Unit = () @@ -79,14 +73,13 @@ class JavaBeanTargetNoIdSetter { def getId: String = id - override def equals(obj: Any): Boolean = { + override def equals(obj: Any): Boolean = obj match { case jbt: JavaBeanTarget => this.id == jbt.getId case _ => false } - } } case class EnclosingCaseClass(ccNoFlag: CaseClassNoFlag) @@ -96,16 +89,14 @@ class EnclosingBean { def getCcNoFlag: CaseClassNoFlag = ccNoFlag - def setCcNoFlag(ccNoFlag: CaseClassNoFlag): Unit = { + def setCcNoFlag(ccNoFlag: CaseClassNoFlag): Unit = this.ccNoFlag = ccNoFlag - } - override def equals(obj: Any): Boolean = { + override def equals(obj: Any): Boolean = obj match { case eb: EnclosingBean => this.ccNoFlag == eb.ccNoFlag case _ => false } - } } diff --git a/chimney/src/test/scala/io/scalaland/chimney/utils/EitherUtils.scala b/chimney/src/test/scala/io/scalaland/chimney/utils/EitherUtils.scala index 04b25b5b5..4120093c9 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/utils/EitherUtils.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/utils/EitherUtils.scala @@ -3,19 +3,17 @@ package io.scalaland.chimney.utils object EitherUtils { implicit final class OptionOps[T](private val opt: Option[T]) extends AnyVal { - def toEither(err: => String): Either[String, T] = { + def toEither(err: => String): Either[String, T] = opt match { case Some(value) => Right(value) case None => Left(err) } - } - def toEitherList(err: => String): Either[List[String], T] = { + def toEitherList(err: => String): Either[List[String], T] = opt match { case Some(value) => Right(value) case None => Left(List(err)) } - } } }