在https://scalacenter.github.io/scalafix/docs/developers/tutorial.html教程中,我看到了SemanticRule是如何为scalafix实现的。我想在从磁盘读取并转换文件的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,它只向我展示了如何使用Scala规则文件的文件路径启动scalafix程序,但这不是我想要的。
发布于 2019-08-09 04:41:25
我知道的唯一方法是使用规则的文件路径,如果它在单个文件中并且没有外部依赖关系,或者发布它。
使用Scalafix生成代码的示例项目如下
https://stackoverflow.com/questions/57407946
复制相似问题