Skip to content

Commit 5be5efc

Browse files
committed
bring back companionApplyFieldsTypesDefaults for future use
1 parent 2e1451f commit 5be5efc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/main/scala/Defaults.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DefaultsMacros( val c: Context ) {
1818
q"new{ ..$defs }"
1919
}
2020

21-
def constructorFieldsTypesDefaults( tpe: Type ): List[( String, Type, Option[Tree] )] = {
21+
private def constructorFieldsTypesDefaults( tpe: Type ): List[( String, Type, Option[Tree] )] = {
2222
val m = tpe.decls.collectFirst {
2323
case m: MethodSymbol if m.isPrimaryConstructor => m
2424
}.head.paramLists.flatten.zipWithIndex
@@ -37,4 +37,21 @@ class DefaultsMacros( val c: Context ) {
3737
)
3838
}.toList
3939
}
40+
41+
private def companionApplyFieldsTypesDefaults( tpe: Type ): List[( String, Type, Option[Tree] )] = {
42+
tpe.companion.member( TermName( "apply" ) ).asTerm.alternatives.find( _.isSynthetic ).get.asMethod.paramLists.flatten.zipWithIndex.map {
43+
case ( field, i ) =>
44+
(
45+
field.name.toTermName.decodedName.toString,
46+
field.infoIn( tpe ),
47+
{
48+
val method = TermName( s"apply$$default$$${i + 1}" )
49+
tpe.companion.member( method ) match {
50+
case NoSymbol => None
51+
case _ => Some( q"${tpe.typeSymbol.companion}.$method" )
52+
}
53+
}
54+
)
55+
}.toList
56+
}
4057
}

0 commit comments

Comments
 (0)