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
)。
有没有办法保留原始格式/糖?