Skip to content

Commit b42ea27

Browse files
committed
I might not be constructing the semantic db correctly here, I do not expect it to be empty.
1 parent 9763c34 commit b42ea27

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

examples/cross-rewrite-example/build/build.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import scalafix.util.TreePatch._
77
import scalafix.util.TokenPatch._
88

99
class Build(val context: Context) extends BaseBuild { outer =>
10-
override def defaultScalaVersion = "2.12.1"
10+
override def defaultScalaVersion = "2.11.8"
11+
12+
override def dependencies =
13+
super.dependencies ++ // don't forget super.dependencies here
14+
Resolver( mavenCentral ).bind(
15+
ScalaDependency( "org.typelevel", "cats", "0.9.0" )
16+
)
1117

1218
override def test: Dependency = {
1319
new BasicBuild(context) with ScalaTest {
@@ -35,7 +41,7 @@ class Build(val context: Context) extends BaseBuild { outer =>
3541
//This works
3642
AddGlobalImport(importer"scalaz._"),
3743
//None of these work, why?
38-
Replace(Symbol("_root_.scala.util.Either."), q"\/"),
44+
Replace(Symbol("_root_.scala.package.Either."), q"\/"),
3945
Replace(Symbol("_root_.Disjunction."), q"Test"),
4046
Rename(q"intOrString", q"xor"),
4147
//And this works again. What is different about import rewrites vs the others?

examples/cross-rewrite-example/src/Main.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.concurrent.Future
1+
import cats.implicits._
22

33
object Main {
44
def main(args: Array[String]): Unit = {

plugins/scalafix/Scalafix.scala

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ object Scalafix{
2525
patches: Seq[Patch] = Seq(),
2626
rewrites: Seq[ Rewrite[ScalafixMirror] ] = Seq(),
2727
allowEmpty: Boolean = false
28-
){
29-
def mirror =
28+
) {
29+
def mirror = {
30+
println("creating semantic mirror")
31+
println(s"classpath: ${classpath.string}")
32+
println(s"files: ${files.map(_._1).mkString(File.pathSeparator)}")
3033
Mirror(
3134
classpath.string,
3235
files.map(_._1).mkString(File.pathSeparator)
3336
)
37+
}
3438

3539
def context(file: File): ( RewriteCtx[Mirror], RewriteCtx[ScalafixMirror] ) = (
3640
scalafix.rewrite.RewriteCtx(
@@ -46,19 +50,28 @@ object Scalafix{
4650
allowEmpty || rewrites.nonEmpty || patches.nonEmpty,
4751
"You need to provide some rewrites via: `override def scalafix = super.scalafix.copy( rewrites = Seq(...) )`"
4852
)
49-
files.foreach{ case (from, to) =>
50-
implicit val ( ctx, ctx2 ) = context(from)
51-
lib.writeIfChanged(
52-
to,
53-
Patch(
54-
(
55-
patches
56-
++ rewrites.flatMap(
57-
_.rewrite( ctx2 ).to
58-
)
59-
).to
53+
files.foreach {
54+
case (from, to) =>
55+
implicit val (ctx, ctx2) = context(from)
56+
println("printing sources")
57+
println(ctx.mirror.sources)
58+
println("printing database")
59+
println(ctx.mirror.database)
60+
println("printing mirror database messages")
61+
println(ctx.mirror.database)
62+
println("end printing")
63+
assert(ctx.mirror.database.toString.trim != "", "I do not believe the database should be empty here")
64+
lib.writeIfChanged(
65+
to,
66+
Patch(
67+
(
68+
patches
69+
++ rewrites.flatMap(
70+
_.rewrite(ctx2).to
71+
)
72+
).to
73+
)
6074
)
61-
)
6275
}
6376
}
6477
}

0 commit comments

Comments
 (0)