0
我正在將Scala函數導出爲外部格式。爲此我使用scala.meta
和StaticAnnotation
。喜歡的東西:如何保留宏註釋中的糖,格式和空格(內聯元)?
@ExportFunctions
object MyFunctions {
def max(x: Int, y: Int): Int = x max y
}
class ExportFunctions extends StaticAnnotation {
inline def apply(defn: Any): Any = meta {
defn match {
case q"object $name extends { ..$earlydefns } with ..$parents { ..$stats }" =>
stats.flatMap{
case [email protected](modifiers, fname, tparams, paramss, Some(returnType), body) =>
println(body.syntax)
}
case _ =>
}
defn
}
}
在ExportFunctions extends StaticAnnotation
執行功能的身體被表示爲脫糖樹:x.max(y)
。
但是,出於文檔目的,實際的源代碼會更好。或者至少糖(x max y
)。
有沒有辦法保留原始格式/糖?