diff options
-rw-r--r-- | examples/scalafix-example/Main.scala | 9 | ||||
-rw-r--r-- | examples/scalafix-example/build/build.scala | 28 | ||||
-rw-r--r-- | examples/scalafix-example/build/build/build.scala | 5 | ||||
-rw-r--r-- | test/test.scala | 22 |
4 files changed, 64 insertions, 0 deletions
diff --git a/examples/scalafix-example/Main.scala b/examples/scalafix-example/Main.scala new file mode 100644 index 0000000..c82c77b --- /dev/null +++ b/examples/scalafix-example/Main.scala @@ -0,0 +1,9 @@ +object Main{ + lazy val x = 1 + 1 + + implicit def toString(i :Int) = i.toString + + def main( args: Array[String] ){ + println("Hello world!") + } +} diff --git a/examples/scalafix-example/build/build.scala b/examples/scalafix-example/build/build.scala new file mode 100644 index 0000000..eff4176 --- /dev/null +++ b/examples/scalafix-example/build/build.scala @@ -0,0 +1,28 @@ +import cbt._ + +import scala.meta._ +import scalafix.rewrite._ +import scalafix.util._ +import scalafix.util.TreePatch._ +import scalafix.util.TokenPatch._ + +class Build(val context: Context) extends BaseBuild{ + override def compile = { + new BasicBuild(context) with Scalafix{ + override def scalafix = super.scalafix.copy( + patches = + Seq( + AddGlobalImport( + importer"scala.collection.immutable" + ) + ), + rewrites = Seq( + ProcedureSyntax, + ExplicitImplicit, + VolatileLazyVal + ) + ) + }.scalafix.apply + super.compile // <- as scalafix trigger compile already before re-writing, this will just return the cached compile result before rewriting + } +} diff --git a/examples/scalafix-example/build/build/build.scala b/examples/scalafix-example/build/build/build.scala new file mode 100644 index 0000000..404356f --- /dev/null +++ b/examples/scalafix-example/build/build/build.scala @@ -0,0 +1,5 @@ +import cbt._ + +class Build(val context: Context) extends BuildBuild { + override def dependencies = super.dependencies :+ plugins.scalafix +} diff --git a/test/test.scala b/test/test.scala index 3b296a1..b97c36e 100644 --- a/test/test.scala +++ b/test/test.scala @@ -444,6 +444,28 @@ object Main{ lib.write(sourceFile, sourceBefore) } + /* + // currently fails with + // java.lang.UnsupportedOperationException: scalafix.rewrite.ScalafixMirror.fromMirror $anon#typeSignature requires the semantic api + { + val sourceFile = cbtHome / "examples" / "scalafix-example" / "Main.scala" + val sourceBefore = sourceFile.readAsString + runCbt("../examples/scalafix-example", Seq("clean","force")) + val res = runCbt("../examples/scalafix-example", Seq("compile")) + assert(res.exit0) + val sourceAfter = sourceFile.readAsString + assert(!(sourceBefore contains "@volatile")) + assert(!(sourceBefore contains ": Unit")) + assert(!(sourceBefore contains ": String ")) + assert(!(sourceBefore contains "import scala.collection.immutable")) + assert(sourceAfter contains "@volatile") + assert(sourceAfter contains ": Unit") + assert(sourceAfter contains ": String ") + assert(sourceAfter contains "import scala.collection.immutable") + lib.write(sourceFile, sourceBefore) + } + */ + System.err.println(" DONE!") System.err.println( successes.toString ++ " succeeded, "++ failures.toString ++ " failed" ) if(failures > 0) ExitCode.Failure else ExitCode.Success |