Implement support for new script customizations in command line compiler

refactor and fix internals in many places to make it work
add appropriate tests for main-kts case
This commit is contained in:
Ilya Chernikov
2019-07-01 13:41:08 +02:00
parent 1ab255eafb
commit dc4370ff08
23 changed files with 477 additions and 272 deletions
@@ -35,21 +35,23 @@ open class ScriptCompilationConfiguration(baseConfigurations: Iterable<ScriptCom
object Default : ScriptCompilationConfiguration()
/**
* An alternative to the constructor with base configuration, which returns a new configuration only if [body] adds anything
* to the original one, otherwise returns original
*/
fun withUpdates(body: Builder.() -> Unit = {}): ScriptCompilationConfiguration {
val newConfiguration = ScriptCompilationConfiguration(this, body = body)
return if (newConfiguration == this) this
else newConfiguration
}
override fun toString(): String {
return "ScriptCompilationConfiguration($providedProperties)"
}
}
/**
* An alternative to the constructor with base configuration, which returns a new configuration only if [body] adds anything
* to the original one, otherwise returns original
*/
fun ScriptCompilationConfiguration?.with(body: ScriptCompilationConfiguration.Builder.() -> Unit): ScriptCompilationConfiguration {
val newConfiguration =
if (this == null) ScriptCompilationConfiguration(body = body)
else ScriptCompilationConfiguration(this, body = body)
return if (newConfiguration == this) this else newConfiguration
}
/**
* The script type display name
*/
@@ -35,6 +35,18 @@ open class ScriptEvaluationConfiguration(baseEvaluationConfigurations: Iterable<
object Default : ScriptEvaluationConfiguration()
}
/**
* An alternative to the constructor with base configuration, which returns a new configuration only if [body] adds anything
* to the original one, otherwise returns original
*/
fun ScriptEvaluationConfiguration?.with(body: ScriptEvaluationConfiguration.Builder.() -> Unit): ScriptEvaluationConfiguration {
val newConfiguration =
if (this == null) ScriptEvaluationConfiguration(body = body)
else ScriptEvaluationConfiguration(this, body = body)
return if (newConfiguration != this) newConfiguration else this
}
/**
* The list of actual script implicit receiver object, in the same order as specified in {@link ScriptCompilationConfigurationKeys#implicitReceivers}
*/