-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from xuwei-k/ParamClause-ArgClause-None
add explicit `None` for `Term.ParamClause` and `Term.ArgClause`
- Loading branch information
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
core/src/main/scala-latest/scalameta_ast/AddDefaultParam.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package scalameta_ast | ||
|
||
import scala.annotation.tailrec | ||
import scala.meta.Position | ||
import scala.meta.Term | ||
|
||
object AddDefaultParam { | ||
|
||
def addDefaultParam(parsed: Term, str: String): String = { | ||
val values = parsed.collect { | ||
case Term.Apply.After_4_6_0( | ||
Term.Select(Term.Name("Term"), Term.Name("ParamClause" | "ArgClause")), | ||
Term.ArgClause( | ||
List(a), | ||
_ | ||
) | ||
) => | ||
a.pos | ||
} | ||
|
||
@tailrec | ||
def loop(acc: List[String], code: String, consumed: Int, src: List[Position]): List[String] = { | ||
src match { | ||
case head :: tail => | ||
val (x1, x2) = code.splitAt(head.end - consumed) | ||
loop( | ||
s", None" :: x1 :: acc, | ||
x2, | ||
x1.length + consumed, | ||
tail | ||
) | ||
case Nil => | ||
(code :: acc).reverse | ||
} | ||
} | ||
loop(Nil, str, 0, values).mkString | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/scala-scalafix_compat-js/scalameta_ast/AddDefaultParam.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package scalameta_ast | ||
|
||
import scala.meta.Term | ||
|
||
object AddDefaultParam { | ||
|
||
def addDefaultParam(parsed: Term, str: String): String = str | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters