@@ -870,11 +870,14 @@ object JsonCodecMaker {
870
870
def scalaCollectionBuilder (tpe : TypeRepr , eTpe : TypeRepr ): Term =
871
871
TypeApply (Select .unique(scalaCollectionCompanion(tpe), " newBuilder" ), List (Inferred (eTpe)))
872
872
873
- def scalaCollectionEmptyNoArgs ( cTpe : TypeRepr , eTpe : TypeRepr ): Term =
874
- TypeApply (Select .unique(scalaCollectionCompanion(cTpe ), " empty " ), List (Inferred (eTpe )))
873
+ def scalaMapBuilder ( tpe : TypeRepr , kTpe : TypeRepr , vTpe : TypeRepr ): Term =
874
+ TypeApply (Select .unique(scalaCollectionCompanion(tpe ), " newBuilder " ), List (Inferred (kTpe), Inferred (vTpe )))
875
875
876
- def scalaMapEmptyNoArgs (cTpe : TypeRepr , kTpe : TypeRepr , vTpe : TypeRepr ): Term =
877
- TypeApply (Select .unique(scalaCollectionCompanion(cTpe), " empty" ), List (Inferred (kTpe), Inferred (vTpe)))
876
+ def scalaCollectionEmpty (tpe : TypeRepr , eTpe : TypeRepr ): Term =
877
+ TypeApply (Select .unique(scalaCollectionCompanion(tpe), " empty" ), List (Inferred (eTpe)))
878
+
879
+ def scalaMapEmpty (tpe : TypeRepr , kTpe : TypeRepr , vTpe : TypeRepr ): Term =
880
+ TypeApply (Select .unique(scalaCollectionCompanion(tpe), " empty" ), List (Inferred (kTpe), Inferred (vTpe)))
878
881
879
882
def scala2EnumerationObject (tpe : TypeRepr ): Expr [Enumeration ] = tpe match
880
883
case TypeRef (eTpe, _) => Ref (eTpe.termSymbol).asExpr.asInstanceOf [Expr [Enumeration ]]
@@ -1126,7 +1129,7 @@ object JsonCodecMaker {
1126
1129
if (tpeTypeArgs ne Nil ) fieldTpe = fieldTpe.substituteTypes(typeParams, tpeTypeArgs)
1127
1130
fieldTpe match
1128
1131
case TypeLambda (_, _, _) =>
1129
- fail(s " Hight-kinded types are not supported for type ' ${tpe.show}' with field type for $name ' ${fieldTpe.show}' " )
1132
+ fail(s " Type lambdas are not supported for type ' ${tpe.show}' with field type for $name ' ${fieldTpe.show}' " )
1130
1133
case TypeBounds (_, _) =>
1131
1134
fail(s " Type bounds are not supported for type ' ${tpe.show}' with field type for $name ' ${fieldTpe.show}' " )
1132
1135
case _ =>
@@ -1135,11 +1138,11 @@ object JsonCodecMaker {
1135
1138
val dvMembers = companionClass.methodMember(" $lessinit$greater$default$" + i)
1136
1139
if (dvMembers.isEmpty) fail(s " Can't find default value for $name in class ${tpe.show}" )
1137
1140
val methodSymbol = dvMembers.head
1138
- val dvSelectNoTArgs = companionModuleRef.select(methodSymbol)
1141
+ val dvSelectNoTypes = companionModuleRef.select(methodSymbol)
1139
1142
val dvSelect = methodSymbol.paramSymss match
1140
- case Nil => dvSelectNoTArgs
1143
+ case Nil => dvSelectNoTypes
1141
1144
case List (params) if params.exists(_.isTypeParam) =>
1142
- TypeApply (dvSelectNoTArgs , tpeTypeArgs.map(Inferred (_)))
1145
+ TypeApply (dvSelectNoTypes , tpeTypeArgs.map(Inferred (_)))
1143
1146
case paramss => fail(s " Default method for $name of class ${tpe.show} have a complex parameter list: $paramss" )
1144
1147
new Some (dvSelect)
1145
1148
} else None
@@ -1874,27 +1877,28 @@ object JsonCodecMaker {
1874
1877
else if (tpe <:< TypeRepr .of[List [? ]] || tpe.typeSymbol == TypeRepr .of[Seq [? ]].typeSymbol) ' { Nil }
1875
1878
else if (tpe <:< TypeRepr .of[collection.SortedSet [? ]] || tpe <:< TypeRepr .of[mutable.PriorityQueue [? ]]) {
1876
1879
val tpe1 = typeArg1(tpe)
1877
- Apply (scalaCollectionEmptyNoArgs (tpe, tpe1), List (summonOrdering(tpe1))).asExpr
1880
+ Apply (scalaCollectionEmpty (tpe, tpe1), List (summonOrdering(tpe1))).asExpr
1878
1881
} else if (tpe <:< TypeRepr .of[mutable.ArraySeq [? ]] || tpe <:< TypeRepr .of[immutable.ArraySeq [? ]] ||
1879
1882
tpe <:< TypeRepr .of[mutable.UnrolledBuffer [? ]]) {
1880
1883
val tpe1 = typeArg1(tpe)
1881
- Apply (scalaCollectionEmptyNoArgs (tpe, tpe1), List (summonClassTag(tpe1))).asExpr
1884
+ Apply (scalaCollectionEmpty (tpe, tpe1), List (summonClassTag(tpe1))).asExpr
1882
1885
} else if (tpe <:< TypeRepr .of[immutable.IntMap [? ]] || tpe <:< TypeRepr .of[immutable.LongMap [? ]] ||
1883
1886
tpe <:< TypeRepr .of[immutable.Seq [? ]] || tpe <:< TypeRepr .of[immutable.Set [? ]]) withNullValueFor(tpe) {
1884
- scalaCollectionEmptyNoArgs (tpe, typeArg1(tpe)).asExpr
1885
- } else if (tpe <:< TypeRepr .of[mutable.LongMap [? ]]) scalaCollectionEmptyNoArgs (tpe, typeArg1(tpe)).asExpr
1887
+ scalaCollectionEmpty (tpe, typeArg1(tpe)).asExpr
1888
+ } else if (tpe <:< TypeRepr .of[mutable.LongMap [? ]]) scalaCollectionEmpty (tpe, typeArg1(tpe)).asExpr
1886
1889
else if (tpe <:< TypeRepr .of[collection.SortedMap [? , ? ]] || tpe <:< TypeRepr .of[mutable.CollisionProofHashMap [? , ? ]]) {
1887
1890
val tpe1 = typeArg1(tpe)
1888
- Apply (scalaMapEmptyNoArgs (tpe, tpe1, typeArg2(tpe)), List (summonOrdering(tpe1))).asExpr
1891
+ Apply (scalaMapEmpty (tpe, tpe1, typeArg2(tpe)), List (summonOrdering(tpe1))).asExpr
1889
1892
} else if (tpe <:< TypeRepr .of[immutable.TreeSeqMap [? , ? ]]) withNullValueFor(tpe) {
1890
- (typeArg1(tpe).asType, typeArg2(tpe).asType) match
1891
- case (' [t1], ' [t2]) => ' { immutable.TreeSeqMap .empty[t1, t2] }
1893
+ typeArg1(tpe).asType match { case ' [t1] =>
1894
+ typeArg2(tpe).asType match { case ' [t2] => ' { immutable.TreeSeqMap .empty[t1, t2] } }
1895
+ }
1892
1896
} else if (tpe <:< TypeRepr .of[immutable.Map [? , ? ]]) withNullValueFor(tpe) {
1893
- scalaMapEmptyNoArgs (tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
1897
+ scalaMapEmpty (tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
1894
1898
} else if (tpe <:< TypeRepr .of[collection.Map [? , ? ]]) {
1895
- scalaMapEmptyNoArgs (tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
1899
+ scalaMapEmpty (tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
1896
1900
} else if (tpe <:< TypeRepr .of[Iterable [? ]] || tpe <:< TypeRepr .of[Iterator [? ]]) {
1897
- scalaCollectionEmptyNoArgs (tpe, typeArg1(tpe)).asExpr
1901
+ scalaCollectionEmpty (tpe, typeArg1(tpe)).asExpr
1898
1902
} else if (tpe <:< TypeRepr .of[Array [? ]]) withNullValueFor(tpe) {
1899
1903
typeArg1(tpe).asType match { case ' [t1] => genNewArray[t1](Expr (0 )) }
1900
1904
} else if (isIArray(tpe)) withNullValueFor(tpe) {
@@ -2417,7 +2421,7 @@ object JsonCodecMaker {
2417
2421
val tpe1 = typeArg1(tpe)
2418
2422
tpe1.asType match
2419
2423
case ' [t1] =>
2420
- val newBuilder = withNullValueFor(tpe)(scalaCollectionEmptyNoArgs (tpe, tpe1).asExpr.asInstanceOf [Expr [immutable.IntMap [t1]]])
2424
+ val newBuilder = withNullValueFor(tpe)(scalaCollectionEmpty (tpe, tpe1).asExpr.asInstanceOf [Expr [immutable.IntMap [t1]]])
2421
2425
val readVal = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false , in)
2422
2426
(if (cfg.mapAsArray) {
2423
2427
val readKey =
@@ -2438,7 +2442,7 @@ object JsonCodecMaker {
2438
2442
val tDefault = default.asInstanceOf [Expr [mutable.LongMap [t1]]]
2439
2443
val newBuilder = ' {
2440
2444
if ($tDefault.isEmpty) $tDefault
2441
- else $ {scalaCollectionEmptyNoArgs (tpe, tpe1).asExpr.asInstanceOf [Expr [mutable.LongMap [t1]]]}
2445
+ else $ {scalaCollectionEmpty (tpe, tpe1).asExpr.asInstanceOf [Expr [mutable.LongMap [t1]]]}
2442
2446
}
2443
2447
val readVal = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false , in)
2444
2448
(if (cfg.mapAsArray) {
@@ -2455,7 +2459,7 @@ object JsonCodecMaker {
2455
2459
val tpe1 = typeArg1(tpe)
2456
2460
tpe1.asType match
2457
2461
case ' [t1] =>
2458
- val newBuilder = withNullValueFor(tpe)(scalaCollectionEmptyNoArgs (tpe, tpe1).asExpr.asInstanceOf [Expr [immutable.LongMap [t1]]])
2462
+ val newBuilder = withNullValueFor(tpe)(scalaCollectionEmpty (tpe, tpe1).asExpr.asInstanceOf [Expr [immutable.LongMap [t1]]])
2459
2463
val readVal = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false , in)
2460
2464
(if (cfg.mapAsArray) {
2461
2465
val readKey =
@@ -2474,10 +2478,10 @@ object JsonCodecMaker {
2474
2478
tpe <:< TypeRepr .of[mutable.CollisionProofHashMap [? , ? ]]) withDecoderFor(methodKey, default, in) { (in, default) =>
2475
2479
val tpe1 = typeArg1(tpe)
2476
2480
val tpe2 = typeArg2(tpe)
2477
- ( tpe1.asType, tpe2.asType) match
2478
- case ( ' [t1], ' [ t2]) =>
2481
+ tpe1.asType match { case ' [t1] =>
2482
+ tpe2.asType match { case ' [ t2] =>
2479
2483
val tDefault = default.asInstanceOf [Expr [T & mutable.Map [t1, t2]]]
2480
- val emptyMapNoArgs = scalaMapEmptyNoArgs (tpe, tpe1, tpe2)
2484
+ val emptyMapNoArgs = scalaMapEmpty (tpe, tpe1, tpe2)
2481
2485
val tEmpty =
2482
2486
(if (tpe <:< TypeRepr .of[mutable.SortedMap [? , ? ]] || tpe <:< TypeRepr .of[mutable.CollisionProofHashMap [? , ? ]]) {
2483
2487
Apply (emptyMapNoArgs, List (summonOrdering(tpe1)))
@@ -2494,20 +2498,18 @@ object JsonCodecMaker {
2494
2498
} else {
2495
2499
genReadMap(newBuilder, x => ' { $x.update($ {genReadKey[t1](tpe1 :: types, in)}, $readVal2) }, identity, in, tDefault)
2496
2500
}).asInstanceOf [Expr [T ]]
2501
+ }
2502
+ }
2497
2503
} else if (tpe <:< TypeRepr .of[collection.Map [? , ? ]]) withDecoderFor(methodKey, default, in) { (in, default) =>
2498
2504
val tpe1 = typeArg1(tpe)
2499
2505
val tpe2 = typeArg2(tpe)
2500
-
2501
- def builderNoApply =
2502
- TypeApply (Select .unique(scalaCollectionCompanion(tpe), " newBuilder" ), List (Inferred (tpe1), Inferred (tpe2)))
2503
-
2504
- (tpe1.asType, tpe2.asType) match
2505
- case (' [t1], ' [t2]) =>
2506
+ tpe1.asType match { case ' [t1] =>
2507
+ tpe2.asType match { case ' [t2] =>
2506
2508
val readVal2 = genReadVal(tpe2 :: types, genNullValue[t2](tpe2 :: types), isStringified, false , in)
2507
2509
val newBuilder =
2508
- (if (tpe <:< TypeRepr .of[collection.SortedMap [? , ? ]]) Apply (builderNoApply , List (summonOrdering(tpe1))).asExpr
2510
+ (if (tpe <:< TypeRepr .of[collection.SortedMap [? , ? ]]) Apply (scalaMapBuilder(tpe, tpe1, tpe2) , List (summonOrdering(tpe1))).asExpr
2509
2511
else if (tpe <:< TypeRepr .of[immutable.TreeSeqMap [? , ? ]]) ' { immutable.TreeSeqMap .newBuilder[t1, t2] }
2510
- else builderNoApply .asExpr).asInstanceOf [Expr [mutable.Builder [(t1, t2), T & collection.Map [t1, t2]]]]
2512
+ else scalaMapBuilder(tpe, tpe1, tpe2) .asExpr).asInstanceOf [Expr [mutable.Builder [(t1, t2), T & collection.Map [t1, t2]]]]
2511
2513
(if (cfg.mapAsArray) {
2512
2514
val readVal1 = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false , in)
2513
2515
genReadMapAsArray(newBuilder,
@@ -2518,6 +2520,8 @@ object JsonCodecMaker {
2518
2520
genReadMap(newBuilder, x => ' { $x.addOne(new Tuple2 ($readKey, $readVal2)): Unit },
2519
2521
x => ' { $x.result() }, in, default)
2520
2522
}).asInstanceOf [Expr [T ]]
2523
+ }
2524
+ }
2521
2525
} else if (tpe <:< TypeRepr .of[BitSet ]) withDecoderFor(methodKey, default, in) { (in, default) =>
2522
2526
val readVal =
2523
2527
if (isStringified) ' { $in.readStringAsInt() }
@@ -2548,7 +2552,7 @@ object JsonCodecMaker {
2548
2552
tpe1.asType match
2549
2553
case ' [t1] =>
2550
2554
val tDefault = default.asInstanceOf [Expr [T & mutable.Set [t1]]]
2551
- val emptySetNoOrdering = scalaCollectionEmptyNoArgs (tpe, tpe1)
2555
+ val emptySetNoOrdering = scalaCollectionEmpty (tpe, tpe1)
2552
2556
val emptySet =
2553
2557
(if (tpe <:< TypeRepr .of[mutable.SortedSet [? ]]) Apply (emptySetNoOrdering, List (summonOrdering(tpe1)))
2554
2558
else emptySetNoOrdering).asExpr.asInstanceOf [Expr [T & mutable.Set [t1]]]
@@ -2616,7 +2620,7 @@ object JsonCodecMaker {
2616
2620
val tpe1 = typeArg1(tpe)
2617
2621
tpe1.asType match
2618
2622
case ' [t1] =>
2619
- val emptyCollectionNoArgs = scalaCollectionEmptyNoArgs (tpe, tpe1)
2623
+ val emptyCollectionNoArgs = scalaCollectionEmpty (tpe, tpe1)
2620
2624
val emptyCollection =
2621
2625
(if (tpe <:< TypeRepr .of[mutable.UnrolledBuffer [? ]]) {
2622
2626
Apply (emptyCollectionNoArgs, List (summonClassTag(tpe1)))
@@ -2783,7 +2787,7 @@ object JsonCodecMaker {
2783
2787
case namedTupleInfo : NamedTupleInfo =>
2784
2788
val i = fieldInfo.nonTransientFieldIndex
2785
2789
if (namedTupleInfo.isGeneric) {
2786
- TypeApply (Select (productElement.appliedTo (Literal (IntConstant (i))), asInstanceOfMethod), List (Inferred (fTpe)))
2790
+ TypeApply (Select (Apply ( productElement, List (Literal (IntConstant (i) ))), asInstanceOfMethod), List (Inferred (fTpe)))
2787
2791
} else Select .unique(valRef, s " _ ${i + 1 }" )
2788
2792
case _ => Select (valRef, fieldInfo.getterOrField)
2789
2793
}.asExpr
@@ -3121,15 +3125,17 @@ object JsonCodecMaker {
3121
3125
tpe <:< TypeRepr .of[mutable.CollisionProofHashMap [? , ? ]]) withEncoderFor(methodKey, m, out) { (out, x) =>
3122
3126
val tpe1 = typeArg1(tpe)
3123
3127
val tpe2 = typeArg2(tpe)
3124
- ( tpe1.asType, tpe2.asType) match
3125
- case ( ' [t1], ' [ t2]) =>
3128
+ tpe1.asType match { case ' [t1] =>
3129
+ tpe2.asType match { case ' [ t2] =>
3126
3130
def writeVal2 (out : Expr [JsonWriter ], v : Expr [t2])(using Quotes ): Expr [Unit ] =
3127
3131
genWriteVal(v, tpe2 :: types, isStringified, None , out)
3128
3132
3129
3133
val tx = x.asInstanceOf [Expr [collection.Map [t1, t2]]]
3130
3134
if (cfg.mapAsArray) {
3131
3135
genWriteMapAsArrayScala(tx, (out, k) => genWriteVal(k, tpe1 :: types, isStringified, None , out), writeVal2, out)
3132
3136
} else genWriteMapScala(tx, (out, k) => genWriteKey(k, tpe1 :: types, out), writeVal2, out)
3137
+ }
3138
+ }
3133
3139
} else if (tpe <:< TypeRepr .of[BitSet ]) withEncoderFor(methodKey, m, out) { (out, x) =>
3134
3140
genWriteArray(x.asInstanceOf [Expr [BitSet ]], (out, x1) => {
3135
3141
if (isStringified) ' { $out.writeValAsString($x1) }
@@ -3221,7 +3227,7 @@ object JsonCodecMaker {
3221
3227
case ' [t] =>
3222
3228
val getter =
3223
3229
(if (isGeneric) {
3224
- TypeApply (Select (productElement.appliedTo (Literal (IntConstant (i - 1 ))), asInstanceOfMethod), List (Inferred (te)))
3230
+ TypeApply (Select (Apply ( productElement, List (Literal (IntConstant (i - 1 ) ))), asInstanceOfMethod), List (Inferred (te)))
3225
3231
} else Select .unique(xTerm, " _" + i)).asExpr.asInstanceOf [Expr [t]]
3226
3232
genWriteVal(getter, te :: types, isStringified, None , out).asTerm
3227
3233
}
0 commit comments