@@ -9,11 +9,10 @@ import org.scalafmt.dynamic.utils.ReflectUtils._
9
9
import scala .util .Try
10
10
11
11
// noinspection TypeAnnotation
12
- class ScalafmtReflectConfig private [dynamic] (
13
- val fmtReflect : ScalafmtReflect ,
14
- private [dynamic] val target : Object ,
15
- private val classLoader : ClassLoader
12
+ class ScalafmtReflectConfig private [dynamic] (val fmtReflect : ScalafmtReflect )(
13
+ private [dynamic] val target : Object
16
14
) {
15
+ import fmtReflect .classLoader
17
16
private val targetCls = target.getClass
18
17
private val constructor : Constructor [_] = targetCls.getConstructors()(0 )
19
18
private val constructorParams = constructor.getParameters.map(_.getName)
@@ -40,24 +39,23 @@ class ScalafmtReflectConfig private[dynamic] (
40
39
}
41
40
}
42
41
43
- lazy val withSbtDialect : ScalafmtReflectConfig = {
44
- val newTarget =
42
+ lazy val withSbtDialect : ScalafmtReflectConfig =
43
+ new ScalafmtReflectConfig (fmtReflect)(
45
44
try target.invoke(" forSbt" )
46
45
catch {
47
46
case ReflectionException (_ : NoSuchMethodException ) =>
48
47
target.invoke(" withDialect" , (dialectCls, sbtDialect))
49
48
}
50
- new ScalafmtReflectConfig (fmtReflect, newTarget, classLoader)
51
- }
49
+ )
52
50
53
51
def withoutRewriteRules : ScalafmtReflectConfig = {
54
52
if (hasRewriteRules) {
55
53
// emulating this.copy(rewrite = RewriteSettings())
56
54
val fieldsValues = constructorParams.map(param => target.invoke(param))
57
55
fieldsValues(rewriteParamIdx) = emptyRewrites
58
- val targetNew =
56
+ new ScalafmtReflectConfig (fmtReflect)(
59
57
constructor.newInstance(fieldsValues : _* ).asInstanceOf [Object ]
60
- new ScalafmtReflectConfig (fmtReflect, targetNew, classLoader )
58
+ )
61
59
} else {
62
60
this
63
61
}
0 commit comments