Skip to content

Commit

Permalink
ScalafmtReflectConfig: fix withoutRewriteRules
Browse files Browse the repository at this point in the history
Account for non-public fields.
  • Loading branch information
kitbellew committed Nov 26, 2021
1 parent fb4ca62 commit 9787a90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ class ScalafmtReflectConfig private[dynamic] (val fmtReflect: ScalafmtReflect)(
val ctor: Constructor[_] = targetCls.getConstructors()(0)
val params = ctor.getParameters.map(_.getName)
val rewriteParamIdx = params.indexOf(rewriteFieldName).ensuring(_ >= 0)
val publicMethodNames = targetCls.getMethods.view.map(_.getName)
val publicParams = publicMethodNames.filter(params.contains).toSet
val fieldValues = params.zipWithIndex.map { case (p, i) =>
target.invoke(
if (i == rewriteParamIdx) "apply$default$" + (rewriteParamIdx + 1)
else p
else { if (publicParams.contains(p)) p else p + "$access$" + i }
)
}
new ScalafmtReflectConfig(fmtReflect)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class DynamicSuite extends FunSuite {
}

private val testedVersions = Seq(
"3.1.2",
"2.7.5",
"2.5.3",
"2.0.0-RC4",
"1.6.0-RC4",
Expand All @@ -190,8 +192,9 @@ class DynamicSuite extends FunSuite {
testedVersions.foreach { version =>
test(s"$name [v=$version]") {
val format = new Format(name, identity)
val dialect = if (version < "3.0.0") null else "scala213"
try {
format.setVersion(version, null, config(version))
format.setVersion(version, dialect, config(version))
fn(format, version)
} finally format.dynamic.clear()
}
Expand Down

0 comments on commit 9787a90

Please sign in to comment.