From 2ea32c06dc673f91f1971ed3b08e0290bd3a6611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fromentin?= Date: Fri, 13 Sep 2024 16:11:47 +0200 Subject: [PATCH] misc: Reformat code --- .../iltotore/iron/constraint/collection.scala | 6 ++- .../iltotore/iron/constraint/numeric.scala | 42 +++++++++---------- .../iltotore/iron/macros/ReflectUtil.scala | 36 ++++++++-------- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/main/src/io/github/iltotore/iron/constraint/collection.scala b/main/src/io/github/iltotore/iron/constraint/collection.scala index 97c957c..06dccaf 100644 --- a/main/src/io/github/iltotore/iron/constraint/collection.scala +++ b/main/src/io/github/iltotore/iron/constraint/collection.scala @@ -111,7 +111,9 @@ object collection: inline given lengthString[C, Impl <: Constraint[Int, C]](using inline impl: Impl): LengthString[C, Impl] = new LengthString - private def checkIterable[I <: Iterable[?] : Type, C, Impl <: Constraint[Int, C]](expr: Expr[I], constraintExpr: Expr[Impl])(using Quotes): Expr[Boolean] = + private def checkIterable[I <: Iterable[?]: Type, C, Impl <: Constraint[Int, C]](expr: Expr[I], constraintExpr: Expr[Impl])(using + Quotes + ): Expr[Boolean] = val rflUtil = reflectUtil import rflUtil.* @@ -142,7 +144,7 @@ object collection: override inline def message: String = "Should contain the string " + constValue[V] - private def checkIterable[I <: Iterable[?] : Type, V : Type](expr: Expr[I], partExpr: Expr[V])(using Quotes): Expr[Boolean] = + private def checkIterable[I <: Iterable[?]: Type, V: Type](expr: Expr[I], partExpr: Expr[V])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil import rflUtil.* diff --git a/main/src/io/github/iltotore/iron/constraint/numeric.scala b/main/src/io/github/iltotore/iron/constraint/numeric.scala index 5b90899..0a91ca5 100644 --- a/main/src/io/github/iltotore/iron/constraint/numeric.scala +++ b/main/src/io/github/iltotore/iron/constraint/numeric.scala @@ -167,13 +167,13 @@ object numeric: override inline def test(inline value: Double): Boolean = value > doubleValue[V] inline given bigDecimalDouble[V <: NumConstant]: GreaterConstraint[BigDecimal, V] with - override inline def test(inline value: BigDecimal): Boolean = ${checkBigDecimalDouble('value, '{doubleValue[V]})} + override inline def test(inline value: BigDecimal): Boolean = ${ checkBigDecimalDouble('value, '{ doubleValue[V] }) } inline given bigDecimalLong[V <: Int | Long]: GreaterConstraint[BigDecimal, V] with - override inline def test(inline value: BigDecimal): Boolean = ${checkBigDecimalLong('value, '{longValue[V]})} + override inline def test(inline value: BigDecimal): Boolean = ${ checkBigDecimalLong('value, '{ longValue[V] }) } inline given [V <: Int | Long]: GreaterConstraint[BigInt, V] with - override inline def test(inline value: BigInt): Boolean = ${checkBigInt('value, '{longValue[V]})} + override inline def test(inline value: BigInt): Boolean = ${ checkBigInt('value, '{ longValue[V] }) } private def checkBigDecimalDouble(expr: Expr[BigDecimal], thanExpr: Expr[Double])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -181,7 +181,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value > BigDecimal(than)) - case _ => '{$expr > BigDecimal($thanExpr)} + case _ => '{ $expr > BigDecimal($thanExpr) } private def checkBigDecimalLong(expr: Expr[BigDecimal], thanExpr: Expr[Long])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -189,7 +189,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value > BigDecimal(than)) - case _ => '{$expr > BigDecimal($thanExpr)} + case _ => '{ $expr > BigDecimal($thanExpr) } private def checkBigInt(expr: Expr[BigInt], thanExpr: Expr[Long])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -197,8 +197,8 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value > BigInt(than)) - case _ => '{$expr > BigInt($thanExpr)} - + case _ => '{ $expr > BigInt($thanExpr) } + given [V1, V2](using V1 > V2 =:= true): (Greater[V1] ==> Greater[V2]) = Implication() given [V1, V2](using V1 > V2 =:= true): (StrictEqual[V1] ==> Greater[V2]) = Implication() @@ -226,13 +226,13 @@ object numeric: override inline def test(inline value: Double): Boolean = value < doubleValue[V] inline given bigDecimalDouble[V <: NumConstant]: LessConstraint[BigDecimal, V] with - override inline def test(inline value: BigDecimal): Boolean = ${checkBigDecimalDouble('value, '{doubleValue[V]})} + override inline def test(inline value: BigDecimal): Boolean = ${ checkBigDecimalDouble('value, '{ doubleValue[V] }) } inline given bigDecimalLong[V <: Int | Long]: LessConstraint[BigDecimal, V] with - override inline def test(inline value: BigDecimal): Boolean = ${checkBigDecimalLong('value, '{longValue[V]})} + override inline def test(inline value: BigDecimal): Boolean = ${ checkBigDecimalLong('value, '{ longValue[V] }) } inline given [V <: Int | Long]: LessConstraint[BigInt, V] with - override inline def test(inline value: BigInt): Boolean = ${checkBigInt('value, '{longValue[V]})} + override inline def test(inline value: BigInt): Boolean = ${ checkBigInt('value, '{ longValue[V] }) } private def checkBigDecimalDouble(expr: Expr[BigDecimal], thanExpr: Expr[Double])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -240,7 +240,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value < BigDecimal(than)) - case _ => '{$expr < BigDecimal($thanExpr)} + case _ => '{ $expr < BigDecimal($thanExpr) } private def checkBigDecimalLong(expr: Expr[BigDecimal], thanExpr: Expr[Long])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -248,7 +248,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value < BigDecimal(than)) - case _ => '{$expr < BigDecimal($thanExpr)} + case _ => '{ $expr < BigDecimal($thanExpr) } private def checkBigInt(expr: Expr[BigInt], thanExpr: Expr[Long])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -256,7 +256,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value < BigInt(than)) - case _ => '{$expr < BigInt($thanExpr)} + case _ => '{ $expr < BigInt($thanExpr) } given [V1, V2](using V1 < V2 =:= true): (Less[V1] ==> Less[V2]) = Implication() @@ -286,11 +286,11 @@ object numeric: inline given [V <: NumConstant]: MultipleConstraint[BigDecimal, V] with - override inline def test(inline value: BigDecimal): Boolean = ${checkBigDecimal('value, '{doubleValue[V]})} + override inline def test(inline value: BigDecimal): Boolean = ${ checkBigDecimal('value, '{ doubleValue[V] }) } inline given [V <: Int | Long]: MultipleConstraint[BigInt, V] with - override inline def test(inline value: BigInt): Boolean = ${checkBigInt('value, '{longValue[V]})} + override inline def test(inline value: BigInt): Boolean = ${ checkBigInt('value, '{ longValue[V] }) } private def checkBigDecimal(expr: Expr[BigDecimal], thanExpr: Expr[Double])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -298,7 +298,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value % BigDecimal(than) == 0) - case _ => '{$expr % BigDecimal($thanExpr) == 0} + case _ => '{ $expr % BigDecimal($thanExpr) == 0 } private def checkBigInt(expr: Expr[BigInt], thanExpr: Expr[Long])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -306,7 +306,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(value % BigInt(than) == 0) - case _ => '{$expr % BigInt($thanExpr) == 0} + case _ => '{ $expr % BigInt($thanExpr) == 0 } given [A, V1 <: A, V2 <: A](using V1 % V2 =:= Zero[A]): (Multiple[V1] ==> Multiple[V2]) = Implication() @@ -327,10 +327,10 @@ object numeric: override inline def test(inline value: Double): Boolean = doubleValue[V] % value == 0 inline given [V <: NumConstant]: DivideConstraint[BigDecimal, V] with - override inline def test(inline value: BigDecimal): Boolean = ${checkBigDecimal('value, '{doubleValue[V]})} + override inline def test(inline value: BigDecimal): Boolean = ${ checkBigDecimal('value, '{ doubleValue[V] }) } inline given [V <: Int | Long]: DivideConstraint[BigInt, V] with - override inline def test(inline value: BigInt): Boolean = ${checkBigInt('value, '{longValue[V]})} + override inline def test(inline value: BigInt): Boolean = ${ checkBigInt('value, '{ longValue[V] }) } private def checkBigDecimal(expr: Expr[BigDecimal], thanExpr: Expr[Double])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -338,7 +338,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(BigDecimal(than) % value == 0) - case _ => '{BigDecimal($thanExpr) % $expr == 0} + case _ => '{ BigDecimal($thanExpr) % $expr == 0 } private def checkBigInt(expr: Expr[BigInt], thanExpr: Expr[Long])(using Quotes): Expr[Boolean] = val rflUtil = reflectUtil @@ -346,7 +346,7 @@ object numeric: (expr.decode, thanExpr.decode) match case (Right(value), Right(than)) => Expr(BigInt(than) % value == 0) - case _ => '{BigInt($thanExpr) % $expr == 0} + case _ => '{ BigInt($thanExpr) % $expr == 0 } object NaN: private trait NaNConstraint[A] extends Constraint[A, NaN]: diff --git a/main/src/io/github/iltotore/iron/macros/ReflectUtil.scala b/main/src/io/github/iltotore/iron/macros/ReflectUtil.scala index 93a86b4..00181d3 100644 --- a/main/src/io/github/iltotore/iron/macros/ReflectUtil.scala +++ b/main/src/io/github/iltotore/iron/macros/ReflectUtil.scala @@ -22,8 +22,8 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q): import _quotes.reflect.* type DecodingResult[+T] = Either[DecodingFailure, T] - extension [T](result: DecodingResult[T]) - private def as[U]: DecodingResult[U] = result.asInstanceOf[DecodingResult[U]] + extension [T](result: DecodingResult[T]) + private def as[U]: DecodingResult[U] = result.asInstanceOf[DecodingResult[U]] extension [T: Type](expr: Expr[T]) /** @@ -186,11 +186,11 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q): object ExprDecoder: private val enhancedDecoders: Map[TypeRepr, (Term, Map[String, ?]) => DecodingResult[?]] = Map( - TypeRepr.of[Boolean] -> decodeBoolean, + TypeRepr.of[Boolean] -> decodeBoolean, TypeRepr.of[BigDecimal] -> decodeBigDecimal, - TypeRepr.of[BigInt] -> decodeBigInt, - TypeRepr.of[List[?]] -> decodeList, - TypeRepr.of[String] -> decodeString + TypeRepr.of[BigInt] -> decodeBigInt, + TypeRepr.of[List[?]] -> decodeList, + TypeRepr.of[String] -> decodeString ) /** @@ -267,12 +267,12 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q): case _ => tree.tpe.widenTermRefByName match case ConstantType(c) => Right(c.value) - case _ => tree match - case Ident(name) => definitions - .get(name) - .toRight(DecodingFailure.NotInlined(tree)) - - case _ => Left(DecodingFailure.NotInlined(tree)) + case _ => tree match + case Ident(name) => definitions + .get(name) + .toRight(DecodingFailure.NotInlined(tree)) + + case _ => Left(DecodingFailure.NotInlined(tree)) /** * Decode a binding/definition. @@ -343,7 +343,7 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q): term match case Apply(Select(Ident("BigInt"), "apply"), List(value)) => decodeTerm(value, definitions).as[Int | Long].map: - case x: Int => BigInt(x) + case x: Int => BigInt(x) case x: Long => BigInt(x) case _ => Left(DecodingFailure.Unknown) @@ -358,11 +358,11 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q): term match case Apply(Select(Ident("BigDecimal"), "apply"), List(value)) => decodeTerm(value, definitions).as[NumConstant].map: - case x: Int => BigDecimal(x) - case x: Long => BigDecimal(x) - case x: Float => BigDecimal(x) + case x: Int => BigDecimal(x) + case x: Long => BigDecimal(x) + case x: Float => BigDecimal(x) case x: Double => BigDecimal(x) - + case _ => Left(DecodingFailure.Unknown) /** @@ -376,4 +376,4 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q): term match case Apply(TypeApply(Select(Ident("List"), "apply"), _), List(values)) => decodeTerm(values, definitions).as[List[?]] - case _ => Left(DecodingFailure.Unknown) \ No newline at end of file + case _ => Left(DecodingFailure.Unknown)