Refactor scripting - prepare utilities for refactoring of the script definitions handling
This commit is contained in:
+25
@@ -83,6 +83,31 @@ open class PropertiesCollection(private val properties: Map<Key<*>, Any?> = empt
|
|||||||
data[this] = v
|
data[this] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> PropertiesCollection.Key<T>.putIfNotNull(v: T?) {
|
||||||
|
if (v != null) {
|
||||||
|
data[this] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> PropertiesCollection.Key<in List<T>>.putIfAny(vals: Iterable<T>?) {
|
||||||
|
if (vals?.any() == true) {
|
||||||
|
data[this] = if (vals is List) vals else vals.toList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmName("putIfAny_map")
|
||||||
|
fun <K, V> PropertiesCollection.Key<in Map<K, V>>.putIfAny(vals: Iterable<Pair<K, V>>?) {
|
||||||
|
if (vals?.any() == true) {
|
||||||
|
data[this] = vals.toMap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <K, V> PropertiesCollection.Key<in Map<K, V>>.putIfAny(vals: Map<K, V>?) {
|
||||||
|
if (vals?.isNotEmpty() == true) {
|
||||||
|
data[this] = vals
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// generic for lists
|
// generic for lists
|
||||||
|
|
||||||
operator fun <T> PropertiesCollection.Key<in List<T>>.invoke(vararg vals: T) {
|
operator fun <T> PropertiesCollection.Key<in List<T>>.invoke(vararg vals: T) {
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ fun mapLegacyDiagnosticSeverity(severity: ScriptDependenciesResolver.ReportSever
|
|||||||
ScriptDependenciesResolver.ReportSeverity.DEBUG -> ScriptDiagnostic.Severity.DEBUG
|
ScriptDependenciesResolver.ReportSeverity.DEBUG -> ScriptDiagnostic.Severity.DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun mapLegacyDiagnosticSeverity(severity: ScriptReport.Severity): ScriptDiagnostic.Severity = when (severity) {
|
||||||
|
ScriptReport.Severity.FATAL -> ScriptDiagnostic.Severity.FATAL
|
||||||
|
ScriptReport.Severity.ERROR -> ScriptDiagnostic.Severity.ERROR
|
||||||
|
ScriptReport.Severity.WARNING -> ScriptDiagnostic.Severity.WARNING
|
||||||
|
ScriptReport.Severity.INFO -> ScriptDiagnostic.Severity.INFO
|
||||||
|
ScriptReport.Severity.DEBUG -> ScriptDiagnostic.Severity.DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
fun mapToLegacyScriptReportSeverity(severity: ScriptDiagnostic.Severity): ScriptReport.Severity = when (severity) {
|
fun mapToLegacyScriptReportSeverity(severity: ScriptDiagnostic.Severity): ScriptReport.Severity = when (severity) {
|
||||||
ScriptDiagnostic.Severity.FATAL -> ScriptReport.Severity.FATAL
|
ScriptDiagnostic.Severity.FATAL -> ScriptReport.Severity.FATAL
|
||||||
ScriptDiagnostic.Severity.ERROR -> ScriptReport.Severity.ERROR
|
ScriptDiagnostic.Severity.ERROR -> ScriptReport.Severity.ERROR
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kotlin.script.experimental.jvm.compat
|
||||||
|
|
||||||
|
import kotlin.script.experimental.api.ScriptAcceptedLocation
|
||||||
|
import kotlin.script.experimental.location.ScriptExpectedLocation
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
fun List<ScriptAcceptedLocation>.mapToLegacyExpectedLocations(): List<ScriptExpectedLocation> = map {
|
||||||
|
when (it) {
|
||||||
|
ScriptAcceptedLocation.Sources -> ScriptExpectedLocation.SourcesOnly
|
||||||
|
ScriptAcceptedLocation.Tests -> ScriptExpectedLocation.TestsOnly
|
||||||
|
ScriptAcceptedLocation.Libraries -> ScriptExpectedLocation.Libraries
|
||||||
|
ScriptAcceptedLocation.Project -> ScriptExpectedLocation.Project
|
||||||
|
ScriptAcceptedLocation.Everywhere -> ScriptExpectedLocation.Everywhere
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
fun List<ScriptExpectedLocation>.mapLegacyExpectedLocations(): List<ScriptAcceptedLocation> = map {
|
||||||
|
when (it) {
|
||||||
|
ScriptExpectedLocation.SourcesOnly -> ScriptAcceptedLocation.Sources
|
||||||
|
ScriptExpectedLocation.TestsOnly -> ScriptAcceptedLocation.Tests
|
||||||
|
ScriptExpectedLocation.Libraries -> ScriptAcceptedLocation.Libraries
|
||||||
|
ScriptExpectedLocation.Project -> ScriptAcceptedLocation.Project
|
||||||
|
ScriptExpectedLocation.Everywhere -> ScriptAcceptedLocation.Everywhere
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user