Refactoring scripting infrastructure:
- add a helper for new constructing Compilation Configuration only when necessary - add more converters for legacy diagnostics - add helpers for simpler creating of failure results
This commit is contained in:
@@ -138,6 +138,24 @@ operator fun <R> List<ScriptDiagnostic>.plus(result: ResultWithDiagnostics<R>):
|
||||
fun <R> R.asSuccess(reports: List<ScriptDiagnostic> = listOf()): ResultWithDiagnostics.Success<R> =
|
||||
ResultWithDiagnostics.Success(this, reports)
|
||||
|
||||
/**
|
||||
* Makes Failure result with optional diagnostic [reports]
|
||||
*/
|
||||
fun makeFailureResult(reports: List<ScriptDiagnostic>): ResultWithDiagnostics.Failure =
|
||||
ResultWithDiagnostics.Failure(reports)
|
||||
|
||||
/**
|
||||
* Makes Failure result with optional diagnostic [reports]
|
||||
*/
|
||||
fun makeFailureResult(vararg reports: ScriptDiagnostic): ResultWithDiagnostics.Failure =
|
||||
ResultWithDiagnostics.Failure(reports.asList())
|
||||
|
||||
/**
|
||||
* Makes Failure result with diagnostic [message] with optional [path] and [location]
|
||||
*/
|
||||
fun makeFailureResult(message: String, path: String? = null, location: SourceCode.Location? = null): ResultWithDiagnostics.Failure =
|
||||
ResultWithDiagnostics.Failure(message.asErrorDiagnostics(path, location))
|
||||
|
||||
/**
|
||||
* Converts the receiver Throwable to the Failure results wrapper with optional [customMessage], [path] and [location]
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,16 @@ open class ScriptCompilationConfiguration(baseConfigurations: Iterable<ScriptCom
|
||||
companion object : ScriptCompilationConfigurationKeys
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user