Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
Add copyToBuffer rule
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrf committed Jan 19, 2018
1 parent 15b166e commit 7c4580b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
rule = "scala:fix.Collectionstrawman_v0"
*/
package fix

import scala.collection.mutable

class Collectionstrawman_v0_copyToBuffer(xs: List[Int], b: mutable.Buffer[Int]) {

xs.copyToBuffer(b)
(xs ++ xs).copyToBuffer(b)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fix

import scala.collection.mutable

class Collectionstrawman_v0_copyToBuffer(xs: List[Int], b: mutable.Buffer[Int]) {

b ++= xs
b ++= xs ++ xs

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,20 @@ case class Collectionstrawman_v0(index: SemanticdbIndex)
removeTokensPatch + replaceCommasPatch
}.asPatch

val copyToBuffer = SymbolMatcher.normalized(
Symbol("_root_.scala.collection.TraversableOnce.copyToBuffer.")
)

def replaceCopyToBuffer(ctx: RuleCtx): Patch =
ctx.tree.collect {
case t @ q"${copyToBuffer(Term.Select(collection, _))}($buffer)" =>
ctx.replaceTree(t, q"$buffer ++= $collection".syntax)
}.asPatch

override def fix(ctx: RuleCtx): Patch = {
replaceToList(ctx) +
replaceSymbols(ctx) +
replaceTupleZipped(ctx)
replaceTupleZipped(ctx) +
replaceCopyToBuffer(ctx)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Collectionstrawman_Tests
Seq(AbsolutePath(BuildInfo.outputSourceroot))
) {
override def assertNoDiff(a: String, b: String, c: String) = {
println(a)
super.assertNoDiff(a, b, c)
}
runAllTests()
Expand Down

0 comments on commit 7c4580b

Please sign in to comment.