Skip to content

Commit 7083321

Browse files
olafurpgjulienrf
authored andcommitted
Setup skeleton for rewriting with scalafix.
0 parents  commit 7083321

File tree

8 files changed

+87
-0
lines changed

8 files changed

+87
-0
lines changed

build.sbt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Use a scala version supported by scalafix.
2+
scalaVersion in ThisBuild := org.scalameta.BuildInfo.supportedScalaVersions.last
3+
4+
lazy val root = project.aggregate(rewrites, input, output, tests)
5+
6+
lazy val rewrites = project.settings(
7+
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % "0.4.2"
8+
)
9+
10+
lazy val input = project.settings(
11+
scalametaSourceroot := sourceDirectory.in(Compile).value
12+
)
13+
14+
lazy val output = project
15+
16+
lazy val tests = project
17+
.settings(
18+
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % "0.4.2" % Test cross CrossVersion.full,
19+
buildInfoPackage := "fix",
20+
buildInfoKeys := Seq[BuildInfoKey](
21+
"inputSourceroot" ->
22+
sourceDirectory.in(input, Compile).value,
23+
"outputSourceroot" ->
24+
sourceDirectory.in(output, Compile).value,
25+
"inputClassdirectory" ->
26+
classDirectory.in(input, Compile).value
27+
)
28+
)
29+
.dependsOn(input, rewrites)
30+
.enablePlugins(BuildInfoPlugin)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* ONLY
2+
rewrite = "scala:fix.Collectionstrawman_v0"
3+
*/
4+
package fix
5+
6+
object Collectionstrawman_v0_Test {
7+
List(1, 2, 3)
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package fix
2+
3+
import scala.{ List => _ }
4+
import strawman.collection.immutable.List
5+
object Collectionstrawman_v0_Test {
6+
List(1, 2, 3)
7+
}

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.13

project/plugins.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.4.2")
2+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.4.2")
3+
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC3")
4+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")
5+

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Scalafix rewrites for collection-strawman
2+
3+
To develop rewrite:
4+
```
5+
sbt ~tests/test
6+
# edit rewrites/src/main/scala/fix/Collectionstrawman_v0.scala
7+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package fix
2+
3+
import scalafix._
4+
import scala.meta._
5+
6+
case class Collectionstrawman_v0(mirror: Mirror)
7+
extends SemanticRewrite(mirror) {
8+
val immutableListSymbol = Symbol("_root_.scala.collection.immutable.List.")
9+
def rewrite(ctx: RewriteCtx): Patch = {
10+
ctx.tree.collect {
11+
case name @ Term.Name(_) if name.symbol == immutableListSymbol =>
12+
ctx.addGlobalImport(importer"scala.{List => _}") +
13+
ctx.addGlobalImport(importer"strawman.collection.immutable.List")
14+
}.asPatch
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package fix
2+
3+
import scala.meta._
4+
import scalafix.testkit._
5+
6+
class Collectionstrawman_Tests
7+
extends SemanticRewriteSuite(
8+
Database.load(Classpath(AbsolutePath(BuildInfo.inputClassdirectory))),
9+
AbsolutePath(BuildInfo.inputSourceroot),
10+
Seq(AbsolutePath(BuildInfo.outputSourceroot))
11+
) {
12+
runAllTests()
13+
}

0 commit comments

Comments
 (0)