diff options
author | Martin Odersky <odersky@gmail.com> | 2016-03-14 10:02:16 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-03-14 10:02:16 +0100 |
commit | 6c18e37886e90d217579112ccf867c22658273be (patch) | |
tree | 3e5bed6a8bee401d38c80d2b4fbdbfdd6cec039f /src/dotty/tools/dotc/rewrite/Rewrites.scala | |
parent | 13e3d59937ddcb9819904593cb7c6417af8eedd2 (diff) | |
download | dotty-6c18e37886e90d217579112ccf867c22658273be.tar.gz dotty-6c18e37886e90d217579112ccf867c22658273be.tar.bz2 dotty-6c18e37886e90d217579112ccf867c22658273be.zip |
Address reviewer comments.
Diffstat (limited to 'src/dotty/tools/dotc/rewrite/Rewrites.scala')
-rw-r--r-- | src/dotty/tools/dotc/rewrite/Rewrites.scala | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/dotty/tools/dotc/rewrite/Rewrites.scala b/src/dotty/tools/dotc/rewrite/Rewrites.scala index cda9e8565..7ab0e5d59 100644 --- a/src/dotty/tools/dotc/rewrite/Rewrites.scala +++ b/src/dotty/tools/dotc/rewrite/Rewrites.scala @@ -51,7 +51,7 @@ object Rewrites { def writeBack(): Unit = { val out = source.file.output - val chars = apply(source.content) + val chars = apply(source.underlying.content) val bytes = new String(chars).getBytes out.write(bytes) out.close() @@ -62,28 +62,21 @@ object Rewrites { * given by `pos` in `source` by `replacement` */ def patch(source: SourceFile, pos: Position, replacement: String)(implicit ctx: Context): Unit = - ctx.settings.rewrite.value match { - case Some(rewrites: Rewrites) => - rewrites.patched.get(source) match { - case Some(ps) => - ps.addPatch(pos, replacement) - case None => - rewrites.patched(source) = new Patches(source) - patch(source, pos, replacement) - } - case _ => - } + for (rewrites <- ctx.settings.rewrite.value) + rewrites.patched + .getOrElseUpdate(source, new Patches(source)) + .addPatch(pos, replacement) + + /** Patch position in `ctx.compilationUnit.source`. */ + def patch(pos: Position, replacement: String)(implicit ctx: Context): Unit = + patch(ctx.compilationUnit.source, pos, replacement) /** If -rewrite is set, apply all patches and overwrite patched source files. */ def writeBack()(implicit ctx: Context) = - ctx.settings.rewrite.value match { - case Some(rewrites: Rewrites) => - for (source <- rewrites.patched.keys) { - ctx.println(s"[patched file ${source.file.path}]") - rewrites.patched(source).writeBack() - } - case _ => + for (rewrites <- ctx.settings.rewrite.value; source <- rewrites.patched.keys) { + ctx.println(s"[patched file ${source.file.path}]") + rewrites.patched(source).writeBack() } } |