Skip to content

Commit 1063f88

Browse files
committed
revert formatting changes
1 parent 17681b1 commit 1063f88

File tree

1 file changed

+38
-55
lines changed

1 file changed

+38
-55
lines changed

mainargs/src-3/Macros.scala

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ 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 {
15-
(annotatedMethod, mainAnnotationInstance) =>
16-
createMainData[Any, B](annotatedMethod, mainAnnotationInstance)
14+
val mainDatas = Expr.ofList(annotatedMethodsWithMainAnnotations.map { (annotatedMethod, mainAnnotationInstance) =>
15+
createMainData[Any, B](annotatedMethod, mainAnnotationInstance)
1716
})
1817

1918
'{
@@ -27,7 +26,7 @@ object Macros {
2726
import quotes.reflect._
2827
val typeReprOfB = TypeRepr.of[B]
2928
val companionModule = typeReprOfB match {
30-
case TypeRef(a, b) => TermRef(a, b)
29+
case TypeRef(a,b) => TermRef(a,b)
3130
}
3231
val typeSymbolOfB = typeReprOfB.typeSymbol
3332
val companionModuleType = typeSymbolOfB.companionModule.tree.asInstanceOf[ValDef].tpt.tpe.asType
@@ -52,36 +51,31 @@ object Macros {
5251
'{ new ParserForClass[B](${ mainData }, () => ${ Ident(companionModule).asExpr }) }
5352
}
5453

55-
def createMainData[T: Type, B: Type](using
56-
Quotes
57-
)(method: quotes.reflect.Symbol, mainAnnotation: quotes.reflect.Term): Expr[MainData[T, B]] = {
54+
def createMainData[T: Type, B: Type](using Quotes)
55+
(method: quotes.reflect.Symbol,
56+
mainAnnotation: quotes.reflect.Term): Expr[MainData[T, B]] = {
5857
createMainData[T, B](method, mainAnnotation, method.paramSymss)
5958
}
6059

61-
def createMainData[T: Type, B: Type](using Quotes)(
62-
method: quotes.reflect.Symbol,
63-
mainAnnotation: quotes.reflect.Term,
64-
annotatedParamsLists: List[List[quotes.reflect.Symbol]]
65-
): Expr[MainData[T, B]] = {
60+
def createMainData[T: Type, B: Type](using Quotes)
61+
(method: quotes.reflect.Symbol,
62+
mainAnnotation: quotes.reflect.Term,
63+
annotatedParamsLists: List[List[quotes.reflect.Symbol]]): Expr[MainData[T, B]] = {
6664

6765
import quotes.reflect.*
68-
val params = method.paramSymss.headOption.getOrElse(
69-
report.throwError("Multiple parameter lists not supported")
70-
)
66+
val params = method.paramSymss.headOption.getOrElse(report.throwError("Multiple parameter lists not supported"))
7167
val defaultParams = getDefaultParams(method)
7268
val argSigsExprs = params.zip(annotatedParamsLists.flatten).map { paramAndAnnotParam =>
7369
val param = paramAndAnnotParam._1
7470
val annotParam = paramAndAnnotParam._2
7571
val paramTree = param.tree.asInstanceOf[ValDef]
7672
val paramTpe = paramTree.tpt.tpe
77-
val arg = annotParam.getAnnotation(argAnnotation).map(_.asExprOf[mainargs.arg]).getOrElse('{
78-
new mainargs.arg()
79-
})
73+
val arg = annotParam.getAnnotation(argAnnotation).map(_.asExprOf[mainargs.arg]).getOrElse('{ new mainargs.arg() })
8074
val paramType = paramTpe.asType
8175
paramType match
8276
case '[t] =>
8377
val defaultParam: Expr[Option[B => t]] = defaultParams.get(param) match {
84-
case Some('{ $v: `t` }) => '{ Some(((_: B) => $v)) }
78+
case Some('{ $v: `t`}) => '{ Some(((_: B) => $v)) }
8579
case None => '{ None }
8680
}
8781
val tokensReader = Expr.summon[mainargs.TokensReader[t]].getOrElse {
@@ -90,10 +84,7 @@ object Macros {
9084
param.pos.get
9185
)
9286
}
93-
'{
94-
(ArgSig.create[t, B](${ Expr(param.name) }, ${ arg }, ${ defaultParam })(using
95-
${ tokensReader }))
96-
}
87+
'{ (ArgSig.create[t, B](${ Expr(param.name) }, ${ arg }, ${ defaultParam })(using ${ tokensReader })) }
9788
}
9889
val argSigs = Expr.ofList(argSigsExprs)
9990

@@ -104,35 +95,28 @@ object Macros {
10495

10596
'{ (b: B, params: Seq[Any]) => ${ callOf('b, 'params) } }
10697
}
107-
'{
108-
MainData.create[T, B](
109-
${ Expr(method.name) },
110-
${ mainAnnotation.asExprOf[mainargs.main] },
111-
$argSigs,
112-
$invokeRaw
113-
)
114-
}
98+
'{ MainData.create[T, B](${ Expr(method.name) }, ${ mainAnnotation.asExprOf[mainargs.main] }, ${ argSigs }, ${ invokeRaw }) }
11599
}
116100

117-
/**
118-
* Call a method given by its symbol.
119-
*
120-
* E.g.
121-
*
122-
* assuming:
123-
*
124-
* def foo(x: Int, y: String)(z: Int)
125-
*
126-
* val argss: List[List[Any]] = ???
127-
*
128-
* then:
129-
*
130-
* call(<symbol of foo>, '{argss})
131-
*
132-
* will expand to:
133-
*
134-
* foo(argss(0)(0), argss(0)(1))(argss(1)(0))
135-
*/
101+
/** Call a method given by its symbol.
102+
*
103+
* E.g.
104+
*
105+
* assuming:
106+
*
107+
* def foo(x: Int, y: String)(z: Int)
108+
*
109+
* val argss: List[List[Any]] = ???
110+
*
111+
* then:
112+
*
113+
* call(<symbol of foo>, '{argss})
114+
*
115+
* will expand to:
116+
*
117+
* foo(argss(0)(0), argss(0)(1))(argss(1)(0))
118+
*
119+
*/
136120
private def call(using Quotes)(
137121
methodOwner: Expr[Any],
138122
method: quotes.reflect.Symbol,
@@ -151,17 +135,16 @@ object Macros {
151135
for (j <- paramss(i).indices.toList) yield {
152136
val tpe = paramss(i)(j).tree.asInstanceOf[ValDef].tpt.tpe
153137
tpe.asType match
154-
case '[t] => '{ $argss(${ Expr(i) })(${ Expr(j) }).asInstanceOf[t] }.asTerm
138+
case '[t] => '{ $argss(${Expr(i)})(${Expr(j)}).asInstanceOf[t] }.asTerm
155139
}
156140
}
157141

158142
methodOwner.asTerm.select(method).appliedToArgss(accesses).asExpr
159143
}
144+
160145

161146
/** Lookup default values for a method's parameters. */
162-
private def getDefaultParams(using
163-
Quotes
164-
)(method: quotes.reflect.Symbol): Map[quotes.reflect.Symbol, Expr[Any]] = {
147+
private def getDefaultParams(using Quotes)(method: quotes.reflect.Symbol): Map[quotes.reflect.Symbol, Expr[Any]] = {
165148
// Copy pasted from Cask.
166149
// https://github.com/com-lihaoyi/cask/blob/65b9c8e4fd528feb71575f6e5ef7b5e2e16abbd9/cask/src-3/cask/router/Macros.scala#L38
167150
import quotes.reflect._
@@ -174,7 +157,7 @@ object Macros {
174157

175158
val idents = method.owner.tree.asInstanceOf[ClassDef].body
176159

177-
idents.foreach {
160+
idents.foreach{
178161
case deff @ DefDef(Name(idx), _, _, _) =>
179162
val expr = Ref(deff.symbol).asExpr
180163
defaults += (params(idx.toInt - 1) -> expr)

0 commit comments

Comments
 (0)