@@ -11,8 +11,9 @@ object Macros {
1111    val  annotatedMethodsWithMainAnnotations  =  allMethods.flatMap { methodSymbol => 
1212      methodSymbol.getAnnotation(mainAnnotation).map(methodSymbol ->  _)
1313    }.sortBy(_._1.pos.map(_.start))
14-     val  mainDatas  =  Expr .ofList(annotatedMethodsWithMainAnnotations.map { (annotatedMethod, mainAnnotationInstance) => 
15-       createMainData[Any , B ](annotatedMethod, mainAnnotationInstance)
14+     val  mainDatas  =  Expr .ofList(annotatedMethodsWithMainAnnotations.map {
15+       (annotatedMethod, mainAnnotationInstance) => 
16+         createMainData[Any , B ](annotatedMethod, mainAnnotationInstance)
1617    })
1718
1819    ' {
@@ -26,13 +27,13 @@ object Macros {
2627    import  quotes .reflect ._ 
2728    val  typeReprOfB  =  TypeRepr .of[B ]
2829    val  companionModule  =  typeReprOfB match  {
29-       case  TypeRef (a,b) =>  TermRef (a,b)
30+       case  TypeRef (a,  b) =>  TermRef (a,  b)
3031    }
3132    val  typeSymbolOfB  =  typeReprOfB.typeSymbol
3233    val  companionModuleType  =  typeSymbolOfB.companionModule.tree.asInstanceOf [ValDef ].tpt.tpe.asType
3334    val  companionModuleExpr  =  Ident (companionModule).asExpr
3435    val  mainAnnotationInstance  =  typeSymbolOfB.getAnnotation(mainAnnotation).getOrElse {
35-       ' {new  mainargs.main()}.asTerm //  construct a default if not found.
36+       ' {  new  mainargs.main()  }.asTerm //  construct a default if not found.
3637    }
3738    val  ctor  =  typeSymbolOfB.primaryConstructor
3839    val  ctorParams  =  ctor.paramSymss.flatten
@@ -58,13 +59,13 @@ object Macros {
5859          //  parameters, so use those for getting the annotations instead
5960          TypeRepr .of[B ].typeSymbol.primaryConstructor.paramSymss
6061        )
61-         val  erasedMainData  =  ' {$mainData.asInstanceOf [MainData [B , Any ]]}
62+         val  erasedMainData  =  ' {  $mainData.asInstanceOf [MainData [B , Any ]]  }
6263        ' { new  ParserForClass [B ]($erasedMainData, () =>  $ { Ident (companionModule).asExpr }) }
6364  }
6465
65-   def  createMainData [T :  Type , B :  Type ](using   Quotes ) 
66-                                       ( method : quotes.reflect. Symbol , 
67-                                         mainAnnotation : quotes.reflect.Term ):  Expr [MainData [T , B ]] =  {
66+   def  createMainData [T :  Type , B :  Type ](using 
67+       Quotes 
68+   )( method : quotes.reflect. Symbol ,  mainAnnotation : quotes.reflect.Term ):  Expr [MainData [T , B ]] =  {
6869    createMainData[T , B ](method, mainAnnotation, method.paramSymss)
6970  }
7071
@@ -73,7 +74,7 @@ object Macros {
7374      import  quotes .reflect .* 
7475      tpe match  {
7576        case  AnnotatedType (AppliedType (_, Seq (arg)), x)
76-           if  x.tpe =:=  defn.RepeatedAnnot .typeRef =>  Some (arg)
77+              if  x.tpe =:=  defn.RepeatedAnnot .typeRef =>  Some (arg)
7778        case  _ =>  None 
7879      }
7980    }
@@ -85,14 +86,18 @@ object Macros {
8586    }
8687  }
8788
88-   def  createMainData [T :  Type , B :  Type ](using  Quotes )
89-                                       (method : quotes.reflect.Symbol ,
90-                                        mainAnnotation : quotes.reflect.Term ,
91-                                        annotatedParamsLists : List [List [quotes.reflect.Symbol ]]):  Expr [MainData [T , B ]] =  {
89+   def  createMainData [T :  Type , B :  Type ](using  Quotes )(
90+       method : quotes.reflect.Symbol ,
91+       mainAnnotation : quotes.reflect.Term ,
92+       annotatedParamsLists : List [List [quotes.reflect.Symbol ]]
93+   ):  Expr [MainData [T , B ]] =  {
9294
9395    import  quotes .reflect .* 
94-     val  params  =  method.paramSymss.headOption.getOrElse(report.throwError(" Multiple parameter lists not supported" 
95-     val  defaultParams  =  if  (params.exists(_.flags.is(Flags .HasDefault ))) getDefaultParams(method) else  Map .empty
96+     val  params  =  method.paramSymss.headOption.getOrElse(
97+       report.throwError(" Multiple parameter lists not supported" 
98+     )
99+     val  defaultParams  = 
100+       if  (params.exists(_.flags.is(Flags .HasDefault ))) getDefaultParams(method) else  Map .empty
96101    val  argSigsExprs  =  params.zip(annotatedParamsLists.flatten).map { paramAndAnnotParam => 
97102      val  param  =  paramAndAnnotParam._1
98103      val  annotParam  =  paramAndAnnotParam._2
@@ -102,7 +107,9 @@ object Macros {
102107        case  VarargTypeRepr (AsType (' [t])) =>  TypeRepr .of[Leftover [t]]
103108        case  _ =>  paramTpe
104109      }
105-       val  arg  =  annotParam.getAnnotation(argAnnotation).map(_.asExprOf[mainargs.arg]).getOrElse(' { new  mainargs.arg() })
110+       val  arg  =  annotParam.getAnnotation(argAnnotation).map(_.asExprOf[mainargs.arg]).getOrElse(' {
111+         new  mainargs.arg()
112+       })
106113      readerTpe.asType match  {
107114        case  ' [t] => 
108115          def  applyAndCast (f : Expr [Any ] =>  Expr [Any ], arg : Expr [B ]):  Expr [t] =  {
@@ -117,10 +124,10 @@ object Macros {
117124                    case  err : Exception  => 
118125                      report.errorAndAbort(
119126                        s """ Failed to convert default value for parameter  ${param.name}, 
120-                         |expected type:  ${paramTpe.show}, 
121-                         |but default value  ${expr.show} is of type:  ${expr.asTerm.tpe.widen.show}
122-                         |while converting type caught an exception with message:  ${err.getMessage}
123-                         |There might be a bug in mainargs. """ .stripMargin,
127+                             |expected type:  ${paramTpe.show}, 
128+                             |but default value  ${expr.show} is of type:  ${expr.asTerm.tpe.widen.show}
129+                             |while converting type caught an exception with message:  ${err.getMessage}
130+                             |There might be a bug in mainargs. """ .stripMargin,
124131                        param.pos.getOrElse(Position .ofMacroExpansion)
125132                      )
126133                recoveredType
@@ -137,7 +144,10 @@ object Macros {
137144              method.pos.getOrElse(Position .ofMacroExpansion)
138145            )
139146          }
140-           ' { (ArgSig .create[t, B ]($ { Expr (param.name) }, $ { arg }, $ { defaultParam })(using  $ { tokensReader })) }
147+           ' {
148+             (ArgSig .create[t, B ]($ { Expr (param.name) }, $ { arg }, $ { defaultParam })(using 
149+             $ { tokensReader }))
150+           }
141151      }
142152    }
143153    val  argSigs  =  Expr .ofList(argSigsExprs)
@@ -149,28 +159,35 @@ object Macros {
149159
150160      ' { (b : B , params : Seq [Any ]) =>  $ { callOf(' b , ' params ) } }
151161    }
152-     ' { MainData .create[T , B ]($ { Expr (method.name) }, $ { mainAnnotation.asExprOf[mainargs.main] }, $ { argSigs }, $ { invokeRaw }) }
162+     ' {
163+       MainData .create[T , B ](
164+         $ { Expr (method.name) },
165+         $ { mainAnnotation.asExprOf[mainargs.main] },
166+         $ { argSigs },
167+         $ { invokeRaw }
168+       )
169+     }
153170  }
154171
155-   /**  Call a method given by its symbol.  
156-     *  
157-     * E.g.  
158-     *  
159-     * assuming:  
160-     *  
161-     *   def foo(x: Int, y: String)(z: Int)  
162-     *  
163-     *   val argss: List[List[Any]] = ???  
164-     *  
165-     * then:  
166-     *  
167-     *   call(<symbol of foo>, '{argss})  
168-     *  
169-     * will expand to:  
170-     *  
171-     *   foo(argss(0)(0), argss(0)(1))(argss(1)(0))  
172-     *  
173-      */  
172+   /**  
173+    * Call a method given by its symbol.  
174+    *  
175+    * E.g.  
176+    *  
177+    * assuming:  
178+    *  
179+    *   def foo(x: Int, y: String)(z: Int)  
180+    *  
181+    *   val argss: List[List[Any]] = ???  
182+    *  
183+    * then:  
184+    *  
185+    *   call(<symbol of foo>, '{argss})  
186+    *  
187+    * will expand to:  
188+    *  
189+    *   foo(argss(0)(0), argss(0)(1))(argss(1)(0))  
190+    */  
174191  private  def  call (using  Quotes )(
175192      methodOwner : Expr [Any ],
176193      method : quotes.reflect.Symbol ,
@@ -195,23 +212,25 @@ object Macros {
195212      for  (i <-  params.indices.toList) yield  {
196213        val  param  =  params(i)
197214        val  tpe  =  methodType.memberType(param)
198-         val  untypedRef  =  ' { $ref($ {Expr (i)}) }
215+         val  untypedRef  =  ' { $ref($ {  Expr (i)  }) }
199216        tpe match  {
200217          case  VarargTypeRepr (AsType (' [t])) => 
201218            Typed (
202219              ' { $untypedRef.asInstanceOf [Leftover [t]].value }.asTerm,
203220              Inferred (AppliedType (defn.RepeatedParamClass .typeRef, List (TypeRepr .of[t])))
204221            )
205222          case  _ =>  tpe.asType match 
206-             case  ' [t] =>  ' { $untypedRef.asInstanceOf [t] }.asTerm
223+                case  ' [t] =>  ' { $untypedRef.asInstanceOf [t] }.asTerm
207224        }
208225      }
209226
210227    methodOwner.asTerm.select(method).appliedToArgs(accesses(args)).asExpr
211228  }
212229
213230  /**  Lookup default values for a method's parameters. */  
214-   private  def  getDefaultParams (using  Quotes )(method : quotes.reflect.Symbol ):  Map [quotes.reflect.Symbol , Expr [Any ] =>  Expr [Any ]] =  {
231+   private  def  getDefaultParams (using 
232+       Quotes 
233+   )(method : quotes.reflect.Symbol ):  Map [quotes.reflect.Symbol , Expr [Any ] =>  Expr [Any ]] =  {
215234    //  Copy pasted from Cask.
216235    //  https://github.com/com-lihaoyi/cask/blob/65b9c8e4fd528feb71575f6e5ef7b5e2e16abbd9/cask/src-3/cask/router/Macros.scala#L38
217236    import  quotes .reflect ._ 
@@ -224,7 +243,7 @@ object Macros {
224243
225244    val  idents  =  method.owner.tree.asInstanceOf [ClassDef ].body
226245
227-     idents.foreach{
246+     idents.foreach  {
228247      case  deff @  DefDef (Name (idx), _, _, _) => 
229248        val  expr  =  (owner : Expr [Any ]) =>  Select (owner.asTerm, deff.symbol).asExpr
230249        defaults +=  (params(idx.toInt -  1 ) ->  expr)
0 commit comments