0

在教程https://scalacenter.github.io/scalafix/docs/developers/tutorial.html中,我看到了如何SemanticRule为 scalafix 实现 a。我想直接在我从磁盘读取的 Scala 文件的源代码中调用它并转换文件。

在 scalameta 中,我可以执行以下操作:

val f = .... // some File
val path = f.toPath
val bytes = java.nio.file.Files.readAllBytes(path)
val text = new String(bytes, "UTF-8")
val input = Input.VirtualFile(path.toString, text)
val source = input.parse[Source].get
val transformer = new MyTransformer()
val transformedSource = transformer(source)
// The transformed source can be written into an output file

我想对 scalafix 做同样的事情,但使用SemanticRule. 如果我读到这个:https : //scalacenter.github.io/scalafix/docs/developers/tutorial.html#run-the-rule-from-source-code 它只向我展示了如何使用文件启动 scalafix 程序Scala 规则文件的路径,但这不是我想要的。

4

1 回答 1

0

我知道的唯一方法是使用规则的文件路径,如果它在单个文件中并且没有外部依赖项或以其他方式发布它。

使用 Scalafix 生成代码的示例项目是

https://github.com/olafurpg/scalafix-codegen

https://github.com/DmytroMitin/scalafix-codegen

于 2019-08-08T20:41:25.360 回答